18.01.2013 Views

UML for Embedded Systems III. Detailed Design - Eurecom

UML for Embedded Systems III. Detailed Design - Eurecom

UML for Embedded Systems III. Detailed Design - Eurecom

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

slide 2<br />

Memo on Methodology<br />

<strong>III</strong>. <strong>Detailed</strong> design<br />

Behavior of the system<br />

II. <strong>Design</strong><br />

Classes of the system<br />

Architecture of the system<br />

<strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong><br />

<strong>III</strong>. <strong>Detailed</strong> <strong>Design</strong><br />

Ludovic Apvrille<br />

ludovic.apvrille@telecom-paristech.fr<br />

<strong>Eurecom</strong>, Office 470<br />

Page 1<br />

IV. Validation of the<br />

system<br />

Simulation<br />

Code generation<br />

I. Analysis<br />

Use case<br />

First class diagram<br />

Relevant scenarios<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012


slide 3<br />

slide 4<br />

<strong>Detailed</strong> <strong>Design</strong> Stage<br />

� Purpose<br />

• <strong>Design</strong> the behavior of classes<br />

� State machine diagrams<br />

• Signal sending<br />

• Signal receiving<br />

• Composite states<br />

• Loop, tests<br />

• Setting and use of variables<br />

• Etc.<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

<strong>Detailed</strong> <strong>Design</strong><br />

� Basics of automata<br />

� Modeling objects with states machines<br />

� <strong>UML</strong> state machine diagram<br />

� TAU G2 state machines<br />

� Examples<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Page 2


slide 5<br />

slide 6<br />

Basics of Automata<br />

� Definition<br />

• Machines whose input behavior is not only a direct<br />

consequence of the current input, but of some past<br />

history of its input<br />

� Characterized by an internal state<br />

• Current state = past experience<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Example of State Machine Diagrams<br />

LampOff<br />

on() off()<br />

lampOn<br />

Page 3<br />

Start state<br />

States<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Trigger


Output and Actions<br />

� Actions can be generated<br />

either at state entrance,<br />

exit or at trigger level<br />

slide 8<br />

Use of Variables<br />

LampOff<br />

on()/ctr = ctr+1; off()<br />

lampOn<br />

Page 4<br />

LampOff<br />

on()/print("on"); off()<br />

lampOn<br />

Mealy automaton<br />

Integer ctr;<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012


slide 9<br />

slide 10<br />

Mealy Machines<br />

� Mealy machines<br />

• Hopcroft and Ullman (1979, 42), Salomaa (1973, 31)<br />

• Finite-state machines<br />

- Take a string on an input alphabet<br />

- Producing a string of equal length on an output alphabet.<br />

� Formally, a Mealy machine is a six-tuple<br />

M = (Q, Σ, Γ, δ, λ, q 1)<br />

• where<br />

- Q = (q 1, q 2, …, q |Q|) is a finite set of states;<br />

- Σ = (σ 1, σ 2, …, σ |Σ|) is a finite input alphabet;<br />

- Γ = (γ 1, γ 2, …, γ |Γ|) is a finite output alphabet;<br />

- δ : Q x Σ → Q is the next-state function, such that a machine in state q j, after reading symbol σ k,<br />

moves to state δ(q j, σ k) ∈ Q<br />

- λ : Q x Σ → Γ is the output function, such that a machine in state q j, after reading symbol σ k,<br />

writes symbol λ(q j, σ k) ∈ Γ ; and<br />

- q 1 ∈ Q is the initial state in which the machine is found be<strong>for</strong>e the first symbol of a string is<br />

processed<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Example<br />

� Let M = (Q, Σ, Γ, δ, λ, q1) with<br />

• Q = {q1, q2} • Σ = {sig1, sig2}<br />

• Γ = {out1, out2}<br />

• δ(q1, sig1) = q1; δ(q1, sig2) = q2;<br />

• δ(q2, sig1) = q2; δ(q2, sig2) = q1;<br />

