UML for Embedded Systems III. Detailed Design - Eurecom

33 downloads 15 Views 276KB Size Report
history of its input. □ Characterized by an internal state. • Current state = past experience. (C) Ludovic Apvrille. UML for Embedded Systems - Fall 2012 slide 6.
UML for Embedded Systems III. Detailed Design Ludovic Apvrille [email protected] Eurecom, Office 470

Memo on Methodology

IV. Validation of the system Simulation Code generation

III. Detailed design Behavior of the system

I. Analysis Use case First class diagram Relevant scenarios

II. Design Classes of the system Architecture of the system

slide 2

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Page 1

Detailed Design Stage 



slide 3

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

Detailed Design  Basics

of automata  Modeling objects with states machines  UML state machine diagram  TAU G2 state machines  Examples

slide 4

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Page 2

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

slide 5

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Example of State Machine Diagrams

Start state

LampOff

on()

States

off()

Trigger lampOn

slide 6

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Page 3

Output and Actions  Actions

can be generated either at state entrance, exit or at trigger level LampOff

on()/print("on"); off()

lampOn

Mealy automaton

Use of Variables

Integer ctr; LampOff

on()/ctr = ctr+1; off()

lampOn

slide 8

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Page 4

Mealy Machines 

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 9

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

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

slide 10

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Page 5

Detailed Design  Basics

of automata  Modeling objects with states machines  UML state machine diagram  TAU G2 state machines  Examples

(C) Ludovic Apvrille

slide 11

UML for Embedded Systems - Fall 2012

What Can be Modeled with State Machines?  State

machines are well-suited for the modeling of eventdriven and discrete behavior  Inappropriate for modeling continuous behavior

threshold

time  Are

State Machines well-suited for modeling real-time and embedded systems? • What is an event-driven systems? • What are real-time and embedded systems?

slide 12

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Page 6

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

slide 13

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Embedded Systems’ Architecture  Embedded

system = controlling system + controlled system + environment Controlling System Sensors Sensors Actuators

Sensors Sensors Sensors

Interface Controlled System slide 14

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Page 7

Response to External Events External Hostile Environment Synchronous

Synchronous

Asynchronous

Asynchronous

Event (Input)

Embedded System

Response (Output)

Single event

Single event

Multiple event

Multiple event

slide 15

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

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 the computation, but also on the time at which the results are produced” (J. Stankovic, “Misconceptions About Real-Time Computing”, IEEE Computer, 21(10), October 1988)

slide 16

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Page 8

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. slide 17

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Response to External Events

Timing Constraints

Synchronous

Synchronous

Asynchronous

Asynchronous

Event (Input)

Real-Time RealSystem

Response (Output)

Single event

Single event

Multiple event

Multiple event

slide 18

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Page 9

Are State Machines Well-Suited for Modeling Real-Time and embedded Systems?  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 19

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Object Behavior: General Model

Initialization

Waiting for input

Note: this is not a UML state machine but rather a flowchart to explain how an object generally behaves

Computing input

Sending output

Termination

slide 20

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Page 10

Example

Initialization LampOff

Waiting for input

on()/print(on); off()

Computing input

Sending output

lampOn stopLamp()

Termination

slide 21

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

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

slide 22

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Page 11

Object Behavior: Active Objects

Initialization

Waiting for input

Computing input

Sending output

Termination

slide 23

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Object Behavior: Passive Objects

Initialization

Waiting for input

Computing input

Sending output

Termination

slide 24

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Page 12

Passive Objects: Synchronization Issues

Initialization

Waiting for input

Synchronization may be required!

Computing input

Sending output

Termination

slide 25

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

V. Detailed Design  Basics

of automata  Modeling objects with states machines  UML state machine diagram  TAU G2 state machines  Examples

slide 26

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Page 13

Basics of UML State Machine Diagrams 

States



Transitions s1



Message [condition] / action

s2

Transition with temporal information E1

slide 27

when (date = 10)

(C) Ludovic Apvrille

E1

E2

after(100)

E2

UML for Embedded Systems - Fall 2012

States, Transitions and Actions LampOn entry/lamp.on();

off/printf(“to off”);

LampOff entry/lamp.off();

exit/printf(“exiting”);

exit/printf(“exiting”);

off/printf(“needless”); LampOff entry/lamp.off(); exit/printf(“exiting”); off/null slide 28

(C) Ludovic Apvrille

Self transition entry and exit actions are ignored

UML for Embedded Systems - Fall 2012

Page 14

UML 2.x State Machines: Towards SDL state1

Waiting for the receiving of signal signal1

signal1()

signal2()

Sending of signal signal2

state2

slide 29

(C) Ludovic Apvrille

UML for Embedded Systems - Fall 2012

Guards

state1

LampOff

Integer x;

entry/lamp.off();

signal1()

exit/printf(“exiting”); x = x +1;

on[LampIsPlugged]/printf(“to on”); LampOn

signal2()

x=5

x