Finite-state Machines

10
Finite-state Machines Chapter 14

description

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. - PowerPoint PPT Presentation

Transcript of Finite-state Machines

Page 1: Finite-state Machines

Finite-state Machines

Chapter 14

Page 2: Finite-state Machines

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.

Page 3: Finite-state Machines

Formal Finite-state Automata Simple graphical representation:

State A State B

Simulus/Response

Page 4: Finite-state Machines

Example FSM specification The controller will respond to a over-

temperature condition with a system shutdown reaction.

Normal Operation

Emergency Shutdown

System over temperature / Emergency Shutdown

Page 5: Finite-state Machines

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.

Page 6: Finite-state Machines

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).

Page 7: Finite-state Machines

Finite State Machine with Pseudo code

A B C

z/S

s/Q y/R

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 abortB: 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

Page 8: Finite-state Machines

Page 55, Figure 2.2 State Diagrams for Alarm Clock Example

Page 9: Finite-state Machines

States for the Tool Booth Controller

Page 10: Finite-state Machines

State Diagram for Toll Booth Controller