|Hint: Use the tree menu to navigate groups of related pages|
[RTOS Task Notification API]
BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry,
TickType_t xTicksToWait );
[If you are using RTOS task notifications to implement binary or counting semaphore type behaviour then use the simpler ulTaskNotifyTake() API function instead of xTaskNotifyWait()]
Each RTOS task has a 32-bit notification value which is initialised to zero when the RTOS task is created. An RTOS task notification is an event sent directly to a task that can unblock the receiving task, and optionally update the receiving task’s notification value in a number of different ways. For example, a notification may overwrite the receiving task’s notification value, or just set one or more bits in the receiving task’s notification value. See the RTOS task notifications use case documentation for examples.
xTaskNotifyWait() waits, with an optional timeout, for the calling task to receive a notification.
If the receiving RTOS task was already Blocked waiting for a notification when one arrives the receiving RTOS task will be removed from the Blocked state and the notification cleared.
ulBitsToClearOnEntry Any bits set in ulBitsToClearOnEntry will be cleared in the calling RTOS task’s notification value on entry to the xTaskNotifyWait() function (before the task waits for a new notification) provided a notification is not already pending when xTaskNotifyWait() is called.
For example, if ulBitsToClearOnEntry is 0x01, then bit 0 of the task’s notification value will be cleared on entry to the function.
Setting ulBitsToClearOnEntry to 0xffffffff (ULONG_MAX) will clear all the bits in the task’s notification value, effectively clearing the value to 0.
ulBitsToClearOnExit Any bits set in ulBitsToClearOnExit will be cleared in the calling RTOS task’s notification value before xTaskNotifyWait() function exits if a notification was received.
The bits are cleared after the RTOS task’s notification value has been saved in *pulNotificationValue (see the description of pulNotificationValue below).
For example, if ulBitsToClearOnExit is 0x03, then bit 0 and bit 1 of the task’s notification value will be cleared before the function exits.
Setting ulBitsToClearOnExit to 0xffffffff (ULONG_MAX) will clear all the bits in the task’s notification value, effectively clearing the value to 0.
pulNotificationValue Used to pass out the RTOS task’s notification value. The value copied to *pulNotificationValue is the RTOS task’s notification value as it was before any bits were cleared due to the ulBitsToClearOnExit setting.
If the notification value is not required then set pulNotificationValue to NULL.
xTicksToWait The maximum time to wait in the Blocked state for a notification to be received if a notification is not already pending when xTaskNotifyWait() is called.
The RTOS task does not consume any CPU time when it is in the Blocked state.
The time is specified in RTOS tick periods. The pdMS_TO_TICKS() macro can be used to convert a time specified in milliseconds into a time specified in ticks.
pdTRUE if a notification was received, or a notification was already
pending when xTaskNotifyWait() was called.
pdFALSE if the call to xTaskNotifyWait() timed out before a notification was received.
[More examples are referenced from the main RTOS task notifications page]
/* This task shows bits within the RTOS task notification value being used to pass
different events to the task in the same way that flags in an event group might
be used for the same purpose. */
void vAnEventProcessingTask( void *pvParameters )
for( ;; )
/* Block indefinitely (without a timeout, so no need to check the function's
return value) to wait for a notification.
Bits in this RTOS task's notification value are set by the notifying
tasks and interrupts to indicate which events have occurred. */
xTaskNotifyWait( 0x00, /* Don't clear any notification bits on entry. */
ULONG_MAX, /* Reset the notification value to 0 on exit. */
&ulNotifiedValue, /* Notified value pass out in
portMAX_DELAY ); /* Block indefinitely. */
/* Process any events that have been latched in the notified value. */
if( ( ulNotifiedValue & 0x01 ) != 0 )
/* Bit 0 was set - process whichever event is represented by bit 0. */
if( ( ulNotifiedValue & 0x02 ) != 0 )
/* Bit 1 was set - process whichever event is represented by bit 1. */
if( ( ulNotifiedValue & 0x04 ) != 0 )
/* Bit 2 was set - process whichever event is represented by bit 2. */
/* Etc. */