Updated Apr 2025
vTaskNotifyGiveFromISR, vTaskNotifyGiveIndexedFromISR
task.h
1void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify,2 BaseType_t *pxHigherPriorityTaskWoken );34void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle,5 UBaseType_t uxIndexToNotify,6 BaseType_t *pxHigherPriorityTaskWoken );
Versions of
xTaskNotifyGive()
xTaskNotifyGiveIndexed()
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
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.pxCreatedTask -
uxIndexToNotify
The index within the target task's array of notification values to which the notification is to be sent.
must be less thanuxIndexToNotify.configTASK_NOTIFICATION_ARRAY_ENTRIESdoes not have this parameter and always sends notifications to index 0.xTaskNotifyGiveFromISR() -
pxHigherPriorityTaskWoken
must be initialised to 0.*pxHigherPriorityTaskWokenwill setvTaskNotifyGiveFromISR()to*pxHigherPriorityTaskWokenif sending the notification caused a task to unblock, and the unblocked task has a priority higher than the currently running task. IfpdTRUEsets this value tovTaskNotifyGiveFromISR()then a context switch should be requested before the interrupt is exited. See the example below.pdTRUEis an optional parameter and can be set to NULL.pxHigherPriorityTaskWoken
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. An2 RTOS task calls the transmit function, then waits in the Blocked state (so not3 using an CPU time) until it is notified that the transmission is complete. The4 transmission is performed by a DMA, and the DMA end interrupt is used to notify5 the task. */6static TaskHandle_t xTaskToNotify = NULL;78/* 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 in12 progress. A mutex can be used to guard access to the peripheral if13 necessary. */14 configASSERT( xTaskToNotify == NULL );1516 /* Store the handle of the calling task. */17 xTaskToNotify = xTaskGetCurrentTaskHandle();1819 /* Start the transmission - an interrupt is generated when the transmission20 is complete. */21 vStartTransmit( pcData, xDatalength );22}2324/*-----------------------------------------------------------*/2526/* The transmit end interrupt. */27void vTransmitEndISR( void )28{29 BaseType_t xHigherPriorityTaskWoken = pdFALSE;3031 /* At this point xTaskToNotify should not be NULL as a transmission was32 in progress. */33 configASSERT( xTaskToNotify != NULL );3435 /* Notify the task that the transmission is complete. */36 vTaskNotifyGiveIndexedFromISR( xTaskToNotify, 0, &xHigherPriorityTaskWoken );3738 /* There are no transmissions in progress, so no tasks to notify. */39 xTaskToNotify = NULL;4041 /* If xHigherPriorityTaskWoken is now set to pdTRUE then a context switch42 should be performed to ensure the interrupt returns directly to the highest43 priority task. The macro used for this purpose is dependent on the port in44 use and may be called portEND_SWITCHING_ISR(). */45 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );46}4748/*-----------------------------------------------------------*/4950/* The task that initiates the transmission, then enters the Blocked state (so51 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 );5657 /* Start the transmission by calling the function shown above. */58 StartTransmission( ucDataToTransmit, xDataLength );5960 /* Wait for the transmission to complete. */61 ulNotificationValue = ulTaskNotifyTakeIndexed( 0, pdFALSE, xMaxBlockTime );6263 if( ulNotificationValue == 1 )64 {65 /* The transmission ended as expected. */66 }67 else68 {69 /* The call to ulTaskNotifyTake() timed out. */70 }71}