// 事件結構體 typedef struct os_event { INT8U OSEventType; /* Type of event control block (see OS_EVENT_TYPE_xxxx) */ void *OSEventPtr; /* Pointer to message or queue structure */ INT16U OSEventCnt; /* Semaphore Count (not used if other EVENT type) */ #if OS_LOWEST_PRIO <= 63 INT8U OSEventGrp; /* Group corresponding to tasks waiting for event to occur */ INT8U OSEventTbl[OS_EVENT_TBL_SIZE]; /* List of tasks waiting for event to occur */ #else INT16U OSEventGrp; /* Group corresponding to tasks waiting for event to occur */ INT16U OSEventTbl[OS_EVENT_TBL_SIZE]; /* List of tasks waiting for event to occur */ #endif #if OS_EVENT_NAME_SIZE > 1 INT8U OSEventName[OS_EVENT_NAME_SIZE]; #endif } OS_EVENT;
//事件鏈表 OS_EXT OS_EVENT *OSEventFreeList; OS_EXT OS_EVENT OSEventTbl[OS_MAX_EVENTS];
static void OS_InitEventList (void) { #if (OS_EVENT_EN) && (OS_MAX_EVENTS > 0) #if (OS_MAX_EVENTS > 1) INT16U i; OS_EVENT *pevent1; OS_EVENT *pevent2; OS_MemClr((INT8U *)&OSEventTbl[0], sizeof(OSEventTbl)); /* Clear the event table */ pevent1 = &OSEventTbl[0]; pevent2 = &OSEventTbl[1]; for (i = 0; i < (OS_MAX_EVENTS - 1); i++) { /* Init. list of free EVENT control blocks */ pevent1->OSEventType = OS_EVENT_TYPE_UNUSED; pevent1->OSEventPtr = pevent2; #if OS_EVENT_NAME_SIZE > 1 pevent1->OSEventName[0] = '?'; /* Unknown name */ pevent1->OSEventName[1] = OS_ASCII_NUL; #endif pevent1++; pevent2++; } pevent1->OSEventType = OS_EVENT_TYPE_UNUSED; pevent1->OSEventPtr = (OS_EVENT *)0; #if OS_EVENT_NAME_SIZE > 1 pevent1->OSEventName[0] = '?'; pevent1->OSEventName[1] = OS_ASCII_NUL; #endif OSEventFreeList = &OSEventTbl[0]; #else OSEventFreeList = &OSEventTbl[0]; /* Only have ONE event control block */ OSEventFreeList->OSEventType = OS_EVENT_TYPE_UNUSED; OSEventFreeList->OSEventPtr = (OS_EVENT *)0; #if OS_EVENT_NAME_SIZE > 1 OSEventFreeList->OSEventName[0] = '?'; /* Unknown name */ OSEventFreeList->OSEventName[1] = OS_ASCII_NUL; #endif #endif #endif }
鏈表添加過程圖解spa
pevent1++; 指向pevent2;指針
pevent2++; 指向下一個事件code
最後 OSEventFreeList = &OSEventTbl[0]; 將任務鏈表賦給OSEventFreeList 指針。隊列