事件组(Event Groups)

  这是一位事件位
0 0 0 1 0
↑↑↑这是一个五位事件组↑↑↑

通过事件组,同时记录多个事件的发生状态,0无1有。

使用流程:

创建事件组->等待事件组中某个标志位->设置标志位->清除标志位

1.  创建事件组

同样,需要先创建事件组的句柄,再定义两事件位。

static EventGroupHandle_t test_event_handle;
//创建事件组句柄,名字为test_event_handle
test_event_handle = xEventGroupCreate();
//给test_event_handle创建事件组

2.  读取&处理事件组

读取:xEventGroupWaitBits这个函数有返回值为事件组的16进制值,也就是表格中的00010B=>0x02,第三位表示是否清除标志位,第四位表示是否等待的标志位都成功了才返回,选择pdTURE时为与条件,选择pdFALSE时为或条件

event_group_data xEventGroupWaitBits(test_event_handle,BIT0|BIT11,pdTRUE,pdFALSE,pdMS_TO_TICKS(5000));
//设置标志位
xEventGroupSetBits(
EventGroupHandle_t xEventGroup,//事件组句柄
const EventBits_t uxBitsToSet ); //设置哪个位
//清除标志位
xEventGroupClearBits(
EventGroupHandle_t xEventGroup,//事件组句柄
const EventBits_t uxBitsToClear ); //设置哪个位