下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

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

xTaskNotifyAndQueryFromISR / xTaskNotifyAndQueryIndexedFromISR
[ RTOS任务通知API 函数]


task.h

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

BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue, BaseType_t *pxHigherPriorityTaskWoken );

请参阅 请参阅RTOS任务通知

xTaskNotifyAndQueryIndexedFromISR() 执行的操作 与xTaskNotifyIndexedFromISR() 执行的操作相同,此外, 还会在附加的 pulPreviousNotifyValue 参数中 返回目标任务的先前通知值 (函数被调用时的通知值,而不是函数返回时的通知值)。

xTaskNotifyAndQueryFromISR() 执行的操作与 xTaskNotifyFromISR() 执行的操作相同,此外 还会在附加的 pulPreviousNotifyValue 参数中 返回目标任务的先前通知值 (函数被调用时的通知值,而不是函数返回时的通知值)。

参数:
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()。

pxHigherPriorityTaskWoken   * pxHigherPriorityTaskWoken必须初始化为pdFALSE (0)。

xTaskNotifyAndQueryFromISR ()将设置* pxHigherPriorityTaskWoken 如果发送通知导致一个任务解除阻塞,且解除阻塞的任务的优先级高于当前正在运行的任务, 那么xTaskNotifyFromISR()将把*pxHigherPriorityTaskWoken设置 为pdTRUE。

如果xTaskNotifyAndQueryFromISR()将该值设置为pdTRUE 那么应该在中断退出之前请求 切换上下文。请参阅以下示例。

pxHigherPriorityTaskWoken 为可选参数,且可 设置为 NULL。

eAction Setting 已执行的操作
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。


用法示例:


void vAnISR( void )
{
/* Must be Initialised to pdFALSE! */
BaseType_t xHigherPriorityTaskWoken = pdFALSE.
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. */

xTaskNotifyAndQueryIndexedFromISR( xTask1Handle,
0,
( 1UL << 8UL ),
eSetBits,
&ulPreviousValue,
&xHigherPriorityTaskWoken );

/* The task's previous notification value is saved in
ulPreviousValue. */


/* If the task referenced by xTask1Handle was in the Blocked
state, waiting for the notification, then it will now have been
moved from the Blocked state to the Ready state. If its priority
is higher than the priority of the currently executing task (the
task this interrupt interrupted) then xHigherPriorityTaskWoken will
have been set to pdTRUE, and passing the variable into a call to
portYIELD_FROM_ISR() will result in the interrupt returning directly
to the unblocked task. If xHigherPriorityTaskWoken is still pdFALSE
then passing it into portYIELD_FROM_ISR() will have no effect. */


portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}





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