事件標志組用於線程間同步,每一個事件標志組都有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 }
