Statically allocated tasks

Tasks that are created without using the FreeRTOS heap require the programmer to perform allocation for the task's stack and TCB before creating the task. The static version of task creation is xTaskCreateStatic().

The FreeRTOS prototype for xTaskCreateStatic() is as follows:

TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
                                 const char * const pcName,
                                 const uint32_t ulStackDepth,
                                 void * const pvParameters,
                                 UBaseType_t uxPriority,
                                 StackType_t * const puxStackBuffer,
                                 StaticTask_t * const pxTaskBuffer );

Let's take a look at how this is used in our example, which creates a task with a statically allocated stack:

static StackType_t RedTaskStack[STACK_SIZE];
static StaticTask_t RedTaskTCB;
xTaskCreateStatic( RedTask, "RedTask", STACK_SIZE, NULL,
tskIDLE_PRIORITY + 1,
RedTaskStack, &RedTaskTCB);

Unlike xTaskCreate()xTaskCreateStatic() is guaranteed to always create the task, provided RedTaskStack or RedTaskTCB isn't NULL. As long as your toolchain's linker can find space in RAM to store the variables, the task will be created successfully.

configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h if you wish to make use of the preceding code.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.32.86