Download FreeRTOS

Quality RTOS & Embedded Software

FreeRTOS website now available in Simplified Chinese
New FreeRTOS Long Term Support version now available.
FreeRTOS Extended Maintenance Program (EMP) registration now open.
FreeRTOS-Plus-TCP v3.0.0 released:
Featured FreeRTOS IoT Integrations:

vTaskNotifyGiveFromISR / vTaskNotifyGiveIndexedFromISR
[RTOS Task Notification API]


 void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
                              BaseType_t *pxHigherPriorityTaskWoken );

void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, 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.

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]

/* This is an example of a transmit function in a generic peripheral driver. An
RTOS task calls the transmit function, then waits in the Blocked state (so not
using an CPU time) until it is notified that the transmission is complete. The
transmission is performed by a DMA, and the DMA end interrupt is used to notify
the task. */

static TaskHandle_t xTaskToNotify = NULL;

/* The peripheral driver's transmit function. */
void StartTransmission( uint8_t *pcData, size_t xDataLength )
/* At this point xTaskToNotify should be NULL as no transmission is in
progress. A mutex can be used to guard access to the peripheral if
necessary. */

configASSERT( xTaskToNotify == NULL );

/* Store the handle of the calling task. */
xTaskToNotify = xTaskGetCurrentTaskHandle();

/* Start the transmission - an interrupt is generated when the transmission
is complete. */

vStartTransmit( pcData, xDatalength );

/* The transmit end interrupt. */
void vTransmitEndISR( void )
BaseType_t xHigherPriorityTaskWoken = pdFALSE;

/* At this point xTaskToNotify should not be NULL as a transmission was
in progress. */

configASSERT( xTaskToNotify != NULL );

/* Notify the task that the transmission is complete. */
vTaskNotifyGiveIndexedFromISR( xTaskToNotify, 0, &xHigherPriorityTaskWoken );

/* There are no transmissions in progress, so no tasks to notify. */
xTaskToNotify = NULL;

/* If xHigherPriorityTaskWoken is now set to pdTRUE then a context switch
should be performed to ensure the interrupt returns directly to the highest
priority task. The macro used for this purpose is dependent on the port in
use and may be called portEND_SWITCHING_ISR(). */

portYIELD_FROM_ISR( xHigherPriorityTaskWoken );

/* The task that initiates the transmission, then enters the Blocked state (so
not consuming any CPU time) to wait for it to complete. */

void vAFunctionCalledFromATask( uint8_t ucDataToTransmit, size_t xDataLength )
uint32_t ulNotificationValue;
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );

/* Start the transmission by calling the function shown above. */
StartTransmission( ucDataToTransmit, xDataLength );

/* Wait for the transmission to complete. */
ulNotificationValue = ulTaskNotifyTakeIndexed( 0, pdFALSE, xMaxBlockTime );

if( ulNotificationValue == 1 )
/* The transmission ended as expected. */
/* The call to ulTaskNotifyTake() timed out. */

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.