0% found this document useful (0 votes)
31 views2 pages

Leafsm

The document describes a leaf state machine that detects when a leaf card is inserted. It has two states - LeafInserted and LeafNotInserted. The state machine initializes the leaf pin as a digital input, initializes the last pin state, and initializes the current state to PseudoState_Leaf. When the leaf is inserted, it posts a LEAF_ACTIVATED event. When the leaf is removed, it posts a LEAF_RESET event and switches the state back to LeafNotInserted.

Uploaded by

api-438010548
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Leafsm

The document describes a leaf state machine that detects when a leaf card is inserted. It has two states - LeafInserted and LeafNotInserted. The state machine initializes the leaf pin as a digital input, initializes the last pin state, and initializes the current state to PseudoState_Leaf. When the leaf is inserted, it posts a LEAF_ACTIVATED event. When the leaf is removed, it posts a LEAF_RESET event and switches the state back to LeafNotInserted.

Uploaded by

api-438010548
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

/*

LEAF_STATE_MACHINE

This state machine detecs the insertion of the leaf card, during which the game
should run

States:
LeafInserted
LeafNotInserted

*/

Include Dependent Files


Function define module functions
Define port and pin for the LEAF

Specify Module Variables


MyPriority
LastPinState
CurrentState

InitLeafSM

Parameters
uint8_t : the priorty of this service

Returns
bool, false if error in initialization, true otherwise

Description
Saves away the priority, and does any
other required initialization for this service

Function

Initialize the MyPriority module variable with the passed priority


Initialize the leaf pin as a digital input
Initialize the last pin state for the leaf pin
Make current state - PseudoState_Leaf

Likewise, initialise the Leaf LED


Initialize the Leaf LED to start as Off

Post ES_INIT to this state machine. Return true if successful, false in case of
any error.

PostLeafSM

Parameters
ES_Event_t ThisEvent ,the event to post to the queue

Returns
bool false if the Enqueue operation failed, true otherwise

Description
Posts an event to this state machine's queue

Function:

Call ES_PostToService passing the priority through MyPriority and the assigned
event

RunLeafSM
Parameters
ES_Event_t : the event from its service queue to process in this State
Machine
Types of ES_Event_t: LEAF_ACTIVATED, LEAF_NOT_ACTIVATED

Returns
ES_Event_t, ES_NO_EVENT if no error ES_ERROR otherwise

Function

Declare a ReturnEvent and initialise it as ES_NO_EVENT. This would be returned


in case of no error.

Switch CurrentState
If PseudoState_Leaf:
If event is ES_INIT:
Switch on the Leaf LED
Put current state to LeafNotInserted

If LeafNotInserted:
If event is LEAF_VALID:
Post LEAF_ACTIVATED event to the ControlSM
Put current state to LeafInserted
Switch off leaf led

If LeafInserted:
If event LEAF_REMOVED:
Post LEAF_RESET
Put current state to LeafNotInserted
Switch on the Leaf LED

return ReturnEvent

You might also like