Pseudocode Spi HSM
Pseudocode Spi HSM
RunMasterSM
switch Current State
case WaitinginSPI
CurrentEvent=DuringWaitinginSPI
If Current Event is ES_TIMEOUT, make Next State to Registering and trigger a one second timer, perform Exit
function for current state and entry function for next state
case Registering
CurrentEvent=DuringRegistering
If Current Event is ES_EOT, make Next State to Acknowledging, perform Exit function for current state and entry
function for next state
If Current Event is ES_ERROR, make Next State to Registering, perform Exit function for current state and entry
function for next state
case Acknowledging
CurrentEvent=DuringAcknowledging
If Current Event is ES_DECODED, make Next State to GetTeamInfo and trigger a one second timer, perform Exit
function for current state and entry function for next state
If Current Event is ES_ERROR, make Next State to Registering, perform Exit function for current state and entry
function for next state
case GetTeamInfo
CurrentEvent=DuringGTI
If Current Event is ES_EOT, make Next State to TeamInfo, perform Exit function for current state and entry
function for next state
case TeamInfo
CurrentEvent=DuringTI
If Current Event is ES_DECODED, make Next State to GetGameStatus and trigger a one second timer, perform Exit
function for current state and entry function for next state
If Current Event is ES_ERROR, make Next State to Registering, perform Exit function for current state and entry
function for next state
case GetGameStatus
CurrentEvent=DuringGGS
If Current Event is ES_EOT, make Next State to GameStatus, perform Exit function for current state and entry
function for next state
case GameStatus
CurrentEvent=DuringGS
If Current Event is ES_DECODED, make Next State to GetGameStatus and trigger a one second timer, perform Exit
function for current state and entry function for next state
If Current Event is ES_ERROR, make Next State to Registering, perform Exit function for current state and entry
function for next state
StartMasterSM
CurrentState to be made as Waiting in SPI
RunMasterSM to be run with CurrentEvent
DuringWaitinginSPI
-------
DuringRegistering
If Timeout is received, send registration bits at specified time intervals based on Team switch status
DuringAcknowledging
If ES_RECEIVED is received, check for correctness of received bytes
If received bytes is not in the right format, post ES_ERROR to service
If registration is successful, post ES_DECODED to service
DuringGetTeamINFO
If Timeout is received, send registration bits at specified time intervals based on Team switch status
DuringTeamINFO
If ES_RECEIVED is received, check for correctness of received bytes
If received bytes is not in the right format, post ES_ERROR to service
else, decode relevant messages and post ES_DECODED to service
DuringGetGameStatus
If Timeout is received, send registration bits at specified time intervals based on Team switch status
DuringGameStatus
If ES_RECEIVED is received, check for correctness of received bytes
If received bytes is not in the right format, post ES_ERROR to service
else, decode relevant messages and post ES_DECODED to service.
If Game has started, post ES_START to all services.
If Game ends, post ES_GAMEOVER to all services.
CommandGeneratorResponse
Clear the source of Interrupt
Read required number of data from the data register
Post ES_RECEIVED to Service
QueryWest
Return 1 if West Recycling accepts your ball, else return 0
QueryEast
Return 1 if East Recycling accepts your ball, else return 0
QueryColour
Return the colour of your ball
QueryFrequency
Return the frequency to activate recycling center
QueryTeam
Return Team