Quality RTOS & Embedded Software
About   Contact   Support   FAQ

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs Books & Kits Trace Tools Ecosystem TCP & FAT Training

Last site update June 02 2015

[Task Creation]

task. h
BaseType_t xTaskCreate( TaskFunction_t pvTaskCode, const char * const pcName, unsigned short usStackDepth, void *pvParameters, UBaseType_t uxPriority, TaskHandle_t *pvCreatedTask );

Create a new task and add it to the list of tasks that are ready to run.

If you are using FreeRTOS-MPU then it is recommended to use xTaskCreateRestricted() in place of xTaskCreate(). Using xTaskCreate() with FreeRTOS-MPU allows tasks to be created to run in either Privileged or User modes (see the description of uxPriority below). When Privileged mode it used the task will have access to the entire memory map, when User mode is used the task will have access to only its stack. In both cases the MPU will not automatically catch stack overflows, although the standard FreeRTOS stack overflow detection schemes can still be used. xTaskCreateRestricted() permits much greater flexibility.

pvTaskCode Pointer to the task entry function. Tasks must be implemented to never return (i.e. continuous loop).
pcName A descriptive name for the task. This is mainly used to facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN.
usStackDepth The size of the task stack specified as the number of variables the stack can hold - not the number of bytes. For example, if the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes will be allocated for stack storage. The stack depth multiplied by the stack width must not exceed the maximum value that can be contained in a variable of type size_t.
pvParameters Pointer that will be used as the parameter for the task being created.
uxPriority The priority at which the task should run.

Systems that include MPU support can optionally create tasks in a privileged (system) mode by setting bit portPRIVILEGE_BIT of the priority parameter. For example, to create a privileged task at priority 2 the uxPriority parameter should be set to ( 2 | portPRIVILEGE_BIT ).

pvCreatedTask Used to pass back a handle by which the created task can be referenced.
pdPASS if the task was successfully created and added to a ready list, otherwise an error code defined in the file projdefs. h
Example usage:
/* Task to be created. */
void vTaskCode( void * pvParameters )
  for( ;; )
      /* Task code goes here. */

/* Function that creates a task. */
void vOtherFunction( void )
static unsigned char ucParameterToPass;
TaskHandle_t xHandle = NULL;

  /* Create the task, storing the handle.  Note that the passed parameter 
  ucParameterToPass must exist for the lifetime of the task, so in this 
  case is declared static.  If it was just an an automatic stack variable 
  it might no longer exist, or at least have been corrupted, by the time
  the new task attempts to access it. */
  xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, 
               &xHandle );
  configASSERT( xHandle );

  /* Use the handle to delete the task. */
  if( xHandle != NULL )
      vTaskDelete( xHandle );

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2015 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News - New Book Edition!

Receive a complimentary pre-release pdf of our up-coming book "Mastering the FreeRTOS Real Time Kernel, a Hands-On Tutorial Guide" with every purchased copy of the existing "Using the FreeRTOS Real Time Kernel" book.

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists