May 13, 2009
The embedded Finite State MachineBo Berry
This fsm is written in C and portable to different environments
A finite state machine (fsm) is a method to model a system's behavior. The model is composed of a set of states, of which one is designated as the start or initial state. The initial state is the state that the fsm begins when it is instantiated. The transition from the initial state and between the set of states is determined by a set of events. From one state to the next, an event may be processed to cause a transition or ignored.
The embedded Finite State Machine (eFSM) I present here is written in C and portable to different environments. You can download the eFSM from SourceForge here.
The set of states is defined in a state description table. The state description table from the demo is shown below:
Once the states are determined, the set of normalized events is defined is the event description table as shown below:
Now to put the states and events together. The state table provides an entry for each state. The entries map a state to the associated state-event table. In the table below, the established state is mapped to the established state-event table:
Here the event handler and the transition caused by an event is defined:
With the state and event tables, the fsm_engine() can be called to process events and drive state transitions.
Included are calls to display the state machine history of events and resulting state transitions (useful for debugging) and a call to display the state-event tables. The organization of the demo software suggests an organization for your real application.
You can find a comprehensive and detailed description of finite state machines here.
|
|
||||||||||||||||||||||||||||
|
|
|
|