• λ(q1, sig1) = out1; λ(q1, sig2) = out2;<br />

• λ(q2, sig1) = out2; λ(q2, sig2) = out1;<br />

� Propose a graphical representation of this machine<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Page 5


slide 11<br />

slide 12<br />

<strong>Detailed</strong> <strong>Design</strong><br />

� Basics of automata<br />

� Modeling objects with states machines<br />

� <strong>UML</strong> state machine diagram<br />

� TAU G2 state machines<br />

� Examples<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

What Can be Modeled with State<br />

Machines?<br />

� State machines are well-suited <strong>for</strong> the modeling of eventdriven<br />

and discrete behavior<br />

� Inappropriate <strong>for</strong> modeling continuous behavior<br />

threshold<br />

� Are State Machines well-suited <strong>for</strong> modeling real-time and<br />

embedded systems?<br />

• What is an event-driven systems?<br />

• What are real-time and embedded systems?<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Page 6<br />

time


slide 13<br />

slide 14<br />

Event-Driven Behavior<br />

� Event = a type of observable occurrence<br />

• Interactions<br />

- Invocation of object operations is synchronous (call event)<br />

- Receiving of asynchronous signal (signal event)<br />

• Occurrence of time instants (time event)<br />

- Interval expiry<br />

- Calendar/clock time<br />

• Change in value of some entity (change event)<br />

� Event Instance = an instance of an event (type)<br />

• Occurs at a particular time instant and has no duration<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

<strong>Embedded</strong> <strong>Systems</strong>’ Architecture<br />

� <strong>Embedded</strong> system = controlling system + controlled<br />

system + environment<br />

Sensors Sensors<br />

Controlling<br />

System<br />

Controlled<br />

System<br />

Page 7<br />

Sensors Sensors Actuators<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Interface


Synchronous<br />

Asynchronous<br />

slide 15<br />

Single event<br />

Multiple event<br />

slide 16<br />

Response to External Events<br />

Event<br />

(Input)<br />

External Hostile<br />

Environment<br />

<strong>Embedded</strong><br />

System<br />

Page 8<br />

Response<br />

(Output)<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

What is a Real-Time System?<br />

Synchronous<br />

Asynchronous<br />

Single event<br />

Multiple event<br />

� Real-Time <strong>Systems</strong> have been defined as:<br />

“Those systems in which the correctness of the<br />

system depends not only on the logical results of the<br />

computation, but also on the time at which the results<br />

are produced”<br />

(J. Stankovic, “Misconceptions About Real-Time<br />

Computing”, IEEE Computer, 21(10), October 1988)<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012


slide 17<br />

slide 18<br />

Jobs and Tasks<br />

� Task<br />

• A task is a set of related jobs joined to provide functions<br />

� Job<br />

• A job is a unit of work, scheduled and executed by the<br />

system<br />

� Parameters<br />

• Temporal behavior<br />

- Last less than 20ms, periodic task i.e. executes every 30 ms<br />

• Functional: intrinsic properties of the job<br />

- Taps of filter<br />

• Resource requirements<br />

- 10kb of memory<br />

• Interconnection: its communication with other jobs<br />

- The decoding job must send its result to the displaying job<br />

- May use shared memory, message queues, etc.<br />

Synchronous<br />

Asynchronous<br />

Single event<br />

Multiple event<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Response to External Events<br />

Event<br />

(Input)<br />

Timing<br />

Constraints<br />

Real Real-Time Time<br />

System<br />

Page 9<br />

Response<br />

(Output)<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Synchronous<br />

Asynchronous<br />

Single event<br />

Multiple event


slide 19<br />

slide 20<br />

Are State Machines Well-Suited <strong>for</strong> Modeling<br />

Real-Time and embedded <strong>Systems</strong>?<br />

� What do you think?<br />

� What should be modeled with state machines?<br />

• In principle, anything that manifests event-driven behavior<br />

