0
0
FreeRTOSprogramming~10 mins

xTaskNotify() with value in FreeRTOS - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - xTaskNotify() with value
Task A calls xTaskNotify() with value
Kernel stores notification value for Task B
Task B unblocked or notified
Task B reads notification value
Task B processes notification
Notification cleared or updated
Task A sends a notification with a value to Task B, which then receives and processes it.
Execution Sample
FreeRTOS
xTaskNotify(taskBHandle, 42, eSetValueWithOverwrite);
// Task B waits and reads notification value
uint32_t value;
xTaskNotifyWait(0, 0xffffffffUL, &value, portMAX_DELAY);
Task A sends value 42 to Task B using xTaskNotify(), Task B waits and receives the value.
Execution Table
StepActionTask A StateTask B StateNotification ValueResult
1Task A calls xTaskNotify(taskBHandle, 42, eSetValueWithOverwrite)RunningBlocked (waiting)NoneNotification value 42 stored for Task B
2Kernel unblocks Task BReadyReady42Task B ready to run with notification
3Task B returns from xTaskNotifyWait(0, 0xffffffffUL, &value, portMAX_DELAY)ReadyRunning42Task B reads notification value 42
4Notification cleared after readReadyRunningNoneNotification cleared for Task B
5Task B processes value 42ReadyRunningNoneTask B uses notification value
6No further notificationsReadyRunningNoneExecution continues normally
💡 No more notifications sent; Task B continues running after processing value
Variable Tracker
VariableStartAfter Step 1After Step 3After Step 4Final
Notification ValueNone4242NoneNone
Task A StateReadyRunningReadyReadyReady
Task B StateBlockedBlockedRunningRunningRunning
value (in Task B)UndefinedUndefined424242
Key Moments - 3 Insights
Why does Task B get unblocked after Task A calls xTaskNotify()?
Because xTaskNotify() sends a notification to Task B, the kernel unblocks Task B so it can process the notification, as shown in execution_table step 2.
What happens to the notification value after Task B reads it with xTaskNotifyWait()?
The notification value is cleared after Task B reads it, so it doesn't remain set, as shown in execution_table step 4.
Can Task A overwrite the notification value if it calls xTaskNotify() again before Task B reads it?
Yes, using eSetValueWithOverwrite allows Task A to overwrite the previous notification value before Task B reads it.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the notification value stored for Task B immediately after Task A calls xTaskNotify()?
A42
BNone
C0
DUndefined
💡 Hint
Check execution_table row 1 under 'Notification Value'
At which step does Task B read the notification value?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Look at execution_table rows and find when Task B returns from xTaskNotifyWait()
If Task A calls xTaskNotify() twice with eSetValueWithOverwrite before Task B reads, what happens to the notification value?
AThe first value is kept, second ignored
BThe notification value is overwritten with the second value
CTask B receives both values separately
DNotification value is cleared
💡 Hint
Refer to key_moments about eSetValueWithOverwrite behavior
Concept Snapshot
xTaskNotify(taskHandle, value, action) sends a notification with a value to a task.
The notified task can wait and read the value using xTaskNotifyWait().
Using eSetValueWithOverwrite overwrites previous notification values.
Notification unblocks the task if it was waiting.
After reading, the notification value is cleared.
Full Transcript
This visual execution shows how xTaskNotify() sends a value from one task to another in FreeRTOS. Task A calls xTaskNotify() with a value and an action to overwrite. The kernel stores this value and unblocks Task B if it was waiting. Task B then calls xTaskNotifyWait() to receive the value. After reading, the notification is cleared. This process allows tasks to communicate simple data efficiently. The execution table tracks each step, showing task states and notification values. Key moments clarify why tasks unblock and how values are handled. The quiz tests understanding of notification timing and overwriting behavior.