void main(void){ ES_Event MyEvent; bool bReturn; ES_InitQueue( TestQueue, ARRAY_SIZE(TestQueue) ); MyEvent.EventType = 0; MyEvent.EventParam = 1; bReturn = ES_EnQueueFIFO( TestQueue, MyEvent ); bReturn +=1; // keep that sily optimizer away // Try stuffing one on using the LIFO rule MyEvent.EventType = 10; MyEvent.EventParam = 11; bReturn = ES_EnQueueLIFO( TestQueue, MyEvent ); bReturn +=1; // keep that sily optimizer away // at this point, the events in the queue should be 11,0 // so pull off the 11, leaving 1 entry NumLeft = ES_DeQueue( TestQueue, &MyEvent); if ( NumLeft != 1) bReturn = 0; MyEvent.EventType = 2; MyEvent.EventParam = 3; bReturn = ES_EnQueueFIFO( TestQueue, MyEvent ); bReturn +=1; // keep that sily optimizer away MyEvent.EventType = 4; MyEvent.EventParam = 5; bReturn = ES_EnQueueFIFO( TestQueue, MyEvent ); bReturn +=1; // keep that sily optimizer away // queue is now full so this one should fail MyEvent.EventType = 6; MyEvent.EventParam = 7; bReturn = ES_EnQueueFIFO( TestQueue, MyEvent ); bReturn +=1; // keep that sily optimizer away // at this point, the events in the queue should be 0,2,4 // so pull off the 0, leaving 2 entries NumLeft = ES_DeQueue( TestQueue, &MyEvent); if ( NumLeft != 2) bReturn = 0; // Try stuffing one on using the LIFO rule MyEvent.EventType = 8; MyEvent.EventParam = 9; bReturn = ES_EnQueueLIFO( TestQueue, MyEvent ); bReturn +=1; // keep that sily optimizer away // at this point, the events in the queue should be 8,2,4 // so pull off the 8, leaving 2 entries NumLeft = ES_DeQueue( TestQueue, &MyEvent); NumLeft += 3; //to keep the compiler from optimizing away the last save while(1) ; }
/**************************************************************************** Function ES_Run Parameters None Returns ES_Return_t : FailedRun is any of the run functions failed during execution Description This is the main framework function. It searches through the state machines to find one with a non-empty queue and then executes the state machine to process the event in its queue. while all the queues are empty, it searches for system generated or user generated events. Notes this function only returns in case of an error Author J. Edward Carryer, 10/23/11, ****************************************************************************/ ES_Return_t ES_Run( void ){ // make these static to improve speed uint8_t HighestPrior; static ES_Event ThisEvent; while(1){ // stay here unless we detect an error condition // loop through the list executing the run functions for services // with a non-empty queue. Process any pending ints before testing // Ready while( (_HW_Process_Pending_Ints()) && (Ready != 0)){ HighestPrior = ES_GetMSBitSet(Ready); if ( ES_DeQueue( EventQueues[HighestPrior].pMem, &ThisEvent ) == 0 ){ Ready &= BitNum2ClrMask[HighestPrior]; // mark queue as now empty } if( ServDescList[HighestPrior].RunFunc(ThisEvent).EventType != ES_NO_EVENT) { return FailedRun; } } // all the queues are empty, so look for new user detected events ES_CheckUserEvents(); } }
/**************************************************************************** Function ES_Run Parameters None Returns ES_Return_t : FailedRun is any of the run functions failed during execution Description This is the main framework function. It searches through the state machines to find one with a non-empty queue and then executes the state machine to process the event in its queue. while all the queues are empty, it searches for system generated or user generated events. Notes this function only returns in case of an error Author J. Edward Carryer, 10/23/11, ****************************************************************************/ ES_Return_t ES_Run( void ) { // make these static to improve speed uint8_t HighestPrior; static ES_Event ThisEvent; while(1) { // stay here unless we detect an error condition // loop through the list executing the run functions for services // with a non-empty queue while( Ready != 0) { //printf("Rdy=%X ", Ready); HighestPrior = Byte2MSBitNum[Ready-1]; if ( ES_DeQueue( EventQueues[HighestPrior].pMem, &ThisEvent ) == 0 ) { Ready &= BitNum2ClrMask[HighestPrior]; // mark queue as now empty } if( ServDescList[HighestPrior].RunFunc(ThisEvent).EventType != ES_NO_EVENT) { return FailedRun; } } // all the queues are empty, so look for new system or user detected events if (CheckSystemEvents() == False) ES_CheckUserEvents(); } }