Quality RTOS & Embedded Software

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




xTaskNotifyAndQuery()
[RTOS Task Notification API]


task.h

 BaseType_t xTaskNotifyAndQuery( TaskHandle_t xTaskToNotify,
                                 uint32_t ulValue,
                                 eNotifyAction eAction,
                                 uint32_t *pulPreviousNotifyValue );

[If you are using RTOS task notifications to implement binary or counting semaphore type behaviour then use the simpler xTaskNotifyGive() API function instead of xTaskNotifyAndQuery().]

xTaskNotifyAndQuery() is similar to xTaskNotify(), but contains an additional parameter in which the subject task's previous notification value is returned.

Each RTOS task has a 32-bit notification value which is initialised to zero when the RTOS task is created. xTaskNotifyAndQuery() is used to send an event directly to and potentially unblock an RTOS task, and optionally update the receiving task's notification value in one of the following ways:

  • Write a 32-bit number to the notification value
  • Add one (increment) the notification value
  • Set one or more bits in the notification value
  • Leave the notification value unchanged

This function must not be called from an interrupt service routine (ISR).

Parameters:
xTaskToNotify   The handle of the RTOS task being notified. This is the subject 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.

ulValue   Used to update the notification value of the subject task. See the description of the eAction parameter below.
eAction   An enumerated type that can take one of the values documented in the table below in order to perform the associated action.
pulPreviousNotifyValue   Can be used to pass out the subject task's notification value before any bits are modified by the action of xTaskNotifyAndQuery().

pulPreviousNotifyValue is an optional parameter, and can be set to NULL if it is not required. If pulPreviousNotifyValue is not used then consider using xTaskNotify() in place of xTaskNotifyAndQuery().

eAction Setting Action Performed
eNoAction The subject task receives the event, but its notification value is not updated. In this case ulValue is not used.

eSetBits The notification value of the subject task will be bitwise ORed with ulValue. For example, if ulValue is set to 0x01, then bit 0 will get set within the subject task's notification value. Likewise if ulValue is 0x04 then bit 2 will get set in the subject task's notification value. In this way the RTOS task notification mechanism can be used as a light weight alternative to an event group.

eIncrement The notification value of the subject task will be incremented by one, making the call to xTaskNotify() equivalent to a call to xTaskNotifyGive(). In this case ulValue is not used.
eSetValueWithOverwrite The notification value of the subject task is unconditionally set to ulValue. In this way the RTOS task notification mechanism is being used as a light weight alternative to xQueueOverwrite().
eSetValueWithoutOverwrite If the subject task does not already have a notification pending then its notification value will be set to ulValue.

If the subject task already has a notification pending then its notification value is not updated as to do so would overwrite the previous value before it was used. In this case the call to xTaskNotify() fails and pdFALSE is returned.

In this way the RTOS task notification mechanism is being used as a light weight alternative to xQueueSend() on a queue of length 1.

Returns:
pdPASS is returned in all cases other than when eAction is set to eSetValueWithoutOverwrite and the subject task's notification value cannot be updated because the subject task already had a notification pending.


Example usage:

uint32_t ulPreviousValue;

    /* Set bit 8 in the notification value of the task referenced by xTask1Handle.
    Store the task's previous notification value (before bit 8 is set) in
    ulPreviousValue. */
    xTaskNotifyAndQuery( xTask1Handle, ( 1UL << 8UL ), eSetBits, &ulPreviousValue );

    /* Send a notification to the task referenced by xTask2Handle, potentially
    removing the task from the Blocked state, but without updating the task's
    notification value.  Store the tasks notification value in ulPreviousValue. */
    xTaskNotifyAndQuery( xTask2Handle, 0, eNoAction, &ulPreviousValue );

    /* Set the notification value of the task referenced by xTask3Handle to 0x50,
    even if the task had not read its previous notification value. The task's
    previous notification value is of no interest so the last parameter is set
    to NULL. */
    xTaskNotifyAndQuery( xTask3Handle, 0x50, eSetValueWithOverwrite,  NULL );

    /* Set the notification value of the task referenced by xTask4Handle to 0xfff,
    but only if to do so would not overwrite the task's existing notification
    value before the task had obtained it (by a call to xTaskNotifyWait()
    or ulTaskNotifyTake()).  The task's previous notification value is saved
    in ulPreviousValue. */
    if( xTaskNotifyAndQuery( xTask4Handle,
                             0xfff,
                             eSetValueWithoutOverwrite,
                             &ulPreviousValue ) == pdPASS )
    {
        /* The task's notification value was updated. */
    }
    else
    {
        /* The task's notification value was not updated. */
    }







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




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.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists