0
0
FreeRTOSprogramming~10 mins

Task function signature in FreeRTOS - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Task function signature
Start Task Function
Function receives void* parameter
Function runs infinite loop
Task does work inside loop
Optionally uses vTaskDelay or other FreeRTOS APIs
Loop repeats forever
Task never returns
A FreeRTOS task function starts with a void pointer parameter and runs an infinite loop doing its work without returning.
Execution Sample
FreeRTOS
void TaskFunction(void *pvParameters) {
    for(;;) {
        // Task code here
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}
This task function runs forever, delaying 1 second each loop iteration.
Execution Table
StepActionParameter (pvParameters)Loop ConditionTask Behavior
1Task startsPointer to parametersEnter infinite loopBegin task work
2Inside loop iteration 1Pointer unchangedLoop continuesExecute task code, call vTaskDelay(1000 / portTICK_PERIOD_MS)
3Inside loop iteration 2Pointer unchangedLoop continuesExecute task code, call vTaskDelay(1000 / portTICK_PERIOD_MS)
4Inside loop iteration 3Pointer unchangedLoop continuesExecute task code, call vTaskDelay(1000 / portTICK_PERIOD_MS)
...Loop repeats foreverPointer unchangedLoop continuesTask keeps running, never returns
💡 Task function never exits; it runs an infinite loop to keep the task alive.
Variable Tracker
VariableStartAfter 1After 2After 3Final
pvParametersPointer to input dataSame pointerSame pointerSame pointerSame pointer
Key Moments - 3 Insights
Why does the task function use an infinite loop?
Because FreeRTOS tasks must keep running to stay alive; the infinite loop ensures the task does not return and get deleted (see execution_table rows 2-5).
What is the purpose of the void* parameter?
It allows passing any data to the task when created; the pointer stays the same throughout the task execution (see variable_tracker).
Can the task function return to end the task?
No, returning would delete the task; tasks should run forever or call vTaskDelete explicitly if they want to end.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what happens to pvParameters after the first loop iteration?
AIt stays the same pointer
BIt becomes NULL
CIt changes to a new pointer
DIt is freed automatically
💡 Hint
Check the 'Parameter (pvParameters)' column in execution_table rows 2 and 3.
At which step does the task function exit the infinite loop?
AStep 1
BStep 3
CIt never exits
DAfter the third iteration
💡 Hint
See the 'Loop Condition' column in execution_table; the loop continues forever.
If the infinite loop was removed, what would happen to the task?
AThe task would run forever anyway
BThe task would run once and then delete itself
CThe task would never start
DThe task would crash the system
💡 Hint
Refer to key_moments about why the infinite loop is needed to keep the task alive.
Concept Snapshot
FreeRTOS task functions have this signature:
void TaskFunction(void *pvParameters)
{
    for(;;) {
        // task code
        vTaskDelay(...);
    }
}
They receive a void pointer parameter and run an infinite loop to stay alive.
Full Transcript
A FreeRTOS task function must have the signature void TaskFunction(void *pvParameters). It receives a pointer to any data passed when the task is created. The function runs an infinite loop to keep the task alive and perform its work repeatedly. Inside the loop, it can call FreeRTOS APIs like vTaskDelay to wait or yield. The task function never returns; returning would delete the task. The parameter pointer remains unchanged during execution. This pattern ensures the task runs continuously until explicitly deleted.