chapter 1 embedded computing 金仲達教授 清華大學資訊工程學系 (slides are taken from...
Post on 21-Dec-2015
247 views
TRANSCRIPT
Chapter 1
Embedded Computing
金仲達教授清華大學資訊工程學系
(Slides are taken from the textbook slides)
Embedded Computing-2
Outline What are embedded systems? Challenges in embedded computing
system design Design methodologies Object-oriented design and Unified
Modeling Language (UML) Example: model train controller
Embedded Computing-3
Definition Embedded system: any device that
includes a programmable computer but is not itself a general-purpose computer.
Take advantage of application characteristics to optimize the design: don’t need all the general-purpose bells and
whistles.
Embedded Computing-4
Embedding a computer
CPU
mem
input
output analog
analog
embeddedcomputer
Embedded Computing-5
Examples Personal digital assistant (PDA). Printer. Cell phone. Automobile: engine, brakes, dash, etc. Television. Household appliances. PC keyboard (scans keys).
Embedded Computing-6
Early history Late 1940’s: MIT Whirlwind computer for rea
l-time operations; Originally designed to control an aircraft simulator.
First P was Intel 4004 in early 1970’s. HP-35 calculator used several chips to implem
ent a microprocessor in 1972 Automobiles used microprocessor-based engi
ne controllers starting in 1970’s. Control fuel/air mixture, engine timing, etc. Multiple modes of operations: warm-up, hill climbi
ng.. Provides lower emissions, better fuel efficiency.
Embedded Computing-7
Microprocessor varieties Microcontroller: includes I/O devices, on-boar
d memory. Digital signal processor (DSP): microprocessor
optimized for digital signal processing. Typical embedded word sizes: 8-bit, 16-bit, 32-
bit.
Embedded Computing-8
Application examples Simple control: front panel of microwave oven,
etc. Canon EOS 3 has three microprocessors.
32-bit RISC CPU runs autofocus and eye control systems.
Analog TV: channel selection, etc. Digital TV: programmable CPUs + hardwired lo
gic.
Embedded Computing-9
Automotive embedded systems High-end automobile may have 100 Ps:
4-bit microcontroller checks seat belt; microcontrollers run dashboard devices; 16/32-bit microprocessor controls engine.
BMW 850i Anti-lock brake system (ABS): pumps brakes to red
uce skidding. Automatic stability control (ASC+T): controls engin
e to improve stability. ABS was introduced first--> ASC+T needs to interfac
e to existing ABS module.
Embedded Computing-10
BMW 850i, cont’d.
brake
sensor
brake
sensor
brake
sensor
brake
sensor
ABShydraulic
pump
Embedded Computing-11
Characteristics of embedded systems Sophisticated functionality.
Often run sophisticated algo. or multiple algo. Cell phone, laser printer.
Often provide sophisticated user interfaces. Real-time operation.
Must finish operations by deadlines. Hard real time: missing deadline causes failure. Soft real time: missing deadline results in degraded p
erformance. Many systems are multi-rate: must handle operatio
ns at widely varying rates.
Embedded Computing-12
Characteristics of embedded systems Low manufacturing cost.
Many embedded systems are mass-market items that must have low manufacturing costs.
Limited memory, microprocessor power, etc. Low power.
Power is critical in battery-powered devices Excessive power consumption increases system
cost even in wall-powered devices. Designed to tight deadlines by small
teams. 6 month market window is common. E.g., can’t miss back-to-school window for
calculator.
Embedded Computing-13
Why use microprocessors? Alternatives: field-programmable gate arrays
(FPGAs), custom logic, etc. Intuition: Microprocessors use much more logic to i
mplement a function than does custom logic. But, microprocessors are often efficient, beca
use can use same logic to perform different functions heavily pipelined large design teams aggressive VLSI technology
Microprocessors simplify the design of families of products.
Embedded Computing-14
Although power is a concern, Custom logic is a clear winner for low
power devices. Modern microprocessors offer features to
help control power consumption. Software design techniques can help
reduce power consumption.
Embedded Computing-15
Outline What are embedded systems? Challenges in embedded computing
system design Design methodologies Object-oriented design and Unified
Modeling Language (UML) Example: model train controller
Embedded Computing-16
Challenges in embedded system design How much hardware do we need?
How big is the CPU? Memory? How do we meet our deadlines?
Faster hardware or cleverer software? How do we minimize power?
Turn off unnecessary logic? reduce mem. accesses? Does it really work?
Is the specification correct? Is the spec met? How do we test for real-time, real data?
How do we work on the system? Observability, controllability? development platfor
m?
Embedded Computing-17
Design methodologies A procedure for designing a system. Understanding methodology helps you
ensure you didn’t skip anything. Compilers, computer-aided design (CAD)
tools, software engineering tools, etc., can be used to: help automate methodology steps; keep track of the methodology itself.
Embedded Computing-18
Need to consider design goals Performance.
Overall speed, deadlines. Functionality and user interface. Manufacturing cost. Power consumption. Other requirements (physical size, etc.)
Embedded Computing-19
Work with levels of abstraction
requirements
specification
architecture
componentdesign
systemintegration
Top-downdesign
Bottom-updesign
Real design usesboth techniques
Embedded Computing-20
Stepwise refinement At each level of abstraction, we must:
analyze the design to determine characteristics of the current state of the design;
refine the design to add detail.
Embedded Computing-21
Level 1: Requirements Plain language description of what the
user wants and expects to get. May be developed in several ways:
talking directly to customers; talking to marketing representatives; providing prototypes to users for comment.
Embedded Computing-22
Functional vs. non-functional requirements Functional requirements:
output as a function of input. Non-functional requirements:
time required to compute output; size, weight, etc.; power consumption; reliability; etc.
Embedded Computing-23
Our requirements formnamepurposeinputsoutputsfunctionsperformancemanufacturing costpowerphysical size/weight
Embedded Computing-24
Example: GPS moving map requirements Moving map
obtains position from GPS, paints map from local database.
lat: 40 13 lon: 32 19
I-78
Sco
tch
Roa
d
Embedded Computing-25
GPS moving map needs Functionality: For automotive use. Show majo
r roads and landmarks. User interface: At least 400 x 600 pixel screen.
Three buttons max. Pop-up menu. Performance: Map scroll smoothly. Less than 1
sec power-up. Lock onto GPS within 15 sec Cost: $500 street price = approx. $100 cost of g
oods sold. Physical size/weight: Should fit in hand. Power consumption: 8 hours on 4 AA batteries.
Embedded Computing-26
GPS moving map requirements form
name GPS moving mappurpose consumer-grade
moving map for drivinginputs power button, two
control buttonsoutputs back-lit LCD 400 X 600functions 5-receiver GPS; three
resolutions; displayscurrent lat/lon
performance updates screen within0.25 sec of movement
manufacturing cost $100 cost-of-goods-sold
power 100 mWphysical size/weight no more than 2: X 6:,
12 oz.
Embedded Computing-27
Level 2: Specification A more precise description of the system:
should not imply a particular architecture; provides input to the architecture design
process. May include functional and non-functional
elements. May be executable or may be in
mathematical form for proofs. UML (Unified Modeling Language)
Embedded Computing-28
GPS specification Should include:
What is received from GPS; map data; user interface; operations required to satisfy user requests; background operations needed to keep the
system running.
Embedded Computing-29
Level 3: Architecture design What major components go satisfying the
specification? Hardware components:
CPUs, peripherals, etc. Software components:
major programs and their operations. Must take into account functional and non-
functional specifications.
Embedded Computing-30
GPS moving map block diagram
GPSreceiver
searchengine
renderer
userinterfacedatabase
display
Embedded Computing-31
GPS moving map hardware architecture
GPSreceiver
CPU
panel I/O
display framebuffer
memory
Embedded Computing-32
GPS moving map software architecture
position
databasesearch
renderer
timeruser
interface
pixels
Embedded Computing-33
Level 4: HW and SW components Must spend time architecting the system befor
e you start coding. Some components are ready-made, some can
be modified from existing designs, others must be designed from scratch.
Embedded Computing-34
Level 5: System integration Put together the components.
Many bugs appear only at this stage. Have a plan for integrating components to
uncover bugs quickly, test as much functionality as early as possible.
Embedded Computing-35
Outline What are embedded systems? Challenges in embedded computing
system design Design methodologies Object-oriented design and Unified
Modeling Language (UML) Example: model train controller
Embedded Computing-36
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.
Embedded Computing-37
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. Class: object type
Defines the object’s state elements but state values may change over time.
Defines the methods used to interact with all objects of that type.
Each object has its own state.
Embedded Computing-38
OO implementation in C++class display {pixels : pixeltype[IMAX,JMAX];
public:display() { }pixeltype pixel(int i, int j)
{ return pixels[i,j]; }void set_pixel(pixeltype val, int i, int j) { pixels[i,j] = val; }
}
Embedded Computing-39
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.
Embedded Computing-40
UML Unified Modeling Language Developed by Booch et al. Goals:
object-oriented; visual; useful at many levels of abstraction; usable for all aspects of design.
Embedded Computing-41
UML object
d1: Display
pixels: array[] of pixelselementsmenu_items
pixels is a2-D array
comment
object nameclass name
attributes
Embedded Computing-42
UML class
Display
pixelselementsmenu_items
mouse_click()draw_box
operations
class name
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.
Embedded Computing-43
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.
Embedded Computing-44
Class derivation Define one class in terms of another.
Derived class inherits attributes, operations of base class.
Derived_class
Base_class
UMLgeneralization
Embedded Computing-45
Class derivation example
Display
pixelselementsmenu_items
pixel()set_pixel()mouse_click()draw_box
BW_display Color_map_display
baseclass
derived class
Embedded Computing-46
Multiple inheritance
Speaker Display
Multimedia_display
base classes
derived class
Embedded Computing-47
message
msg: ADPCM_streamlength : integer
message set
count : integer
0..* 1
contains
# contained messages # containing message sets
Association Association: describes relationship
between classes. Example:
association name
Embedded Computing-48
Links Link: describes relationships between
objects. Example: Link defines the contains
relationshipmessage
msg = msg1length = 1102
message
msg = msg2length = 2114
message set
count = 2
Embedded Computing-49
Behavioral description We have discussed how to specify
structure Now consider describing behavior of the
system: internal view external view
Use state machinesa b
state state name
transition
Embedded Computing-50
Event-driven state machines Behavioral descriptions are written as
event-driven state machines. Machine changes state when receiving an
input. Events may come from inside or outside of
the system Signal: asynchronous event. Call: synchronized communication. Timer: activated by time.
Embedded Computing-51
<<signal>>mouse_click
leftorright: buttonx, y: position
declaration
a
b
mouse_click(x,y,button)
event description
Types of events Signal event:
Embedded Computing-52
c d
draw_box(10,5,3,2,blue)
Types of events Call event:
Timer event:
e f
tm(time-value)
Embedded Computing-53
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)
Embedded Computing-54
Sequence diagram Shows sequence of operations over time. Relates behaviors of multiple objects.
m: Mouse d1: Display u: Menu
mouse_click(x,y,button)which_menu(x,y,i)
call_menu(i)
time
Embedded Computing-55
Outline What are embedded systems? Challenges in embedded computing
system design Design methodologies Object-oriented design and Unified
Modeling Language (UML) Example: model train controller
Embedded Computing-56
Model train setup
console
powersupply
rcvr motor
ECCaddressheader command
Embedded Computing-57
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.
Embedded Computing-58
Requirements form
Embedded Computing-59
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. Can start with message definitions, which dete
rmines what the controller can doCommand Parameter set-speed speed (positive or negative)set-inertia inertial-value (nonnegative)estop None
Embedded Computing-60
Message classes
command
set-inertia
value: unsigned-integer
set-speed
value: integer
estop
Embedded Computing-61
:console :train_rcvrset-inertiaset-speed
set-speed
set-speed
estop
:console :receiver1..n: command
Subsystem collaboration
Sequencediagram
Embedded Computing-62
Major subsystem roles Console:
read state of front panel; format messages; transmit messages.
Train: receive message; interpret message; control the train.
Embedded Computing-63
Console system classes
console
panel formatter transmitter
receiver* sender*
1
1
1
11 1
1 1 1 1
Embedded Computing-64
Console class roles panel: describes analog knobs and
interface hardware. formatter: turns knob settings into bit
streams. transmitter: sends data on track.
Embedded Computing-65
Train system classes
train set
train
receiver
controller
motorinterface
detector* pulser*
1 1..t 1
1
1 1
1 1
1
1
1 1
Embedded Computing-66
Train class roles receiver: digitizes signal from track. controller: interprets received commands
and makes control decisions. motor interface: generates signals
required by motor.
Embedded Computing-67
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.
Embedded Computing-68
Train speed control Motor controlled by pulse width
modulation:
V
+
-
dutycycle
Embedded Computing-69
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
Embedded Computing-70
Panel and motor-interface classes panel class defines the controls.
new-settings() behavior reads the controls. motor-interface class defines the motor
speed held as state.
panel
train-number() : integerspeed() : integerinertia() : integerestop() : booleannew-settings()
motor-interface
speed: integer
Embedded Computing-71
Transmitter and receiver classes Transmitter: 1 behavior for each type
message Receiver function provides methods to:
detect a new message, decidetype, read parameters
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)
Embedded Computing-72
Formatter class
formatter
current-train: integercurrent-speed[ntrains]: integercurrent-inertia[ntrains]: unsigned-integercurrent-estop[ntrains]: boolean
send-command()panel-active() : booleanoperate()
Formatter class holds state for each train, setting for current train.
The operate() operation performs the basic formatting task.
Embedded Computing-73
Control input cases Use a soft panel to show current panel setting
s 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.
Embedded Computing-74
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
Embedded Computing-75
Formatter operate behavior
idle
update-panel()
send-command()
panel-active() new train number
other
Embedded Computing-76
Panel-active behavior
panel*:read-train()current-train = train-knob
update-screenchanged = true
T
panel*:read-speed() current-speed = throttlechanged = true
T
F
...
F
...
Embedded Computing-77
Controller class
controller
current-train: integercurrent-speed[ntrains]: integercurrent-direction[ntrains]: booleancurrent-inertia[ntrains]: unsigned-integer
operate()issue-command()
Embedded Computing-78
Setting the speed Don’t want to change speed
instantaneously. Controller should change speed gradually
by sending several commands.
Embedded Computing-79
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
Embedded Computing-80
Controller operate behavior
issue-command()
receive-command()
wait for acommand
from receiver
Embedded Computing-81
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
Embedded Computing-82
Summary Embedded computers are all around us.
Many have complex embedded HW and SW Many design challenges: design time, deadlines,
power, etc. Methodologies help manage design process. Object-oriented design helps organize a design. UML is a transportable system design language.
Provides structural and behavioral primitives. Separate specification and programming. Can’t completely separate specification and
architecture. Make a few tasteful assumptions.