0% found this document useful (0 votes)
37 views

Embedded Systems Lecture 4: Statecharts: Björn Franke University of Edinburgh

This document provides an overview of statecharts, which were introduced by David Harel in 1987 as a notation for describing large, complex reactive systems. Statecharts extend finite state machines with features like depth (also known as abstraction), orthogonality (also known as concurrency), and broadcast communication. They allow decomposition of states into hierarchical AND-OR states and refinement of states for more detail. Default and history states can also be specified to determine initial system state.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Embedded Systems Lecture 4: Statecharts: Björn Franke University of Edinburgh

This document provides an overview of statecharts, which were introduced by David Harel in 1987 as a notation for describing large, complex reactive systems. Statecharts extend finite state machines with features like depth (also known as abstraction), orthogonality (also known as concurrency), and broadcast communication. They allow decomposition of states into hierarchical AND-OR states and refinement of states for more detail. Default and history states can also be specified to determine initial system state.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Embedded Systems

Lecture 4: Statecharts

Björn Franke

University of Edinburgh
Overview

• Statecharts

• Definition

• Depth

• History, Default

• Concurrency

• Broadcast

• Example
Statecharts

• Statecharts were introduced by David Harel in 1987

• D. Harel, “Statecharts: A visual formalism for complex systems”, Science


of Computer Programming 8, 1987, pp. 231-274.

• Statecharts are useful for describing large, complex, reactive systems

• a reactive system is one which must continuously react to external and


internal stimuli

• They are a graphic notation (“visual”)

• Lecture based on Kendra Cooper’s notes


D. Harel, “Statecharts: A visual formalism for complex systems”, Sci
of Computer Programming 8, 1987, pp. 231-274.

Definition• based onareFSM


Statecharts useful for describing large, complex, reactive system
• a reactive system is one which must continuously re
external and internal stimuli

• They are a graphic notation (“visual”)

Statechart = state-diagrams
+ depth (also known as abstraction)
+ orthogonality (also known as concurrency)
+ broadcast communication

The Statechart notation is a kind of extended FSM with abstraction, concur


and 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

• Composed of states, transitions

• 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

• An output can be associated with the transition


Example

• State changes from A to B when event b occurs and the condition P is true;
the output is c

• c is global (can be seen everywhere in the Statechart model)

• c can be used as an input on a transition

• this supports communication in communication


! this supports the model in the model

b(P)/c
A
a
B
Depth (Hierarchie)

• Statecharts extend this with:

• Refinement, clustering

• AND, OR decomposition of states (actually XOR, not OR)


statecharts extend this with: a
B
o refinement, clustering e(P)
d
o AND, OR decomposition of states
C b
Example (Bottom-Up Clustering)
(actually XOR, not OR)

e (clustering, bottom up approach) Can be clustered like this:

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:

The arc labeled b is a common property to the


A
• A xor C
b B
e(P)
d
C
• The arc labeled b is a common property to the superstate D

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

D is refined to include states A andThe


C events a,d are underspecified (which one goes where?)
- needs to be fixed
• State D is
a refined
The to
transition from A to C also
• The
needs to be
events
specified
a,d
for the
are underspecified
example
D
include
A states A and C D (which one goes where?)

a
b
B A
b
e(P) • needs B
C to be fixed

d
C
d

vents a,d are underspecified (which one goes where?)


• The transition from A to C also
- needs to be fixed needs to be specified for the
ansition from A to C also needs to be specified for the example
example
D a
Default state

• If we have substates A, B, and C and we want to enter state A by default

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

• 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

• The scope of the H* entrance is to the lowest level of the diagram.


or
B B

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

• An event is seen everywhere in the diagram at the same time.


Example

• Specify the behaviour of an alarm clock using statecharts.

• Assumptions: The alarm clock has 2 buttons.


Example
• We can start with setting the current time.

• Need to set hours, minutes, seconds

• Need to decide which buttons (one, both together) do what

Set Current Time

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)

Now, consider setting the alarm time.

Set Alarm Time

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

Now, consider how these superstates relate to one another?


Seconds Seconds
Button 2

Alarm Time
Set

Example (continued)

Now, consider how these superstates relate to one another?

• xor

Clock

Display
Alarm Time
Display Time

Button 1 Button 2

Set Current Set Alarm Time


Time

Now, extend the statechart to describe the alarm going off.


Button 1 Button 2

Example (continued)
Set Current Set Alarm Time
Time

Now, extend the statechart to describe the alarm going off.

Clock
Alarm
Time
Display Time
Alarm On
Button 1

Button 1 Button 2

Set Current Set


Time Alarm

Now, validate the behavior of the statechart (i.e., does the statechart specify the
system the way we want it to work)

Question: What happens if the alarm goes off for 5 minutes?


Button 1 Button 2

Set Current Set


Example (Validation)
Time Alarm

Now, validate the behavior of the statechart (i.e., does the statechart specify the
system the way we want it to work)

Question: What happens if the alarm goes off for 5 minutes?

Display vs. Maintain the time?

Maintaining the time needs to occur concurrently with:


• the alarm going off
• setting the alarm time

Question: Is it possible to display and maintain the current time concurrently?

Next step is to fix the statechart.


After it is fixed, need to re-validate the statechart.

Other things to consider:

Is there a radio?
Example (Other Things to Consider)

• Is there a radio?

• Is there a snooze button?

• Is there a battery backup?

• ....
5.1 Examples for Statecharts 184

One-shot State Diagram for Chess Game


5.1 Examples for Statecharts 187

Vending Machine Model


5.1 Examples for Statecharts 190

An Aggregation and its Concurrent State


Diagrams (1)
Summary

• Statecharts

• State-Diagrams, Depth, Orthogonality, Broadcast Communication


Preview

• Imperative Programming Languages

• C, ADA, Real-Time Java, ...

You might also like