uml for embedded systems iii. detailed design -...
TRANSCRIPT
Page 1
UML for Embedded SystemsIII. Detailed Design
Ludovic [email protected], Office 470
slide 2
Memo on Methodology
I. AnalysisUse case
First class diagramRelevant scenarios
II. DesignClasses of the system
Architecture of the system
III. Detailed designBehavior of the system
IV. Validation of the system
SimulationCode generation
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 2
slide 3
Detailed Design Stage
� Purpose• Design the behavior of classes
� State machine diagrams• Signal sending• Signal receiving• Composite states• Loop, tests• Setting and use of variables• Etc.
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
slide 4
Detailed Design
� Basics of automata� Modeling objects with states machines� UML state machine diagram� TAU G2 state machines� Examples
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 3
slide 5
Basics of Automata
� Definition• Machines whose input behavior is not only a direct
consequence of the current input, but of some past history of its input
� Characterized by an internal state• Current state = past experience
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
slide 6
Example of State Machine Diagrams
LampOffLampOff
lampOnlampOn
on()on() off()off()
Start state
States
Trigger
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 4
Output and Actions
� Actions can be generated either at state entrance, exit or at trigger level
LampOffLampOff
lampOnlampOn
on()/print("on");on()/print("on"); off()off()
Mealy automaton
slide 8
Use of Variables
LampOffLampOff
lampOnlampOn
on()/ctr = ctr+1;on()/ctr = ctr+1; off()off()
Integer ctr;Integer ctr;
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 5
slide 9
Mealy Machines
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
� Mealy machines• Hopcroft and Ullman (1979, 42), Salomaa (1973, 31)• Finite-state machines
- Take a string on an input alphabet
- Producing a string of equal length on an output alphabet.
� Formally, a Mealy machine is a six-tuple M = (Q, Σ, Γ, δ, λ, q1)• where
- Q = (q1, q2, …, q|Q|) is a finite set of states;
- Σ = (σ1, σ2, …, σ|Σ|) is a finite input alphabet;
- Γ = (γ1, γ2, …, γ|Γ|) is a finite output alphabet;
- δ : Q x Σ → Q is the next-state function, such that a machine in state qj, after reading symbol σk, moves to state δ(qj, σk) ∈ Q
- λ : Q x Σ → Γ is the output function, such that a machine in state qj, after reading symbol σk, writes symbol λ(qj, σk) ∈ Γ ; and
- q1 ∈ Q is the initial state in which the machine is found before the first symbol of a string is processed
slide 10
Example
� Let M = (Q, Σ, Γ, δ, λ, q1) with• Q = {q1, q2}• Σ = {sig1, sig2}• Γ = {out1, out2}• δ(q1, sig1) = q1; δ(q1, sig2) = q2; • δ(q2, sig1) = q2; δ(q2, sig2) = q1;• λ(q1, sig1) = out1; λ(q1, sig2) = out2; • λ(q2, sig1) = out2; λ(q2, sig2) = out1;
� Propose a graphical representation of this machine
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 6
slide 11
Detailed Design
� Basics of automata� Modeling objects with states machines� UML state machine diagram� TAU G2 state machines� Examples
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
slide 12
What Can be Modeled with State Machines?
� State machines are well-suited for the modeling of event-driven and discrete behavior
� Inappropriate for modeling continuous behavior
� Are State Machines well-suited for modeling real-ti me and embedded systems?• What is an event-driven systems?• What are real-time and embedded systems?
timetime
thresholdthreshold
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 7
slide 13
Event-Driven Behavior
� Event = a type of observable occurrence• Interactions
- Invocation of object operations is synchronous (call event)
- Receiving of asynchronous signal (signal event)
• Occurrence of time instants (time event)- Interval expiry
- Calendar/clock time
• Change in value of some entity (change event)� Event Instance = an instance of an event (type)
• Occurs at a particular time instant and has no duration
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
slide 14
Embedded Systems’ Architecture
� Embedded system = controlling system + controlled system + environment
Controlling Controlling SystemSystem
SensorsSensorsSensorsSensorsSensorsSensorsSensorsSensorsSensorsSensorsActuatorsActuators
Controlled Controlled SystemSystem
Interface
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 8
slide 15
Event(Input)
Response to External Events
Embedded Embedded SystemSystem
Response(Output)
Synchronous
Asynchronous
Single event
Multiple event
Synchronous
Asynchronous
Single event
Multiple event
External Hostile Environment
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
slide 16
What is a Real-Time System?
� Real-Time Systems have been defined as:“Those systems in which the correctness of the system depends not only on the logical results of t he computation, but also on the time at which the resu lts are produced”
(J. Stankovic, “Misconceptions About Real-Time Computing”, IEEE Computer, 21(10), October 1988)
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 9
slide 17
Jobs and Tasks
� Task• A task is a set of related jobs joined to provide functions
� Job• A job is a unit of work, scheduled and executed by the
system� Parameters
• Temporal behavior- Last less than 20ms, periodic task i.e. executes every 30 ms
• Functional: intrinsic properties of the job- Taps of filter
• Resource requirements- 10kb of memory
• Interconnection: its communication with other jobs- The decoding job must send its result to the displaying job- May use shared memory, message queues, etc.
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
slide 18
Event(Input)
Response to External Events
RealReal--Time Time SystemSystem
Response(Output)
Timing ConstraintsSynchronous
Asynchronous
Single event
Multiple event
Synchronous
Asynchronous
Single event
Multiple event
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 10
slide 19
Are State Machines Well-Suited for Modeling Real-Time and embedded Systems?
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
� What do you think?
� What should be modeled with state machines?• In principle, anything that manifests event-driven behavior
• In practice:- The behavior of individual objects
- Object interactions
� The dynamic semantics of UML state machines are currently mainly specified for the case of active objects
� Note: currently, there is no support in UML for modeling continuous behavior
slide 20
Object Behavior: General Model
Initialization
Sending output
Termination
Computing input
Waiting for input
Note: this is not a UML state machine but rather a flowchart to explain how an object generally behaves
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 11
slide 21
Example
LampOffLampOff
lampOnlampOn
on()/print(on); off()off()
stopLamp()stopLamp()
Initialization
Sending output
Termination
Computing input
Waiting for input
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
slide 22
Active and Passive Objects
� An active object is a thread of control of the application• Autonomous• No internal concurrency• Mechanisms for storing input data
� A passive object is an object which is not active• It is activated by external power
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 12
slide 23
Object Behavior: Active Objects
Initialization
Sending output
Termination
Computing input
Waiting for input
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
slide 24
Object Behavior: Passive Objects
Initialization
Sending output
Termination
Computing input
Waiting for input
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 13
slide 25
Passive Objects: Synchronization Issues
Initialization
Sending output
Termination
Computing input
Waiting for input
Synchronization may be
required!
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
slide 26
V. Detailed Design
� Basics of automata� Modeling objects with states machines� UML state machine diagram� TAU G2 state machines� Examples
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 14
slide 27
Basics of UML State Machine Diagrams
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
� States
� Transitions
� Transition with temporal information
s1 s2Message [condition] / action
after(100)E1 E2
when (date = 10)E1 E2
slide 28
States, Transitions and Actions
off/printf(“needless”);off/printf(“needless”);
off/printf(“to off”);off/printf(“to off”);LampOffLampOff
entry/lamp.off();entry/lamp.off();
exit/printf(“exiting”);exit/printf(“exiting”);
LampOnLampOn
entry/lamp.on();entry/lamp.on();
exit/printf(“exiting”);exit/printf(“exiting”);
LampOffLampOff
entry/lamp.off();entry/lamp.off();exit/printf(“exiting”);exit/printf(“exiting”);off/nulloff/null
Self transitionentry and exit
actions are ignored
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 15
slide 29
UML 2.x State Machines: Towards SDL
state1state1
signal2()signal2()
signal1()signal1()
state2state2
Waiting for the receiving of signal signal1
Sending of signal signal2
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Guards
state1state1
signal2()signal2()
signal1()signal1()
state2state2
x = x +1;x = x +1;
Integer x;Integer x;
x <5x <5x = 5x = 5
LampOffLampOffentry/lamp.off();entry/lamp.off();
exit/printf(“exiting”);exit/printf(“exiting”);
LampOnLampOnentry/lamp.on();entry/lamp.on();
exit/printf(“exiting”);exit/printf(“exiting”);
on[LampIsPlugged]/printf(“to on”);on[LampIsPlugged]/printf(“to on”);
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 16
slide 31
State2.1State2.1
Composite States: Hierarchical State Machines
State1State1
State2.1State2.1State2.1State2.1
State2.2State2.2State2.2State2.2
State3State3
H
H*
Swallow historyDeep history
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
H
slide 32
Order of Actions
S1S1exit/exS1exit/exS1
S2S2entry/enS2entry/enS2
initS2initS2E/actEE/actE
Execution sequence when E:
exS11 � exS1 � actE � enS2 � initS2 � enS21
S21S21entry/enS21entry/enS21
S11S11exit/exS11exit/exS11
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 17
slide 33
Orthogonal Regions
oven off
oven lighton
oven lightoff
oven on
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
slide 34
Deferred Events
� Events can be deferred if they cannot be computed• Saved for future use
off/off/
LampOnLampOn
entry/lamp.on()entry/lamp.on()
on/on/
LampOffLampOff
entry/lamp.off()entry/lamp.off()off/deferoff/defer
Event is deferred
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 18
slide 35
Fork and Join Transitions
StaffStaffMemberMember
employeeemployee
ChildChild AdultAdult RetireeRetiree
ageage
ManagerManagerManagerManager
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
slide 36
Detailed Design
� Basics of automata� Modeling objects with states machines� UML state machine diagram� With TAU G2� Examples
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 19
slide 37
States Machines under TAU G2
state1state1
signal2()signal2()
signal1()signal1()
state2state2
x = x + 1;x = x + 1;
Integer x;Integer x;
x <5x <5x = 5x = 5
signal3()signal3()
signal3signal3
Deferred signal
Termination of the object
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
slide 38
Detailed Design
� Basic of automata� Modeling objects with states machines� UML state machine diagram� TAU G2 state machines� Examples
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 20
slide 39
Counter
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
statemachine initializeStatechart Diagram {1/1}statemachine initializeStatechart Diagram {1/1}
initinitInteger value;Integer value;
valuevalue
[true][true]
All transition should have a condition for being triggeredAll transition should have a condition for being triggered
Loop(value)Loop(value)
<5<5
value = 0;value = 0;
initinit
elseelse
value = value + 1;value = value + 1;
Counter
Counter
<<interface>>
fromCounter
Loop (Integer)
<<interface>>
fromCounter
Loop (Integer)
port1port1
fromCounterfromCounter
<<signal>>
Loop
Integer
<<signal>>
Loop
Integer
slide 40
Counter: Trace Obtained at Simulation Step
Counter[1]
Counter[1]
env[1]
env[1]
Sequence diagram tracegenerated by Taufor Counter
Sequence diagram tracegenerated by Taufor Counter
initinit
Loop(1)Loop(1)
initinit
Loop(2)Loop(2)
initinit
Loop(3)Loop(3)
initinit
Loop(4)Loop(4)
initinit
Loop(5)Loop(5)
initinit
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 21
slide 41
Alarm Clock
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Alarm
Alarm'port''port'
SetSet BellBell
<<signal>>
Bell<<signal>>
Bell<<signal>>
Set<<signal>>
Set
statemachine initialize {1/1}
waitForSetwaitForSet
Set()Set()
timer myTimer; timer myTimer;
set(myTimer(), now+10);set(myTimer(), now+10);
waitForTimerwaitForTimer
myTimer()myTimer()
waitForSetwaitForSet
Bell()Bell()
slide 42
Simulation of Alarm Clocksd Trace (7) interaction UseCase3 {1/1}sd
Alarm[1] Alarm[1]
env[1]
env[1]
Trace (7) interaction UseCase3 {1/1}Sequence diagram tracegenerated by Taufor Alarm
Sequence diagram tracegenerated by Taufor Alarm
'@Set' ()'@Set' ()
waitForSetwaitForSet
myTimer () /* 10.0000 */myTimer () /* 10.0000 */
waitForTimerwaitForTimer
myTimer ()myTimer ()
Bell ()Bell ()
waitForSetwaitForSet
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
Page 22
slide 43
Exercises: Ping-Pong Game
� Two players P1 and P2� P1
• Sends value k to P2• Waits for value k• Increment k• And so on..
� P2• Waits for a value x• Returns x to the sender
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012
slide 44
Microwave Oven
� We wish to model a basic oven with a door and a « start » button
� Once a meal has been put in the oven, the user pushes the « start » button. Once pushed, the meal is heated for 30 seconds. Then, the oven stops and plays a bell sound
� Alternatively, the user may open the door while the oven is heating. In that case, the heating process stops and the 30s delay is set to 0
« Start » button
(C) Ludovic Apvrille UML for Embedded Systems - Fall 2012