Embedded System Spring, 2011 Lecture 2: FORMALISMS FOR SYSTEM DESIGN Eng. Wazen M. Shbair.
-
Upload
lindsay-morton -
Category
Documents
-
view
257 -
download
0
Transcript of Embedded System Spring, 2011 Lecture 2: FORMALISMS FOR SYSTEM DESIGN Eng. Wazen M. Shbair.
Embedded SystemSpring, 2011Lecture 2: FORMALISMS FOR SYSTEM DESIGNEng. Wazen M. Shbair
IUG- Embedded System 2
Today’s Lecture
Object-oriented design. Unified Modeling Language (UML).
IUG- Embedded System 3
System modeling
Need languages to describe systems: useful across several levels of abstraction; understandable within and between
organizations. Block diagrams are a start, but don’t cover
everything.
3
IUG- Embedded System 4
Object-oriented design
Object-oriented (OO) design: A generalization of object-oriented programming.
Object = state + methods. State provides each object with its own
identity. Methods provide an abstract interface to the
object.
4
IUG- Embedded System 5
Objects and classes
Class: object type. Class defines the object’s state elements
but state values may change over time. Class defines the methods used to interact
with all objects of that type. Each object has its own state.
5
IUG- Embedded System 6
OO design principles
Some objects will closely correspond to real-world objects. Some objects may be useful only for
description or implementation. Objects provide interfaces to read/write
state, hiding the object’s implementation from the rest of the system.
6
IUG- Embedded System 7
UML
Developed by Booch et al. Goals:
object-oriented; visual; useful at many levels of abstraction; usable for all aspects of design.
7
IUG- Embedded System 8
UML object
d1: Display
pixels: array[] of pixelselementsmenu_items
pixels is a2-D array
comment
object nameclass name
attributes
8
IUG- Embedded System 9
UML class
Display
pixelselementsmenu_items
mouse_click()draw_box
operations
class name
9
IUG- Embedded System 10
The class interface
The operations provide the abstract interface between the class’s implementation and other classes.
Operations may have arguments, return values.
An operation can examine and/or modify the object’s state.
10
IUG- Embedded System 11
Choose your interface properly
If the interface is too small/specialized: object is hard to use for even one application; even harder to reuse.
If the interface is too large: class becomes too cumbersome for designers to
understand; implementation may be too slow; spec and implementation are probably buggy.
11
IUG- Embedded System 12
Relationships between objects and classes
Association: objects communicate but one does not own the other.
Aggregation: a complex object is made of several smaller objects.
Composition: aggregation in which owner does not allow access to its components.
Generalization: define one class in terms of another.
12
IUG- Embedded System 13
Class derivation
May want to define one class in terms of another. Derived class inherits attributes, operations of
base class.
Derived_class
Base_class
UMLgeneralization
13
IUG- Embedded System 14
Class derivation example
Display
pixelselementsmenu_items
pixel()set_pixel()mouse_click()draw_box
BW_display Color_map_display
baseclass
derived class
14
IUG- Embedded System 15
Multiple inheritance
Speaker Display
Multimedia_display
base classes
derived class
15
IUG- Embedded System 16
Links and associations
Link: describes relationships between objects.
Association: describes relationship between classes.
16
IUG- Embedded System 17
Link example
Link defines the contains relationship:
message
msg = msg1length = 1102
message
msg = msg2length = 2114
message set
count = 2
17
IUG- Embedded System 18
Association example
message
msg: ADPCM_streamlength : integer
message set
count : integer
0..* 1
contains
# contained messages # containing message sets
18
IUG- Embedded System 19
Stereotypes
Stereotype: recurring combination of elements in an object or class.
Example: <<foo>>
19
IUG- Embedded System 20
Behavioral description
Several ways to describe behavior: internal view; external view.
20
IUG- Embedded System 21
State machines
a b
state state name
transition
21
IUG- Embedded System 22
Event-driven state machines
Behavioral descriptions are written as event-driven state machines. Machine changes state when receiving an
input. An event may come from inside or outside
of the system.
22
IUG- Embedded System 23
Types of events
Signal: asynchronous event. Call: synchronized communication. Timer: activated by time.
23
IUG- Embedded System 24
Signal event
<<signal>>mouse_click
leftorright: buttonx, y: position
declaration
a
b
mouse_click(x,y,button)
event description
24
IUG- Embedded System 25
Call event
c d
draw_box(10,5,3,2,blue)
25
IUG- Embedded System 26
Timer event
e f
tm(time-value)
26
IUG- Embedded System 27
Example state machine
regionfound
got menuitem
calledmenu item
foundobject
objecthighlighted
start
finish
mouse_click(x,y,button)/find_region(region)
input/outputregion = menu/which_menu(i) call_menu(I)
region = drawing/find_object(objid) highlight(objid)
27
IUG- Embedded System 28
Sequence diagram
Shows sequence of operations over time. Relates behaviors of multiple objects.
28
IUG- Embedded System 29
Sequence diagram example
m: Mouse d1: Display u: Menu
mouse_click(x,y,button)which_menu(x,y,i)
call_menu(i)
time
29
IUG- Embedded System 30
Summary
Object-oriented design helps us organize a design.
UML is a transportable system design language. Provides structural and behavioral description
primitives.
30
IUG- Embedded System 31
Introduction
Example: model train controller.
31
IUG- Embedded System 32
Purposes of example
Follow a design through several levels of abstraction.
Gain experience with UML.
32
IUG- Embedded System 33
Model train setup
console
powersupply
rcvr motor
ECC address headercommand
33
Message
IUG- Embedded System 34
Requirements
Console can control 8 trains on 1 track. Throttle has at least 63 levels. Inertia control adjusts responsiveness with
at least 8 levels. Emergency stop button. Error detection scheme on messages.
34
IUG- Embedded System 35
Requirements form
name model train controllerpurpose control speed of <= 8 model trainsinputs throttle, inertia, emergency stop,
train #outputs train control signalsfunctions set engine speed w. inertia;
emergency stopperformance can update train speed at least 10
times/secmanufacturing cost $50power wall poweredphysicalsize/weight
console comfortable for 2 hands; < 2lbs.
35
IUG- Embedded System 36
Digital Command Control
DCC created by model railroad hobbyists, picked up by industry.
Defines way in which model trains, controllers communicate. Leaves many system design aspects open,
allowing competition. This is a simple example of a big trend:
Cell phones, digital TV rely on standards.
36© 2010 Husam Alzaq Computers as Components
IUG- Embedded System 37
DCC documents
Standard S-9.1, DCC Electrical Standard. Defines how bits are encoded on the rails.
Standard S-9.2, DCC Communication Standard. Defines packet format and semantics.
37
IUG- Embedded System 38
DCC electrical standard
Voltage moves around the power supply voltage; adds no DC component.
1 is 58 s, 0 is at least 100 s. time
logic 1 logic 0
58 s >= 100 s
38
IUG- Embedded System 39
DCC communication standard
Basic packet format: PSA(sD)+E. P: preamble = 1111111111. S: packet start bit = 0. A: address data byte. s: data byte start bit. D: data byte (data payload). E: packet end bit = 1.
39© 2010 Husam Alzaq Computers as Components
IUG- Embedded System 40
DCC packet types
Baseline packet: minimum packet that must be accepted by all DCC implementations. Address data byte gives receiver address. Instruction data byte gives basic instruction. Error correction data byte gives ECC.
40© 2010 Husam Alzaq Computers as Components
IUG- Embedded System 41
Conceptual specification
Before we create a detailed specification, we will make an initial, simplified specification. Gives us practice in specification and UML. Good idea in general to identify potential
problems before investing too much effort in detail.
41
IUG- Embedded System 42
Basic system commands
command name parameters
set-speed speed(positive/negative)
set-inertia inertia-value (non-negative)
estop none
42
IUG- Embedded System 43
Typical control sequence
:console :train_rcvrset-inertiaset-speed
set-speed
set-speed
estop
43
IUG- Embedded System 44
Message classes
command
set-inertia
value: unsigned-integer
set-speed
value: integer
estop
44
IUG- Embedded System 45
Roles of message classes
Implemented message classes derived from message class. Attributes and operations will be filled in for
detailed specification. Implemented message classes specify
message type by their class. May have to add type as parameter to data
structure in implementation.
45
IUG- Embedded System 46
Subsystem collaboration diagram
Shows relationship between console and receiver (ignores role of track):
:console :receiver
1..n: command
46
IUG- Embedded System 47
System structure modeling
Some classes define non-computer components. Denote by *name.
Choose important systems at this point to show basic relationships.
47
IUG- Embedded System 48
Major subsystem roles
Console: read state of front panel; format messages; transmit messages.
Train: receive message; interpret message; control the train.
48© 2010 Husam Alzaq Computers as Components
IUG- Embedded System 49
Console system classes
console
panel formatter transmitter
receiver* sender*
1
1
1
11 1
1 1 1 1
49
IUG- Embedded System 50
Console class roles
panel: describes analog knobs and interface hardware.
formatter: turns knob settings into bit streams.
transmitter: sends data on track.
50© 2010 Husam Alzaq Computers as Components
IUG- Embedded System 51
Train system classes
train set
train
receiver
controller
motorinterface
detector* pulser*
1 1..t 1
1
1 1
1 1
1
1
1 1
51© 2010 Husam Alzaq Computers as Components
IUG- Embedded System 52
Train class roles
receiver: digitizes signal from track. controller: interprets received commands
and makes control decisions. motor interface: generates signals required
by motor.
52© 2010 Husam Alzaq Computers as Components
IUG- Embedded System 53
Detailed specification
We can now fill in the details of the conceptual specification: more classes; behaviors.
Sketching out the spec first helps us understand the basic relationships in the system.
53
IUG- Embedded System 54
Train speed control
Motor controlled by pulse width modulation:
V
+
-
dutycycle
54
IUG- Embedded System 55
Console physical object classes
knobs*
train-knob: integerspeed-knob: integerinertia-knob: unsigned-
integeremergency-stop: boolean
pulser*
pulse-width: unsigned-integer
direction: boolean
sender*
send-bit()
detector*
read-bit() : integer
55© 2010 Husam Alzaq Computers as Components
IUG- Embedded System 56
Panel and motor interface classes
panel
train-number() : integerspeed() : integerinertia() : integerestop() : booleannew-settings()
motor-interface
speed: integer
56
IUG- Embedded System 57
Class descriptions
panel class defines the controls. new-settings() behavior reads the controls.
motor-interface class defines the motor speed held as state.
57© 2010 Husam Alzaq Computers as Components
IUG- Embedded System 58
Transmitter and receiver classes
transmitter
send-speed(adrs: integer, speed: integer)send-inertia(adrs: integer, val: integer)set-estop(adrs: integer)
receiver
current: commandnew: boolean
read-cmd()new-cmd() : booleanrcv-type(msg-type:
command)rcv-speed(val: integer)rcv-inertia(val:integer)
58
IUG- Embedded System 59
Class descriptions
transmitter class has one behavior for each type of message sent.
receiver function provides methods to: detect a new message; determine its type; read its parameters (estop has no
parameters).
59
IUG- Embedded System 60
Formatter class
formatter
current-train: integercurrent-speed[ntrains]: integercurrent-inertia[ntrains]: unsigned-integercurrent-estop[ntrains]: boolean
send-command()panel-active() : booleanoperate()
60
IUG- Embedded System 61
Formatter class description
Formatter class holds state for each train, setting for current train.
The operate() operation performs the basic formatting task.
61
IUG- Embedded System 62
Control input cases
Use a soft panel to show current panel settings for each train.
Changing train number: must change soft panel settings to reflect
current train’s speed, etc. Controlling throttle/inertia/estop:
read panel, check for changes, perform command.
62
IUG- Embedded System 63
Control input sequence diagram
:knobs :panel :formatter :transmitter
chan
ge in
spe
ed/
iner
tia/
esto
pch
ange
intr
ain
num
ber
change incontrolsettings
read panel
panel settingspanel-active
send-command
send-speed,send-inertia.send-estop
read panel
panel settings
read panel
panel settingschange intrainnumber
set-knobs
new-settings
63
IUG- Embedded System 64
Formatter operate behavior
idle
update-panel()
send-command()
panel-active() new train number
other
64
IUG- Embedded System 65
Panel-active behavior
panel*:read-train()current-train = train-knob
update-screenchanged = true
T
panel*:read-speed() current-speed = throttlechanged = true
T
F
...
F
...65
IUG- Embedded System 66
Controller class
controller
current-train: integercurrent-speed[ntrains]: integercurrent-direction[ntrains]: booleancurrent-inertia[ntrains]: unsigned-integer
operate()issue-command()
66
IUG- Embedded System 67
Setting the speed
Don’t want to change speed instantaneously.
Controller should change speed gradually by sending several commands.
67© 2010 Husam Alzaq Computers as Components
IUG- Embedded System 68
Sequence diagram for set-speed command
:receiver :controller :motor-interface :pulser*new-cmd
cmd-type
rcv-speed set-speed set-pulse
set-pulse
set-pulse
set-pulse
set-pulse
68
IUG- Embedded System 69
Controller operate behavior
issue-command()
receive-command()
wait for acommand
from receiver
69© 2010 Husam Alzaq Computers as Components
IUG- Embedded System 70
Refined command classes
command
type: 3-bitsaddress: 3-bitsparity: 1-bit
set-inertia
type=001value: 3-bits
set-speed
type=010value: 7-bits
estop
type=000
70© 2010 Husam Alzaq Computers as Components
IUG- Embedded System 71
Summary
Separate specification and programming. Small mistakes are easier to fix in the spec. Big mistakes in programming cost a lot of time.
You can’t completely separate specification and architecture. Make a few tasteful assumptions.
71
IUG- Embedded System 72
References
Jie Hu , ECE692 Embedded Computing Systems , Fall 2010.
Wayne Wolf’s , Computers as Components © 2000 , Morgan Kaufman