task.h
BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );
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.
xTaskNotifyGive() is a macro 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 using the xSemaphoreGive() API function, xTaskNotifyGive()
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()
API function.
xTaskNotifyGive() must not be called from an interrupt service routine. Use
vTaskNotifyGiveFromISR() instead.
-
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.
|
-
Returns:
-
xTaskNotifyGive() is a macro that calls xTaskNotify() with the
eAction parameter set to eIncrement resulting in all calls returning pdPASS.
Example usage:
[More examples are referenced from the main RTOS task notifications page]
/* Prototypes of the two tasks created by main(). */
static void prvTask1( void *pvParameters );
static void prvTask2( void *pvParameters );
/* Handles for the tasks create by main(). */
static TaskHandle_t xTask1 = NULL, xTask2 = NULL;
/* Create two tasks that send notifications back and forth to each other, then
start the RTOS scheduler. */
void main( void )
{
xTaskCreate( prvTask1, "Task1", 200, NULL, tskIDLE_PRIORITY, &xTask1 );
xTaskCreate( prvTask2, "Task2", 200, NULL, tskIDLE_PRIORITY, &xTask2 );
vTaskStartScheduler();
}
/*-----------------------------------------------------------*/
static void prvTask1( void *pvParameters )
{
for( ;; )
{
/* Send a notification to prvTask2(), bringing it out of the Blocked
state. */
xTaskNotifyGive( xTask2 );
/* Block to wait for prvTask2() to notify this task. */
ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
}
}
/*-----------------------------------------------------------*/
static void prvTask2( void *pvParameters )
{
for( ;; )
{
/* Block to wait for prvTask1() to notify this task. */
ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
/* Send a notification to prvTask1(), bringing it out of the Blocked
state. */
xTaskNotifyGive( xTask1 );
}
}
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|