CommSM State Machine
CommSM Psuedocode
/******************************************************************************/
COMM MODULE STATE MACHINE PSEUDO-CODE
InitCommSM
Takes a priority number, returns True
Initialize the MyPriority variable with the passed in parameter
Initialize CommTimer
Set CurrentState to be InitCommSM
post Event ES_INIT to InitCommSM (this service)
End
RunCommSM (implements the state machine for COMM)
The EventType field of ThisEvent will be of one: ES_INIT, ES_SENDREQ, ES_TIMEOUT
List of States: InitCommSM, Idle, WaitForStrobeFall, WaitForACK, StrobeRise, StrobeFall, ACKRise
Returns ES_NO_EVENT
Module Variables:
Set NextState to CurrentState
Based on the state of the CurrentState variable, choose one of the following blocks of code:
CurrentState is InitCommPState
IF ThisEvent is ES_INIT
Do initialization
Set NextState to Idle
ENDIF
CurrentState is Idle
IF ThisEvent is ES_SENDREQ
IF Strobe Asserted (Strobe pin is High)
Defer ES_SENDREQ
Set NextState to Idle
ENDIF
IF Strobe Not Asserted
Save NewData
Assert Data
Assert Strobe
Start CommTimer
Set NextState to WaitForACK
ENDIF
IF ThisEvent is StrobeRise
Read Data
Assert ACK
Set NextState to WaitForStrobeFall
ENDIF
CurrentState is WaitForStrobeFall
IF ThisEvent is StrobeFall
Deassert ACK
Decode Data (int data[pin1][pin2][pin3])
Post Data
Recall ES_SENDREQ
Set NextState to Idle
ENDIF
IF ThisEvent is ES_SENDREQ
Defer ES_SENDREQ
set NextState to WaitForStrobeFall
ENDIF
CurrentState is WaitForACK
IF ThisEvent is ACKRise
Deassert data and strobe
Post SendCompleted
Recall ES_SENDREQ
ENDIF
IF ThisEvent is ES_SENDREQ
Defer ES_SENDREQ
Set NextState to WaitForACK
ENDIF
IF ThisEvent is ES_TIMEOUT and Event.Param is CommTimer Number
Re-Post ES_SENDREQ with saved data
Set NextState to Idle
ENDIF
Set CurrentState to NextState
/****************************************************************************