Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




xTaskNotifyStateClear()
[RTOS Task Notification API]


task.h

 BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );

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.

If a task is in the Blocked state to wait for a notification when the notification arrives then the task immediately exits the Blocked state and the notification does not remain pending. If a task was not waiting for a notification when a notification arrives then the notification will remain pending until the receiving task reads its notification value.

xTaskNotifyStateClear() is used to clear (Pending to Not Pending) a pending notification without the receiving task first needing to read its notification value.

xTaskNotifyStateClear() does not change the notification value.

Parameters:
xTask   The handle of the RTOS task that will have its notification state cleared. Set xTask to NULL to clear the notification state of the calling task.

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:
If the task referenced by xTask had a notification pending, and the notification was cleared, then pdTRUE is returned. If the task referenced by xTask didn't have a notification pending then pdFALSE is returned.


Example usage:

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

/* An example UART send function.  The function starts a UART transmission then
waits to be notified that the transmission is complete.  The transmission
complete notification is sent from the UART interrupt.  The calling task's
notification state is cleared before the transmission is started to ensure it is
not co-incidentally already pending before the task attempts to block on its
notification state. */
void vSerialPutString( const signed char * const pcStringToSend,
                       unsigned short usStringLength )
{
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 5000 );

    /* xSendingTask holds the handle of the task waiting for the transmission to
    complete.  If xSendingTask is NULL then a transmission is not in progress.
    Don't start to send a new string unless transmission of the previous string
    is complete. */
    if( ( xSendingTask == NULL ) && ( usStringLength > 0 ) )
    {
        /* Ensure the calling task's notification state is not already
        pending. */
        xTaskNotifyStateClear( NULL );

        /* Store the handle of the transmitting task.  This is used to unblock
        the task when the transmission has completed. */
        xSendingTask = xTaskGetCurrentTaskHandle();

        /* Start sending the string - the transmission is then controlled by an
        interrupt. */
        UARTSendString( pcStringToSend, usStringLength );

        /* Wait in the Blocked state (so not using any CPU time) until the UART
        ISR sends a notification to xSendingTask to notify (and unblock) the
        task when the transmission is complete. */
        ulTaskNotifyTake( pdTRUE, xMaxBlockTime );
    }
}






[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS