Professional Documents
Culture Documents
Spi Follower Pseudocode
Spi Follower Pseudocode
Enum spi_comms
InitSPIFollowerService
Takes a priority number, returns True.
Sets MyPriority
Enable Interrupts
Turn SPI on
End of InitSPIFollowerService
PostSPIFollowerService
Takes an ES_Event_t, returns boolean outcome of ES_PostToService
End of PostSPIFollowerService
RunSPIFollowerService
The EventType field of ThisEvent will be one of: ES_INIT,
TEAM_A_SELECTED, TEAM_B_SELECTED, AR1_ALIGN, NOT_ALIGNED
CurrentState is:
InitPState
ThisEvent is ES_INIT
Set CurrentState to Idle
Idle
ThisEvent is TEAM_A_SELECTED
Set GoodToShoot to true
ThisEvent is TEAM_B_SELECTED
Set GoodToShoot to true
ThisEvent is AR1_ALIGN
Set GoodToShoot to true
ThisEvent is NOT_ALIGNED
Set GoodToShoot to false
Return ES_NO_EVENT
End of RunSPIFollowerService
if LeaderRequest is ALIGN_QUERY
Set SPI1BUF to GoodToShoot
Else if LeaderRequest is CLOCK_BITS
Do nothing
else if LeaderRequest is LAUNCH_OFF
Set NewEvent to ES_LAUNCH_OFF
Post to Launcher Service
else if LeaderRequest is ES_LAUNCH_20
Set NewEvent to ES_LAUNCH_20
Post to Launcher Service
else if LeaderRequest is ES_LAUNCH_40
Set NewEvent to ES_LAUNCH_40
Post to Launcher Service
else if LeaderRequest is ES_LAUNCH_60
Set NewEvent to ES_LAUNCH_60
Post to Launcher Service
else if LeaderRequest is ES_LAUNCH_80
Set NewEvent to ES_LAUNCH_80
Post to Launcher Service
else if LeaderRequest is ES_LAUNCH_100
Set NewEvent to ES_LAUNCH_100
Post to Launcher Service
Else
Do nothing
End of SPIReceiveInterrupt