RTX笔记5 - 事件标志组 event flags
作者:互联网
事件标志组用于线程间同步,每一个事件标志组都有31个时间标志位(除最高位)。
osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr):
创建一个事件标志组,返回时间标志ID 或者 NULL。不可在中断中调用。
osEventFlagsAttr_t Data Fields | ||
---|---|---|
const char * | name | name of the event flags
Pointer to a constant string with a human readable name (displayed during debugging) of the event flag object. Default: NULL no name specified. |
uint32_t | attr_bits | attribute bits
Reserved for future use (must be set to '0' for future compatibility). |
void * | cb_mem | memory for control block
Pointer to a memory for the event flag control block object. Refer to Static Object Memory for more information. Default: NULL to use Automatic Dynamic Allocation for the event flag control block. |
uint32_t | cb_size | size of provided memory for control block
The size (in bytes) of memory block passed with cb_mem. For RTX, the minimum value is defined with osRtxEventFlagsCbSize (higher values are permitted). Default: 0 as the default is no memory provided with cb_mem. |
uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags)
设置事件标志组相应flags位。返回设置后标志或者错误码。最高位不可设置。可在中断中调用。
uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout)
等待时间标志组相应flags位被设置,默认情况下,该函数返回时,会将相应的等待标志位清零,其他位保持不变。可在中断中调用。
Option | |
---|---|
osFlagsWaitAny | Wait for any flag (default). |
osFlagsWaitAll | Wait for all flags. |
osFlagsNoClear | Do not clear flags which have been specified to wait for. |
- Note:
- 函数 osEventFlagsSet, osEventFlagsClear, osEventFlagsGet, and osEventFlagsWait 可以在中断中调用。
-
1 osEventFlagsId_t evt; 2 3 void 4 testEventFlags(void) 5 { 6 evt = osEventFlagsNew(NULL); 7 osThreadNew(_ledThread, NULL, NULL); // Create application led thread 8 osThreadNew(_thread2, NULL, NULL); // Create application segment led thread 9 } 10 11 static void 12 _ledThread(void *argument) 13 { 14 (void)argument; 15 uint32_t flags; 16 17 for(;;) { 18 flags = osEventFlagsWait(evt, 0x00000001, osFlagsWaitAny, osWaitForever); 19 menuShow(&seg_led, flags, 0); 20 21 flags = osEventFlagsWait(evt, 0x00000002, osFlagsWaitAny, osWaitForever); 22 menuShow(&seg_led, flags, 0); 23 24 flags = osEventFlagsWait(evt, 0x0000000C, osFlagsWaitAll | osFlagsNoClear, osWaitForever); 25 flags = osEventFlagsGet(evt); 26 menuShow(&seg_led, flags, 0); 27 osEventFlagsClear (evt, 0x0000000C); 28 29 flags = osEventFlagsWait(evt, 0x00000007, osFlagsWaitAll, osWaitForever); 30 menuShow(&seg_led, flags, 0); 31 } 32 } 33 34 static void 35 _thread2(void *argument) 36 { 37 (void)argument; 38 for(;;) { 39 osEventFlagsSet(evt, 0x00000001); 40 osDelay(1000); 41 42 osEventFlagsSet(evt, 0x00000002); 43 osDelay(1000); 44 45 osEventFlagsSet(evt, 0x0000000C); 46 osDelay(1000); 47 48 osEventFlagsSet(evt, 0x00000007); 49 osDelay(1000); 50 } 51 }
标签:event,void,RTX,osEventFlagsSet,flags,NULL,evt,uint32 来源: https://www.cnblogs.com/ivan0512/p/15364770.html