Download Understanding High-Performance Embedded Systems with FSM and Concurrent Processes and more Slides Computer Science in PDF only on Docsity!
5-High-Performance Embedded
Systems using Concurrent Process
Outline
• Models vs. Languages
• State Machine Model
- FSM/FSMD
- HCFSM and Statecharts Language
- Program-State Machine (PSM) Model
• Concurrent Process Model
- Communication
- Synchronization
- Implementation
• Dataflow Model
• Real-Time Operating Systems
An example of trying to be precise in
English
- California Vehicle Code
- Right-of-way of crosswalks
- (a) The driver of a vehicle shall yield the right-of-way to a pedestrian crossing the
roadway within any marked crosswalk or within any unmarked crosswalk at an intersection,
except as otherwise provided in this chapter.
- (b) The provisions of this section shall not relieve a pedestrian from the duty of using due care
for his or her safety. No pedestrian shall suddenly leave a curb or other place of safety and walk
or run into the path of a vehicle which is so close as to constitute an immediate hazard. No
pedestrian shall unnecessarily stop or delay traffic while in a marked or unmarked crosswalk.
- (c) The provisions of subdivision (b) shall not relieve a driver of a vehicle from the duty of
exercising due care for the safety of any pedestrian within any marked crosswalk or within any unmarked crosswalk at an intersection.
- All that just for crossing the street (and there’s much more)!
Models and languages
• How can we (precisely) capture behavior?
- We may think of languages (C, C++), but computation model is the key
• Common computation models:
- Sequential program model
- Statements, rules for composing statements, semantics for executing them
- Communicating process model
- Multiple sequential programs running concurrently
- State machine model
- For control dominated systems, monitors control inputs, sets control outputs
- Dataflow model
- For data dominated systems, transforms input data streams into output streams
- Object-oriented model
- For breaking complex software into simpler, well-defined pieces
Text versus Graphics
• Models versus languages not to be confused
with text versus graphics
– Text and graphics are just two types of languages
• Text: letters, numbers
• Graphics: circles, arrows (plus some letters, numbers)
X = 1;
Y = X + 1;
X = 1
Y = X + 1
Introductory example: An elevator
controller
- Simple elevator controller
- Request Resolver resolves
various floor requests into
single requested floor
- Unit Control moves elevator to
this requested floor
“Move the elevator either up or down
to reach the requested floor. Once at
the requested floor, open the door for
at least 10 seconds, and keep it open
until the requested floor changes.
Ensure the door is never open while
moving. Don’t change directions
unless there are no higher requests
when moving up or no lower requests
when moving down…”
Partial English description
buttons inside elevator
Unit Control
b
down
open
floor
Request Resolver
up/down buttons on each floor
b bN
up up dn
dnN
req
up
System interface
up dn
Finite-state machine (FSM) model
• Trying to capture this behavior as sequential program is a bit awkward
• Instead, we might consider an FSM model, describing the system as:
- Possible states
- E.g., Idle , GoingUp , GoingDn , DoorOpen
- Possible transitions from one state to another based on input
- Actions that occur in each state
- E.g., In the GoingUp state, u,d,o,t = 1,0,0,0 (up = 1, down, open, and timer_start = 0)
• Try it...
Finite-state machine (FSM) model
Idle
GoingUp
req > floor
req < floor
!(req > floor)
!(timer < 10)
req < floor
DoorOpen
GoingDn
req > floor
u,d,o, t = 1,0,0,
u,d,o,t = 0,0,1,
u,d,o,t = 0,1,0,
u,d,o,t = 0,0,1,
u is up, d is down, o is open
req == floor
!(req<floor)
timer < 10
t is timer_start
UnitControl process using a state machine
Finite-state machine with datapath
model (FSMD)
- FSMD extends FSM: complex data types and variables for storing data
- FSMs use only Boolean data types and operations, no variables
- FSMD: 7-tuple < S , I , O , V , F , H , s 0 >
- S is a set of states { s 0 , s 1 , …, s (^) l }
- I is a set of inputs { i 0 , i 1 , …, i (^) m }
- O is a set of outputs { o 0 , o 1 , …, o (^) n }
- V is a set of variables { v 0 , v 1 , …, vn }
- F is a next-state function ( S x I x V → S )
- H is an action function ( S → O + V )
- s 0 is an initial state
- I , O , V may represent complex data types
- (i.e., integers, floating point, etc.)
- F , H may include arithmetic operations
- H is an action function, not just an output function
- Describes variable updates as well as outputs
- Complete system state now consists of current state, s i , and values of all variables
Idle
GoingUp
req > floor
req < floor
!(req > floor)
!(timer < 10)
req < floor
DoorOpen
GoingDn
req > floor
u,d,o, t = 1,0,0,
u,d,o,t = 0,0,1,
u,d,o,t = 0,1,0,
u,d,o,t = 0,0,1,
u is up, d is down, o is open
req == floor
!(req<floor)
timer < 10
t is timer_start
We described UnitControl as an FSMD
Describing a system as a state
machine
- List all possible states
2. Declare all variables (none in this example)
3. For each state, list possible transitions, with conditions, to other states
4. For each state and/or transition,
list associated actions
5. For each state, ensure exclusive
and complete exiting transition
conditions
• No two exiting conditions can
be true at same time
- Otherwise nondeterministic
state machine
• One condition must be true at
any given time
- Reducing explicit transitions
should be avoided when first
learning
req > floor
u,d,o, t = 1,0,0,0 !(req > floor)
u,d,o,t = 0,0,1,
u,d,o,t = 0,1,0,
u,d,o,t = 0,0,1,
u is up, d is down, o is open
req < floor
req > floor
req == floor
req < floor
!(req<floor)
!(timer < 10)
timer < 10
t is timer_start
Idle
GoingUp
DoorOpen
GoingDn
Try Capturing Other Behaviors with
an FSM
• E.g., Answering machine blinking light when
there are messages
• E.g., A simple telephone answering machine
that answers after 4 rings when activated
• E.g., A simple crosswalk traffic control light
• Others
Capturing state machines in
sequential programming language
- Despite benefits of state machine model, most popular development tools use sequential programming
language
- C, C++, Java, Ada, VHDL, Verilog, etc.
- Development tools are complex and expensive, therefore not easy to adapt or replace
- Two approaches to capturing state machine model with sequential programming language
- Front-end tool approach
- Additional tool installed to support state machine language
- Graphical and/or textual state machine languages
- May support graphical simulation
- Automatically generate code in sequential programming language that is input to main development tool
- Drawback: must support additional tool (licensing costs, upgrades, training, etc.)
- Language subset approach
- E.g. using C...
General template
#define S0 0
#define S1 1
#define SN N
void StateMachine() {
int state = S0; // or whatever is the initial state.
while (1) {
switch (state) {
S0:
// Insert S0’s actions here & Insert transitions Ti leaving S0:
if( T 0 ’s condition is true ) {state = T 0 ’s next state; /actions/ }
if( T 1 ’s condition is true ) {state = T 1 ’s next state; /actions/ }
if( Tm ’s condition is true ) {state = Tm ’s next state; /actions/ }
break;
S1:
// Insert S1’s actions here
// Insert transitions Ti leaving S
break;
SN:
// Insert SN’s actions here
// Insert transitions Ti leaving SN
break;