下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

内核
最新资讯
简化任何设备的身份验证云连接。
利用 CoAP 设计节能型云连接 IoT 解决方案。
11.0.0 版 FreeRTOS 内核简介:
FreeRTOS 路线图和代码贡献流程。
使用 FreeRTOS 实现 OPC-UA over TSN。

xTaskNotifyAndQuery / xTaskNotifyAndQueryIndexed
[RTOS 直达任务通知 API]


task.h

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

请参阅 RTOS 任务通知了解详情。

xTaskNotifyAndQueryIndexed() 执行的 操作与 xTaskNotifyIndexed() 相同, 还会在附加的 pulPreviousNotifyValue 参数中 返回目标任务的上一个通知值 (调用函数时的通知值,而不是函数返回时的通知值)。

xTaskNotifyAndQuery() 执行的 操作与 xTaskNotify() 相同, 同样,还会在附加的 pulPreviousNotifyValue 参数中 返回目标任务的上一个通知值 (调用函数时的通知值, 而不是函数返回时的通知值)。

不得从中断服务程序 (ISR) 调用此函数。 使用 xTaskNotifyAndQueryFromISR() 代替。

参数:
xTaskToNotify   正在通知的 RTOS 任务的句柄。 这是目标任务。

要获取任务句柄, xTaskCreate() 创建任务并使用 pxCreatedTask 参数,或使用返回值创建任务 xTaskCreateStatic() 并存储该值,或在 调用 xTaskGetHandle() 中使用任务的名称。

当前执行的 RTOS 任务的句柄通过以下方式 由 xTaskGetCurrentTaskHandle() API 函数返回。

uxIndexToNotify   目标任务通知值数组中的索引, 通知值将发送给该索引。

uxIndexToNotify 必须小于 configTASK_NOTIFICATION_ARRAY_ENTRIES。

ulValue   用于更新目标任务的通知值。 请参阅下面 eAction 参数的说明。
eAction   一种枚举类型,可以采用 下表中记录的值之一来执行相关操作。
pulPreviousNotifyValue   可用于在 xTaskNotifyAndQuery() 操作修改任何位之前 传递目标任务的通知值。

pulPreviousNotifyValue 是一个可选参数, 如不需要,可设置为 NULL。 如果未使用 pulPreviousNotifyValue, 则考虑使用 xTaskNotify() 来 代替 xTaskNotifyAndQuery()。

eAction 设置 已执行的操作
eNoAction 目标任务接收事件,但其 通知值未更新。 在这种情况下,不使用 ulValue。

eSetBits 目标任务的通知值 使用 ulValue 按位或运算。 例如, 如果 ulValue 设置为 0x01,则将在 目标任务的通知值中设置位 0。 同样,如果 ulValue 为 0x04,则将在 目标任务的通知值中设置位 2。 通过这种方式,RTOS 任务通知机制 可以用作 事件组的轻量级替代方案。

eIncrement 目标任务的通知值 自增 1,使得调用 xTaskNotify() 相当于调用 xTaskNotifyGive()。 在这种情况下,不使用 ulValue。
eSetValueWithOverwrite 目标任务的通知值 无条件设置为 ulValue。 因此, RTOS 任务通知机制可用作 xQueueOverwrite() 的轻量级替代方案。
eSetValueWithoutOrwrite 如果目标任务没有 挂起的通知,则其通知值 将设置为 ulValue。

如果目标任务已经有 挂起的通知,则不会更新其通知值, 因为这样做会覆盖 之前使用的值。 在这种情况下, 调用 xTaskNotify() 失败,返回 pdFALSE。

因此,RTOS 任务通知机制可 在长度为 1 的队列上用作 xQueueSend() 在长度为 的轻量级替代方案。

返回:
除了 eAction 被设置为 eSetValueWithoutOverwrite 且目标任务的通知值 因目标任务已有挂起的通知而无法更新之外, 在所有情况下均返回 pdPASS。


用法示例:


uint32_t ulPreviousValue;

/* Set bit 8 in the 0th notification value of the task referenced
by xTask1Handle. Store the task's previous 0th notification
value (before bit 8 is set) in ulPreviousValue. */

xTaskNotifyAndQueryIndexed( xTask1Handle,
0,
( 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. */
}





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