Skip to content

Group xTaskCreateStatic

Modules > xTaskCreateStatic

More...

Detailed Description

task. h

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

Internally, within the FreeRTOS implementation, tasks use two blocks of memory. The first block is used to hold the task's data structures. The second block is used by the task as its stack. If a task is created using xTaskCreate() then both blocks of memory are automatically dynamically allocated inside the xTaskCreate() function. (see http://www.freertos.org/a00111.html). If a task is created using xTaskCreateStatic() then the application writer must provide the required memory. xTaskCreateStatic() therefore allows a task to be created without using any dynamic memory allocation.

Parameters:

  • 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. The maximum length of the string is defined by configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
  • ulStackDepth 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 32-bits wide and ulStackDepth is defined as 100 then 400 bytes will be allocated for stack storage.
  • pvParameters Pointer that will be used as the parameter for the task being created.
  • uxPriority The priority at which the task will run.
  • pxStackBuffer Must point to a StackType_t array that has at least ulStackDepth indexes - the array will then be used as the task's stack, removing the need for the stack to be allocated dynamically.
  • pxTaskBuffer Must point to a variable of type StaticTask_t, which will then be used to hold the task's data structures, removing the need for the memory to be allocated dynamically.

Returns:

If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will be created and a handle to the created task is returned. If either pxStackBuffer or pxTaskBuffer are NULL then the task will not be created and NULL is returned.

Example usage: