事件控制块(ECB)
事件控制块的数据结构
1 typedef struct os_event { 2 INT8U OSEventType; /* Type of event control block (see OS_EVENT_TYPE_xxxx) */ 3 void *OSEventPtr; /* Pointer to message or queue structure */ 4 INT16U OSEventCnt; /* Semaphore Count (not used if other EVENT type) */ 5 OS_PRIO OSEventGrp; /* Group corresponding to tasks waiting for event to occur */ 6 OS_PRIO OSEventTbl[OS_EVENT_TBL_SIZE]; /* List of tasks waiting for event to occur */ 7 8 #if OS_EVENT_NAME_EN > 0u 9 INT8U *OSEventName; 10 #endif 11 } OS_EVENT;
1、事件控制块(ECB)的初始化
1 static void OS_InitEventList (void) 2 { 3 #if (OS_EVENT_EN) && (OS_MAX_EVENTS > 0u) 4 #if (OS_MAX_EVENTS > 1u) 5 INT16U ix; 6 INT16U ix_next; 7 OS_EVENT *pevent1; 8 OS_EVENT *pevent2; 9 10 11 OS_MemClr((INT8U *)&OSEventTbl[0], sizeof(OSEventTbl)); /* Clear the event table */ 12 for (ix = 0u; ix < (OS_MAX_EVENTS - 1u); ix++) { /* Init. list of free EVENT control blocks */ 13 ix_next = ix + 1u; 14 pevent1 = &OSEventTbl[ix]; 15 pevent2 = &OSEventTbl[ix_next]; 16 pevent1->OSEventType = OS_EVENT_TYPE_UNUSED; 17 pevent1->OSEventPtr = pevent2; 18 #if OS_EVENT_NAME_EN > 0u 19 pevent1->OSEventName = (INT8U *)(void *)"?"; /* Unknown name */ 20 #endif 21 } 22 pevent1 = &OSEventTbl[ix]; 23 pevent1->OSEventType = OS_EVENT_TYPE_UNUSED; 24 pevent1->OSEventPtr = (OS_EVENT *)0; 25 #if OS_EVENT_NAME_EN > 0u 26 pevent1->OSEventName = (INT8U *)(void *)"?"; /* Unknown name */ 27 #endif 28 OSEventFreeList = &OSEventTbl[0]; 29 #else 30 OSEventFreeList = &OSEventTbl[0]; /* Only have ONE event control block */ 31 OSEventFreeList->OSEventType = OS_EVENT_TYPE_UNUSED; 32 OSEventFreeList->OSEventPtr = (OS_EVENT *)0; 33 #if OS_EVENT_NAME_EN > 0u 34 OSEventFreeList->OSEventName = (INT8U *)"?"; /* Unknown name */ 35 #endif 36 #endif 37 #endif 38 }
2、