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_PostToService Parameters uint8_t : Which service to post to (index into ServDescList) ES_Event : The Event to be posted Returns boolean : False if the post function failed during execution Description posts to one of the services' queues Notes used by the timer library to associate a timer with a state machine Author J. Edward Carryer, 01/16/12, ****************************************************************************/ bool ES_PostToService( uint8_t WhichService, ES_Event TheEvent){ if ((WhichService < ARRAY_SIZE(EventQueues)) && (ES_EnQueueFIFO( EventQueues[WhichService].pMem, TheEvent) == true )){ Ready |= BitNum2SetMask[WhichService]; // show queue as non-empty return true; } else return false; }
/**************************************************************************** Function ES_PostAll Parameters ES_Event : The Event to be posted Returns boolean : False if any of the post functions failed during execution Description posts to all of the services' queues Notes Author J. Edward Carryer, 01/15/12, ****************************************************************************/ bool ES_PostAll( ES_Event ThisEvent){ uint8_t i; // loop through the list executing the post functions for ( i=0; i< ARRAY_SIZE(EventQueues); i++) { if ( ES_EnQueueFIFO( EventQueues[i].pMem, ThisEvent ) != true ){ break; // this is a failed post }else{ Ready |= BitNum2SetMask[i]; // show queue as non-empty } } if ( i == ARRAY_SIZE(EventQueues) ){ // if no failures return (true); }else{ return(false); } }