xEventGroupCreateStatic
[事件组API ]
event_groups.h
EventGroupHandle_t xEventGroupCreateStatic(
StaticEventGroup_t *pxEventGroupBuffer );
创建一个新的 RTOS 事件组,并返回
可以引用新创建的事件组的句柄。
configSUPPORT_STATIC_ALLOCATION
必须在 FreeRTOSConfig.h 中设置为 1,并且
RTOS 源文件 FreeRTOS/source/event_groups.c 必须
包含在构建中,xEventGroupCreateStatic() 函数才可用。
每个事件组都需要[非常]少量 RAM 来保存
事件组的状态。 如果使用 xEventGroupCreate() 创建事件组,
则会从 FreeRTOS 堆中自动分配所需的 RAM。
如果使用 xEventGroupCreateStatic() 创建事件组
则 RAM 由应用程序编写者提供,这需要用到一个附加参数,
但允许在编译时静态分配 RAM
。 请参阅静态分配与
动态分配页面了解更多信息。
事件组存储在 EventBits_t 类型的变量中。事件组中执行的位数(或标志)取决于
是使用 configUSE_16_BIT_TICKS 还是 configTICK_TYPE_WIDTH_IN_BITS 来控制 TickType_t 的类型:
如果 configUSE_16_BIT_TICKS 设置为 1,则事件组内执行的位数(或标志)为 8;
如果 configUSE_16_BIT_TICKS 设置为 0,则事件组内执行的位数(或标志)为 24。
如果 configTICK_TYPE_WIDTH_IN_BITS 设置为 TICK_TYPE_WIDTH_16_BITS,则事件组内执行的位数(或标志)为 8;
如果 configTICK_TYPE_WIDTH_IN_BITS 设置为 TICK_TYPE_WIDTH_32_BITS,则事件组内执行的位数为 24;
如果 configTICK_TYPE_WIDTH_IN_BITS 设置为 TICK_TYPE_WIDTH_64_BITS,则事件组内执行的位数为 56。
对 configUSE_16_BIT_TICKS 或 configTICK_TYPE_WIDTH_IN_BITS 的依赖源于 RTOS 任务内部实现中用于线程本地存储的数据类型。
-
参数:
-
pxEventGroupBuffer
|
必须指向 StaticEventGroup_t 类型的变量,
该变量用于存储事件组数据结构体。
|
-
返回:
-
如果成功创建了事件组,
则返回事件组的句柄。 如果 pxEventGroupBuffer 为 NULL,则返回 NULL。
用法示例:
/* Declare a variable to hold the handle of the created event group. */
EventGroupHandle_t xEventGroupHandle;
/* Declare a variable to hold the data associated with the created
event group. */
StaticEventGroup_t xCreatedEventGroup;
/* Attempt to create the event group. */
xEventGroupHandle = xEventGroupCreateStatic( &xCreatedEventGroup );
/* pxEventGroupBuffer was not null so expect the event group to have
been created? */
configASSERT( xEventGroupHandle );
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.