下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

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

xEventGroupSetBits()
[事件组 API]



event_groups.h

 EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
                                 const EventBits_t uxBitsToSet );

在 RTOS 事件组中设置位(标志)。 无法从中断调用此函数。 xEventGroupSetBitsFromISR() 是可从中断调用的版本。

在事件组中设置位将自动解除 所有等待位的任务的阻塞态。

RTOS 源文件 FreeRTOS/source/event_groups.c 必须 包含在构建中,xEventGroupSetBits() 函数才可用。

参数:
xEventGroup   要设置位的事件组。 该 必须已通过 通过调用 xEventGroupCreate() 创建。
uxBitsToSet   指定要在事件组中设置的一个或多个位的按位值。 例如,将 uxBitsToSet 设置为 0x08,可仅设置位 3。 将 uxBitsToSet 设置 为 0x09,可设置位 3 和位 0。
返回:
调用 xEventGroupSetBits() 返回时事件组的值。

返回值可能会 清除 uxBitsToSet 参数指定的位,有如下两个原因:

  1. 如果设置某个位导致正在等待该位的任务 解除阻塞态, 则可能该位 已被自动清除(请参阅 xEventGroupWaitBits() 的 xClearBitOnExit 参数)。

  2. 将执行任何处于阻塞态(或就绪态)且优先级 高于调用 xEventGroupSetBits() 的任务, 并可能在调用 xEventGroupSetBits() 返回之前 更改事件组值。
用法示例:
#define BIT_0	( 1 << 0 )
#define BIT_4	( 1 << 4 )

void aFunction( EventGroupHandle_t xEventGroup )
{
EventBits_t uxBits;

  /* Set bit 0 and bit 4 in xEventGroup. */
  uxBits = xEventGroupSetBits(
                              xEventGroup,    /* The event group being updated. */
                              BIT_0 | BIT_4 );/* The bits being set. */

  if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
  {
      /* Both bit 0 and bit 4 remained set when the function returned. */
  }
  else if( ( uxBits & BIT_0 ) != 0 )
  {
      /* Bit 0 remained set when the function returned, but bit 4 was
      cleared.  It might be that bit 4 was cleared automatically as a
      task that was waiting for bit 4 was removed from the Blocked
      state. */
  }
  else if( ( uxBits & BIT_4 ) != 0 )
  {
      /* Bit 4 remained set when the function returned, but bit 0 was
      cleared.  It might be that bit 0 was cleared automatically as a
      task that was waiting for bit 0 was removed from the Blocked
      state. */
  }
  else
  {
      /* Neither bit 0 nor bit 4 remained set.  It might be that a task
      was waiting for both of the bits to be set, and the bits were cleared
      as the task left the Blocked state. */
  }
}





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