BaseType_t *pxHigherPriorityTaskWoken );
A version of xTaskNotifyGive() that can be
called from an interrupt service routine (ISR).
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.
vTaskNotifyGiveFromISR() is a function intended for use when an RTOS task notification value
is being used as a light weight
and faster binary or counting semaphore alternative.
FreeRTOS semaphores are given from an interrupt using the xSemaphoreGiveFromISR() API function,
vTaskNotifyGiveFromISR() is the equivalent that instead uses the receiving RTOS
task's notification value.
When a task notification value is being used as a binary or counting semaphore
equivalent then the task being notified should wait for the notification
using the ulTaskNotifyTake() API
function rather than the xTaskNotifyWait()
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
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
*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.
[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
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. */
vTaskNotifyGiveFromISR( xTaskToNotify, &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 )
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 = ulTaskNotifyTake( pdFALSE, xMaxBlockTime );
if( ulNotificationValue == 1 )
/* The transmission ended as expected. */
/* The call to ulTaskNotifyTake() timed out. */
Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd..
See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.