ulTaskNotifyValueClear / ulTaskNotifyValueClearIndexed
[RTOS 任务通知 API]
task.h
uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask,
uint32_t ulBitsToClear );
uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask,
UBaseType_t uxIndexToClear,
uint32_t ulBitsToClear );
每个 RTOS 任务都有一个
任务通知数组。 每条任务通知
都有
通知状态 ,可以是“挂起”或“非挂起” ,
以及一个 32 位
通知值。
ulTaskNotifyValueClearIndexed() 清除
xTask 引用的任务的数组索引 uxIndexToClear 的通知值中 ulBitsToClear 位掩码指定的位。
ulTaskNotifyValueClear() 和 ulTaskNotifyValueClearIndexed() 是等效的宏 - 唯一的区别
是 ulTaskNotifyValueClearIndexed() 可以对
数组中的任何任务通知进行操作,而 ulTaskNotifyValueClear() 始终在数组索引 0 处对任务通知进行操作。
configUSE_TASK_NOTIFICATIONS
必须在 FreeRTOSConfig.h 中设置为 1(或保留为未定义)才能使用这些宏。
常量
configTASK_NOTIFICATION_ARRAY_ENTRIES 设置
每个任务的任务通知数组中的索引数。
- 参数:
-
xTask
|
将清除其通知值中的位的 RTOS 任务的句柄。将 xTask 设置为 NULL 以清除调用任务的通知值中的位。
若要获取任务句柄,请使用 xTaskCreate() 创建任务并使用 pxCreatedTask 参数,或使用 xTaskCreateStatic() 创建任务并存储返回值,或在调用 xTaskGetHandle() 时使用任务名称。
当前执行的 RTOS 任务的句柄由 xTaskGetCurrentTaskHandle() API 函数返回。
|
uxIndexToClear
|
目标任务的通知值数组中的索引,
用于清除其中的位。 uxIndexToClear
必须小于 configTASK_NOTIFICATION_ARRAY_ENTRIES。
ulTaskNotifyValueClear() 没有此参数,并且始终清除
索引 0 处的通知值中的位。
|
ulBitsToClear
|
要在 xTask 的通知值中清除的位的位掩码
。将位设置为 1 可清除任务的通知值中的相应位
。 将 ulBitsToClear 设置为 0xffffffff(32 位架构上的 UINT_MAX)以
将通知值清除为 0。 将 ulBitsToClear 设置为 0 以查询任务的
通知值,而不清除任何位。
|
- 返回:
- 清除
ulBitsToClear 指定的位之前的目标任务的通知值。
用法示例:
#define MESSAGE_RECEIVED_BIT 8
#define TICKS_UNTIL_TIMEOUT 100
unsigned long ulNotification, ulMessageReceivedMask;
/* Clear any message received events. */
ulMessageReceivedMask = 1u << MESSAGE_RECEIVED_BIT;
ulTaskNotifyValueClear( ulMessageReceivedMask );
/* Send a message that expects a response. */
send_message();
/* Block this task until it has another pending notification. In this example,
the task only ever uses the MESSAGE_RECEIVED_BIT of its notification value,
so the next event can only ever be on message received. */
xTaskNotifyWait( 0u, /* Don't clear any notification bits on entry. */
0u, /* Don't clear any notification bits on exit. */
&ulNotification,
TICKS_UNTIL_TIMEOUT );
/* If there wasn't a timeout, then the only possible event was received.
In this example, that is the MESSAGE_RECEIVED_EVENT. */
if( ulNotification == 0u )
{
/* Handle the response timeout. */
process_response_timeout();
}
else if( ulNotification == ulMessageReceivedMask )
{
/* Process the response event. */
process_response();
ulTaskNotifyValueClear( ulMessageReceivedMask );
}
else
{
/* The example task should only ever receive MESSAGE_RECEIVED_EVENTS. */
process_error();
}
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.