• In practice:<br />

- The behavior of individual objects<br />

- Object interactions<br />

� The dynamic semantics of <strong>UML</strong> state machines are<br />

currently mainly specified <strong>for</strong> the case of active<br />

objects<br />

� Note: currently, there is no support in <strong>UML</strong> <strong>for</strong><br />

modeling continuous behavior<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Object Behavior: General Model<br />

Initialization<br />

Waiting <strong>for</strong> input<br />

Computing input<br />

Sending output<br />

Termination<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Page 10<br />

Note: this is not a<br />

<strong>UML</strong> state<br />

machine but<br />

rather a flowchart<br />

to explain how an<br />

object generally<br />

behaves


slide 21<br />

slide 22<br />

Example<br />

Initialization<br />

Waiting <strong>for</strong> input<br />

Computing input<br />

Sending output<br />

Termination<br />

Page 11<br />

LampOff<br />

on()/print(on); off()<br />

lampOn<br />

stopLamp()<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Active and Passive Objects<br />

� An active object is a thread of control of the<br />

application<br />

• Autonomous<br />

• No internal concurrency<br />

• Mechanisms <strong>for</strong> storing input data<br />

� A passive object is an object which is not active<br />

• It is activated by external power<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012


slide 23<br />

slide 24<br />

Object Behavior: Active Objects<br />

Initialization<br />

Waiting <strong>for</strong> input<br />

Computing input<br />

Sending output<br />

Termination<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Object Behavior: Passive Objects<br />

Initialization<br />

Waiting <strong>for</strong> input<br />

Computing input<br />

Sending output<br />

Termination<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Page 12


slide 25<br />

slide 26<br />

Passive Objects: Synchronization Issues<br />

Synchronization<br />

may be<br />

required!<br />

Initialization<br />

Waiting <strong>for</strong> input<br />

Computing input<br />

Sending output<br />

Termination<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

V. <strong>Detailed</strong> <strong>Design</strong><br />

� Basics of automata<br />

� Modeling objects with states machines<br />

� <strong>UML</strong> state machine diagram<br />

� TAU G2 state machines<br />

� Examples<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Page 13


� States<br />

� Transitions<br />

slide 27<br />

Basics of <strong>UML</strong> State Machine Diagrams<br />

Message [condition] / action<br />

s1 s2<br />

� Transition with temporal<br />

in<strong>for</strong>mation<br />

when (date = 10)<br />

E1 E2<br />

slide 28<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

States, Transitions and Actions<br />

LampOn<br />

entry/lamp.on();<br />

exit/printf(“exiting”);<br />

off/printf(“to off”);<br />

LampOff<br />

entry/lamp.off();<br />

exit/printf(“exiting”);<br />

off/null<br />

Page 14<br />

after(100)<br />

E1 E2<br />

LampOff<br />

entry/lamp.off();<br />

exit/printf(“exiting”);<br />

off/printf(“needless”);<br />

Self transition<br />

entry and exit<br />

actions are<br />

ignored<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012


slide 29<br />

<strong>UML</strong> 2.x State Machines: Towards SDL<br />

state1<br />

signal1()<br />

signal2()<br />

state2<br />

Page 15<br />

Waiting <strong>for</strong><br />

the<br />

receiving<br />

of signal<br />

signal1<br />

Sending of<br />

signal<br />

signal2<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Guards<br />

LampOff<br />

entry/lamp.off();<br />

exit/printf(“exiting”);<br />

on[LampIsPlugged]/printf(“to on”);<br />

LampOn<br />

entry/lamp.on();<br />

exit/printf(“exiting”);<br />

x = 5<br />

state2<br />

state1<br />

signal1()<br />

x = x +1;<br />

signal2()<br />

x


slide 31<br />

slide 32<br />

Composite States: Hierarchical State<br />

Machines<br />

State1<br />

State2.1<br />

State2.1<br />

State2.2<br />

H<br />

