/****************************************************************************
Module
GameSM.c
Description
This module implements the game state machine for Sir Robot
****************************************************************************/
/*---------------------------- Module Functions ---------------------------*/
DuringRound1( ES_Event Event)
DuringRecess1( ES_Event Event)
DuringRound2( ES_Event Event)
DuringRecess2( ES_Event Event)
DuringRound3( ES_Event Event)
DuringRecess3(ES_Event Event)
DuringSuddenDeath( ES_Event Event)
/*---------------------------- Module Variables ---------------------------*/
CurrentState
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
RunGameSM
Parameters
ES_Event: the event to process
Returns
ES_Event: an event to return
****************************************************************************/
switch on CurrentState
case Idle
if event is match underway
Set next state to round 1
mark that we are taking a transition
case Round1
call the during function for this state
If event is RECESS
Set next state to Recess1
mark that we are taking a transition
Set entry event to enter with history
case Recess1
call the during function for this state
If event is match underway
Set NextState to Round2
mark that we are taking a transition
If event is a SWING_TIMER timeout
Retract the lance
case Round2
call the during function for this state
If event is RECESS
Set the NextState to Recess2
mark that we are taking a transition
case Recess2
call the during function for this state
If event is match underway
Set next state to Round3
mark that we are taking a transition
if event is SWING_TIMER timeout
Retract the lance
case Round3
Call the during function for this state
if event is RECESS
Set NextState to Recess3
mark that we are taking a transition
case Recess3
call the during function for this state
if event is sudden death
Set NextState to SuddenDeath
mark that we are taking a transition
if event is SWING_TIMER timeout
Retract the lance
case SuddenDeath
call the during function for this state
end switch on current state
If we are making a state transition
Execute exit function for current state
Execute entry function for new state
/****************************************************************************
Function
StartGameSM
Parameters
None
Returns
None
Description
Does any required initialization for this state machine
****************************************************************************/
if entry is not with history
Set current state to idle
call the entry function for entry state
/***************************************************************************
During functions
***************************************************************************/
/***************************************************************************
DuringRound1
***************************************************************************/
if entry event
pass entry event to lower level SM's
turn on status LED
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM's
/***************************************************************************
DuringRecess1
***************************************************************************/
if entry event
pass entry event to lower level SM's
turn on launcher motor
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM's
/***************************************************************************
DuringRound2
***************************************************************************/
if entry event
pass entry event to lower level SM's
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM's
/***************************************************************************
DuringRecess2
***************************************************************************/
if entry event
pass entry event to lower level SM's
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM's
/***************************************************************************
DuringRound3
***************************************************************************/
if entry event
pass entry event to lower level SM's
turn on status LED
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM's
/***************************************************************************
DuringRecess3
***************************************************************************/
if entry event
pass entry event to lower level SM's
turn on status LED
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM
/***************************************************************************
DuringSuddenDeath
***************************************************************************/
if entry event
pass entry event to lower level SM's
turn on status LED
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM's
Module
GameSM.c
Description
This module implements the game state machine for Sir Robot
****************************************************************************/
/*---------------------------- Module Functions ---------------------------*/
DuringRound1( ES_Event Event)
DuringRecess1( ES_Event Event)
DuringRound2( ES_Event Event)
DuringRecess2( ES_Event Event)
DuringRound3( ES_Event Event)
DuringRecess3(ES_Event Event)
DuringSuddenDeath( ES_Event Event)
/*---------------------------- Module Variables ---------------------------*/
CurrentState
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
RunGameSM
Parameters
ES_Event: the event to process
Returns
ES_Event: an event to return
****************************************************************************/
switch on CurrentState
case Idle
if event is match underway
Set next state to round 1
mark that we are taking a transition
case Round1
call the during function for this state
If event is RECESS
Set next state to Recess1
mark that we are taking a transition
Set entry event to enter with history
case Recess1
call the during function for this state
If event is match underway
Set NextState to Round2
mark that we are taking a transition
If event is a SWING_TIMER timeout
Retract the lance
case Round2
call the during function for this state
If event is RECESS
Set the NextState to Recess2
mark that we are taking a transition
case Recess2
call the during function for this state
If event is match underway
Set next state to Round3
mark that we are taking a transition
if event is SWING_TIMER timeout
Retract the lance
case Round3
Call the during function for this state
if event is RECESS
Set NextState to Recess3
mark that we are taking a transition
case Recess3
call the during function for this state
if event is sudden death
Set NextState to SuddenDeath
mark that we are taking a transition
if event is SWING_TIMER timeout
Retract the lance
case SuddenDeath
call the during function for this state
end switch on current state
If we are making a state transition
Execute exit function for current state
Execute entry function for new state
/****************************************************************************
Function
StartGameSM
Parameters
None
Returns
None
Description
Does any required initialization for this state machine
****************************************************************************/
if entry is not with history
Set current state to idle
call the entry function for entry state
/***************************************************************************
During functions
***************************************************************************/
/***************************************************************************
DuringRound1
***************************************************************************/
if entry event
pass entry event to lower level SM's
turn on status LED
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM's
/***************************************************************************
DuringRecess1
***************************************************************************/
if entry event
pass entry event to lower level SM's
turn on launcher motor
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM's
/***************************************************************************
DuringRound2
***************************************************************************/
if entry event
pass entry event to lower level SM's
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM's
/***************************************************************************
DuringRecess2
***************************************************************************/
if entry event
pass entry event to lower level SM's
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM's
/***************************************************************************
DuringRound3
***************************************************************************/
if entry event
pass entry event to lower level SM's
turn on status LED
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM's
/***************************************************************************
DuringRecess3
***************************************************************************/
if entry event
pass entry event to lower level SM's
turn on status LED
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM
/***************************************************************************
DuringSuddenDeath
***************************************************************************/
if entry event
pass entry event to lower level SM's
turn on status LED
else if exit event
pass exit event to lower level SM's
else
pass event to lower level SM's