Module CompassService.c Revision 1.0.1 Description This is module to implement communication with the COMPASS Notes Team 3 Private definitions TransmitSPI ReadSPI InitSPIComms QUERYCOLOR QUERYECOP QUERYSTATUS QUERYRECYCLE TEAMBYTE TEAMCOLOR TEAMFREQ STATUS ERECYCLE WRECYCLE TeamAssigned ColorAssigned FreqAssigned EastRecycleColor WestRecycleColor GameState bool InitCompassService(uint8_t Priority) { //Define priority for this service //Post initial transition event ES_Event_t RunCompassService(ES_Event_t ThisEvent) //Reads current State //If CurrentState is InitCState and recieved event is ES_INIT //Set next state to WaitforREG //Initialize CompassDelayTimer for 2 ms //If current state is WaitforREG //If Recieved event is TEAM_SELECT //Call TransmitSPI function with EventParam recieved //Set next state to WaitForACK //If current state is WaitForACK //If recieved event is DATA_RECEIVED //Post REG_COMPLETE to GameControlService //Initialize CompassQueryTimer for 500 ms //Set next state to WaitForQuery //If current state is WaitForQuery //If event recieved is ES_TIMEOUT with EventParam CompassQueryTimer //Call TransmitSPI function with QUERYCOLOR //Set next state to WaitForTEAM //If current state is WaitForTEAM //If recieved event is DATA_RECEIVED //Save TeamAssigned as EventParam masked with TEAMBYTE //Save ColorAssigned as EventParam masked with TEAMCOLOR and shifted 1 bit left //Save FreqAssigned as EventParam masked with TEAMFREQ and shifted 4 bits left //Initialize CompassDelayTimer for 500 ms //Set next state to WaitForDelay //If current state is WaitForDelay //If event recieved is ES_TIMEOUT with EventParam CompassDelayTimer //Call TransmitSPI function with QUERYSTATUS //Set next state to WaitForStat //If current state is WaitForStat //If recieved event is DATA_RECEIVED //Save GameState as EventParam masked with STATUS //Save EastRecycleColor as EventParam masked with ERECYCLE and shifted 2 bits left //Save WestRecycleColor as EventParam masked with WRECYCLE and shifted 5 bits left //if GameState is equal to 1 and GameActive is false //Post GAME_STARTED to GameControlService, GameplayMasterSM //Set GameActive to true //Else if GameState is equal to 2, and GameActive is true //Post GAME_OVER to GameControlService, GameplayMasterSM //Set GameActive to false //Initialize CompassQueryTimer for 500 ms //Set next state to WaitForQuery //return ReturnEvent uint8_t GetTeamAssignment(void) //return TeamAssigned uint8_t GetColorAssignment(void) //return ColorAssigned uint16_t GetFreqAssignment(void) //Call function GetOurRecycleBeaconFreq and save value to FrequencyAssigned //If FrequencyAssigned is equal to WestRecycleColor //Save WestAcceptedFreq to FrequencyAssigned //else if FrequencyAssigned is equal to EastRecycleColor //Save EastAcceptedFreq to FrequencyAssigned //return FrequencyAssigned uint8_t GetEastRecycleColor(void) //return EastRecycleColor uint8_t GetWestRecycleColor(void) //return WestRecycleColor; bool QueryGameStatus(void) //return GameActive static void TransmitSPI(uint8_t SendData) // Writes SendData to SSI Data Register FIFO // Writes VOIDBYTE to SSI Data Register FIFO // Writes VOIDBYTE to SSI Data Register FIFO // Activates Local Interrupt to send data to COMPASS static uint16_t ReadSPI(void) //Reads SSI Data Register FIFO should be 0x00 //Reads SSI Data Register FIFO should be 0xFF //Saves to SPIResponse the value from read from the SSI Data Register FIFO //return SPIResponse void ReceiveSPI(void) //Disables Local interrupts (ISR) //Posts DATA_RECEIVED Event to Cpmpass Service, with event parram the value recieved from function ReadSPI()