Page 16<br />

State3<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Order of Actions<br />

S1<br />

exit/exS1<br />

S11<br />

exit/exS11<br />

E/actE<br />

Execution sequence when E:<br />

H<br />

H*<br />

S2<br />

entry/enS2<br />

initS2<br />

S21<br />

entry/enS21<br />

exS11 � exS1 � actE � enS2 � initS2 � enS21<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Swallow history<br />

Deep history


slide 33<br />

slide 34<br />

Orthogonal Regions<br />

oven on<br />

oven off<br />

Page 17<br />

oven light<br />

on<br />

oven light<br />

off<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Deferred Events<br />

� Events can be deferred if they cannot be computed<br />

• Saved <strong>for</strong> future use<br />

off/<br />

LampOff<br />

entry/lamp.off()<br />

off/defer<br />

LampOn<br />

on/<br />

entry/lamp.on()<br />

Event is<br />

deferred<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012


slide 35<br />

slide 36<br />

Fork and Join Transitions<br />

Child Adult Retiree<br />

Staff<br />

Member<br />

Page 18<br />

Manager<br />

age<br />

employee<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

<strong>Detailed</strong> <strong>Design</strong><br />

� Basics of automata<br />

� Modeling objects with states machines<br />

� <strong>UML</strong> state machine diagram<br />

� With TAU G2<br />

� Examples<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012


slide 37<br />

slide 38<br />

States Machines under TAU G2<br />

Deferred<br />

signal<br />

Termination of<br />

the object<br />

signal3<br />

x = 5<br />

state2<br />

signal3()<br />

state1<br />

signal1()<br />

x = x + 1;<br />

signal2()<br />

x


fromCounter<br />

slide 39<br />

slide 40<br />

Counter<br />

port1<br />

Counter<br />

<br />

Loop<br />

Integer<br />

<br />

fromCounter<br />

Loop (Integer)<br />

Statechart Diagram statemachine initialize {1/1}<br />

All transition should have a condition<br />

<strong>for</strong> being triggered<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Page 20<br />


Set Bell<br />

'port'<br />

Alarm<br />

slide 41<br />

slide 42<br />

Alarm Clock<br />

<br />

Bell<br />

<br />

Set<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Page 21<br />

waitForSet<br />

Set()<br />

set(myTimer(), now+10);<br />

waitForTimer<br />

myTimer()<br />

Bell()<br />

waitForSet<br />

Simulation of Alarm Clock<br />

sd Trace (7) Sequence diagram trace<br />

generated by Tau<br />

<strong>for</strong> Alarm<br />

interaction UseCase3 {1/1}<br />

env[1]<br />

'@Set' ()<br />

Alarm[1]<br />

waitForSet<br />

waitForTimer<br />

Bell ()<br />

waitForSet<br />

myTimer () /* 10.0000 */<br />

myTimer ()<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

statemachine initialize {1/1}<br />

timer myTimer;


slide 43<br />

slide 44<br />

Exercises: Ping-Pong Game<br />

� Two players P1 and P2<br />

� P1<br />

• Sends value k to P2<br />

• Waits <strong>for</strong> value k<br />

• Increment k<br />

• And so on..<br />

� P2<br />

• Waits <strong>for</strong> a value x<br />

• Returns x to the sender<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Microwave Oven<br />

� We wish to model a basic oven with a door and a<br />

« start » button<br />

� Once a meal has been put in the oven, the user<br />

pushes the « start » button. Once pushed, the meal<br />

is heated <strong>for</strong> 30 seconds. Then, the oven stops and<br />

plays a bell sound<br />

� Alternatively, the user may open the door while the<br />

oven is heating. In that case, the heating process<br />

stops and the 30s delay is set to 0<br />

(C) Ludovic Apvrille <strong>UML</strong> <strong>for</strong> <strong>Embedded</strong> <strong>Systems</strong> - Fall 2012<br />

Page 22<br />

« Start » button

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!