Embedded Systems Lecture 4: Statecharts: Björn Franke University of Edinburgh
Embedded Systems Lecture 4: Statecharts: Björn Franke University of Edinburgh
Lecture 4: Statecharts
Björn Franke
University of Edinburgh
Overview
• Statecharts
• Definition
• Depth
• History, Default
• Concurrency
• Broadcast
• Example
Statecharts
Statechart = state-diagrams
+ depth (also known as abstraction)
+ orthogonality (also known as concurrency)
+ broadcast communication
State Diagrams
The Statechart notation is a kind of extended FSM with abstraction,
concurrency,• and
Composed of states, transitions
communication.
• transitions from one state to another happen when the event that
labeled on the arc (if any) occurs and the condition (if any) is true
• an output can be associated with the transition
o In the diagram below, the state changes from A to B when
State Diagrams
• Transitions from one state to another happen when the event that is labeled
on the arc (if any) occurs and the condition (if any) is true
• State changes from A to B when event b occurs and the condition P is true;
the output is c
b(P)/c
A
a
B
Depth (Hierarchie)
• Refinement, clustering
b D a
A A
a b B
B e(P)
e(P) d
d
C
C b
• D is called a superstate.
• D is called a superstate.
clustered like this:
• The semantics (aka meaning) of superstate D
o A xor C
D
• The semantics
a (aka meaning) of superstate D• is:
D a b
B
b C
B
d
Example (Top-Down Refinement)
d
ple (refinement, top-down approach)
The events a,d are underspecified (which one goes where
- needs to be fixed
• in this example, we start with states
State DD is
and B
refined to include states A and CThe transition from A to C also needs to be specified for th
D a D a D a
A A
b b b
B B e(P) B
C C
d d d
a
b
B A
b
e(P) • needs B
C to be fixed
d
C
d
Default state
• We specify this using a small arrow:
If we have substates A, B, and C and we want to enter state A by default, we
specify this using a small arrow:
D D
A A
or
B B
C C
History State
Can use a history entrance (H). The state entered is the last state the level was
in when it existed.
• The H entrance overrides a default state
• The scope of the H entrance is the current level of the diagram
History State
• The state entered is the last state the level was in when it existed.
C C
Example
History State
• A timer that continues to count down as the state is entered and exited
Can use a history entrance (H). The state entered is the last state the level was
in when it existed.
• The timer does •notThe
getHreset
entrance
whenoverrides
the statea is
default state
entered
• The scope of the H entrance is the current level of the diagram
• The scope of the H* entrance is to the lowest level of the diagram.
D
A
H
B
Example:
a timer that continues to count down as the state is entered and exit
(the timer does not get reset when the state is entered)
Orthogonality (Concurrency)
nality (concurrency)
D • AND
ple
• Y is the orthogonal product of A and D
e orthogonal product of A and D
Y
• From the default states:
A D
u
A E • If event ‘a’ occurs, then the diagram
g
moves from states A,F into state C,G at
a b d
F the same time (A is synchronised with D)
G
C a
• If event ‘u’ occurs, then only D is affected
and the diagram moves from A,F into
default states:
state A, E (A is independent from D)
’ occurs, then the diagram moves from states A,F into state C,G at the
e (A is synchronized with D)
Broadcast Communication
Button 1
Button 1&2 Blink Button 1
Increment
Hours Button 2 Hours
Button 2
Button 1&2 Blink Button 1
Increment Button 1
Minutes Minutes
Button 2
Button 2
Button 1
Button 1&2 Blink Increment Button 1
Seconds Seconds
Button 2
CurrentTime
Set
Example (continued)
Button 1
Button 1&2 Button 1
Blink Increment
Hours Button 2 Hours
Button 2
Button 1&2 Blink Button 1
Increment Button 1
Minutes Minutes
Button 2
Button 2
Button 1&2 Blink Button 1
Increment Button 1
Seconds Seconds
Button 2
Alarm Time
Set
Alarm Time
Set
Example (continued)
• xor
Clock
Display
Alarm Time
Display Time
Button 1 Button 2
Example (continued)
Set Current Set Alarm Time
Time
Clock
Alarm
Time
Display Time
Alarm On
Button 1
Button 1 Button 2
Now, validate the behavior of the statechart (i.e., does the statechart specify the
system the way we want it to work)
Now, validate the behavior of the statechart (i.e., does the statechart specify the
system the way we want it to work)
Is there a radio?
Example (Other Things to Consider)
• Is there a radio?
• ....
5.1 Examples for Statecharts 184
• Statecharts