100 likes | 346 Views
Finite-state Machines. Chapter 14. Designing with FSMs. Finite state machines are ideal for reactive systems. A typical way of thinking about an FSM is “state-stimulus-response”: In a particular state , a stimulus will provoke a particular response. Formal Finite-state Automata.
E N D
Finite-state Machines Chapter 14
Designing with FSMs • Finite state machines are ideal for reactive systems. • A typical way of thinking about an FSM is “state-stimulus-response”: In a particular state, a stimulus will provoke a particular response.
Formal Finite-state Automata • Simple graphical representation: Simulus/Response State A State B
Example FSM specification • The controller will respond to a over-temperature condition with a system shutdown reaction. System over temperature / Emergency Shutdown Normal Operation Emergency Shutdown
Model Checking • FSM has a basis in mathematics: Finite state automata. This allows checking for forbidden conditions. • FSMs must be deterministic: for each and every state, there must be one and only one response for that simulus in that state. • As FSMs become more complex, manual checking for determinism becomes more and more difficult, so automation of checking is more desirable.
Coding an FSM Design • FSM code lends itself to automatic generation by tools. • Hand-coded FSMs are often table driven, with two sets of tables, one representing the state-response relationship (indexed by stimulus), the other representing the current state-next state relationship (also indexed by stimulus).
z/S A B C s/Q y/R Finite State Machine with Pseudo code A: Get next event E CASE E OF x: Do action Q GOTO B z: Do action S GOTO C ESAC Print ‘Illegal first event’ and abort B: Get next event if not y THEN Print ‘Event must be y’ and abort FI Do action R GOTO C C: IF any next event THEN Print ‘No more events allow3ed’ and abort FI