xEventGroupSetBitsFromISR()
[事件组 API]
event_groups.h
BaseType_t xEventGroupSetBitsFromISR(
EventGroupHandle_t xEventGroup,
const EventBits_t uxBitsToSet,
BaseType_t *pxHigherPriorityTaskWoken );
在RTOS 事件组中设置位(标志)。
可以从中断服务程序 (ISR) 调用的 xEventGroupSetBits() 版本
。
在事件组中设置位将自动解除
所有等待位的任务的阻塞状态。
在事件组中设置位不是确定性操作,因为
可能有未知数量的任务正在等待设置一个
或多个位。 FreeRTOS 不允许在中断或临界区
中执行不确定的操作。 因此, xEventGroupSetBitFromISR()
会向 RTOS 守护进程任务发送一条消息,
从而在守护进程任务的上下文中执行设置操作,其中使用的是调度器锁
而非临界区。
注意: 如上文所述,从中断服务程序中设置位
会将设置操作推迟到 RTOS 守护进程任务(也叫定时器服务任务)
。 RTOS守护进程任务
与其他RTOS任务一样, 都是根据优先级进行调度的。 因此,如果置位操作必须立即完成
(在应用程序创建的任务执行之前),
那么RTOS守护进程任务的优先级必须要高于
其他使用事件组的任务。 RTOS守护进程任务的优先级由
configTIMER_TASK_PRIORITY
在FreeRTOSConfig.h中定义。
INCLUDE_xEventGroupSetBitFromISR, configUSE_TIMERS 和INCLUDE_xTimerPendFunctionCall
必须在FreeRTOSConfig.h中全部设置为1,才能使用xEventGroupSetBitsFromISR()
函数。
RTOS源文件 FreeRTOS/source/event_groups.c 必须
包含在构建中,才能使用xEventGroupSetBitsFromISR()函数。
-
参数:
-
xEventGroup
|
要设置位的事件组。 该
必须已通过
通过调用 xEventGroupCreate() 创建。
|
uxBitsToSet
|
指定要设置的一个或多个位的按位值。
例如,要设置位3,便将uxBitsToSet设置为0x08。 将 uxBitsToSet 设置
位3和位0,便将uxBitsToSet设置为0x09。
|
pxHigherPriorityTaskWoken
|
如上所述,调用此函数
将意味着给RTOS守护进程任务发送一条消息。 如果
守护进程任务的优先级高于
当前正在运行的任务(中断中断的任务),
那么xEventGroupSetBitsFromISR()会将*pxHigherPriorityTaskWoken设置为pdTRUE,
指示应在中断退出之前
请求上下文切换。 因此
必须将 *pxHigherPriorityTaskWoken 初始化为 pdFALSE。 请参阅
下面的代码示例。
|
-
返回:
-
如果消息已发送到RTOS守护进程任务,则返回pdPASS,
否则将返回pdFAIL。 如果
计时器服务队列已满,则将返回pdFAIL 。
用法示例:
#define BIT_0 ( 1 << 0 )
#define BIT_4 ( 1 << 4 )
/* An event group which it is assumed has already been created by a call to
xEventGroupCreate(). */
EventGroupHandle_t xEventGroup;
void anInterruptHandler( void )
{
BaseType_t xHigherPriorityTaskWoken, xResult;
/* xHigherPriorityTaskWoken must be initialised to pdFALSE. */
xHigherPriorityTaskWoken = pdFALSE;
/* Set bit 0 and bit 4 in xEventGroup. */
xResult = xEventGroupSetBitsFromISR(
xEventGroup, /* The event group being updated. */
BIT_0 | BIT_4, /* The bits being set. */
&xHigherPriorityTaskWoken );
/* Was the message posted successfully? */
if( xResult != pdFAIL )
{
/* If xHigherPriorityTaskWoken is now set to pdTRUE then a context
switch should be requested. The macro used is port specific and will
be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to
the documentation page for the port being used. */
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
}
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.