Updated Apr 2025

vTaskNotifyGiveFromISR, vTaskNotifyGiveIndexedFromISR

[RTOS Task Notification API]

task.h

1void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
2 BaseType_t *pxHigherPriorityTaskWoken );
3
4void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle,
5 UBaseType_t uxIndexToNotify,
6 BaseType_t *pxHigherPriorityTaskWoken );

Versions of

xTaskNotifyGive()
and
xTaskNotifyGiveIndexed()
that can be used from an interrupt service routine (ISR). See the documentation page for the xTaskNotifyGive() API function for a description of their operation and the necessary configuration parameters, as well as backward compatibility information.

Parameters:

  • xTaskToNotify

    The handle of the RTOS task being notified, and having its notification value incremented. To obtain a task's handle create the task using xTaskCreate() and make use of the

    pxCreatedTask
    parameter, or create the task using xTaskCreateStatic() and store the returned value, or use the task's name in a call to xTaskGetHandle(). The handle of the currently executing RTOS task is returned by the xTaskGetCurrentTaskHandle() API function.

  • uxIndexToNotify

    The index within the target task's array of notification values to which the notification is to be sent.

    uxIndexToNotify
    must be less than
    configTASK_NOTIFICATION_ARRAY_ENTRIES
    .
    xTaskNotifyGiveFromISR()
    does not have this parameter and always sends notifications to index 0.

  • pxHigherPriorityTaskWoken

    *pxHigherPriorityTaskWoken
    must be initialised to 0.
    vTaskNotifyGiveFromISR()
    will set
    *pxHigherPriorityTaskWoken
    to
    pdTRUE
    if sending the notification caused a task to unblock, and the unblocked task has a priority higher than the currently running task. If
    vTaskNotifyGiveFromISR()
    sets this value to
    pdTRUE
    then a context switch should be requested before the interrupt is exited. See the example below.
    pxHigherPriorityTaskWoken
    is an optional parameter and can be set to NULL.

Example usage:

[More examples are referenced from the main RTOS task notifications page]

1/* This is an example of a transmit function in a generic peripheral driver. An
2 RTOS task calls the transmit function, then waits in the Blocked state (so not
3 using an CPU time) until it is notified that the transmission is complete. The
4 transmission is performed by a DMA, and the DMA end interrupt is used to notify
5 the task. */
6static TaskHandle_t xTaskToNotify = NULL;
7
8/* The peripheral driver's transmit function. */
9void StartTransmission( uint8_t *pcData, size_t xDataLength )
10{
11 /* At this point xTaskToNotify should be NULL as no transmission is in
12 progress. A mutex can be used to guard access to the peripheral if
13 necessary. */
14 configASSERT( xTaskToNotify == NULL );
15
16 /* Store the handle of the calling task. */
17 xTaskToNotify = xTaskGetCurrentTaskHandle();
18
19 /* Start the transmission - an interrupt is generated when the transmission
20 is complete. */
21 vStartTransmit( pcData, xDatalength );
22}
23
24/*-----------------------------------------------------------*/
25
26/* The transmit end interrupt. */
27void vTransmitEndISR( void )
28{
29 BaseType_t xHigherPriorityTaskWoken = pdFALSE;
30
31 /* At this point xTaskToNotify should not be NULL as a transmission was
32 in progress. */
33 configASSERT( xTaskToNotify != NULL );
34
35 /* Notify the task that the transmission is complete. */
36 vTaskNotifyGiveIndexedFromISR( xTaskToNotify, 0, &xHigherPriorityTaskWoken );
37
38 /* There are no transmissions in progress, so no tasks to notify. */
39 xTaskToNotify = NULL;
40
41 /* If xHigherPriorityTaskWoken is now set to pdTRUE then a context switch
42 should be performed to ensure the interrupt returns directly to the highest
43 priority task. The macro used for this purpose is dependent on the port in
44 use and may be called portEND_SWITCHING_ISR(). */
45 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
46}
47
48/*-----------------------------------------------------------*/
49
50/* The task that initiates the transmission, then enters the Blocked state (so
51 not consuming any CPU time) to wait for it to complete. */
52void vAFunctionCalledFromATask( uint8_t ucDataToTransmit, size_t xDataLength )
53{
54 uint32_t ulNotificationValue;
55 const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );
56
57 /* Start the transmission by calling the function shown above. */
58 StartTransmission( ucDataToTransmit, xDataLength );
59
60 /* Wait for the transmission to complete. */
61 ulNotificationValue = ulTaskNotifyTakeIndexed( 0, pdFALSE, xMaxBlockTime );
62
63 if( ulNotificationValue == 1 )
64 {
65 /* The transmission ended as expected. */
66 }
67 else
68 {
69 /* The call to ulTaskNotifyTake() timed out. */
70 }
71}