2012-09-03
Lecture 1
-
Introduction to
Embedded Systems
-
Damir Isovic
What is an embedded system?
Embedded system
• “A computer that doesn’t look like a computer”
• “A special-purpose computer that performs a few dedicated
functions, usually with very specific requirements”
• “Any device that includes a programmable computer but is not itself
a general-purpose computer”
Includes both hardware and software
• It is embedded as part of a complete device often including
hardware and mechanical parts
Often part of a larger system
• A modern car can contain up to 100 embedded CPUs (airbag,
engine, brakes, stability control, dashboard, navigation, multimedia,
…)
• Let’s start with some examples from the automotive industry…
1
2012-09-03
Example: Airbag
Airbags are inflatable cushions built into the steering wheel or dashboard,
designed to rapidly expand in a frontal crash.
When the car hits something, it gets decelerated (looses speed). If the
deceleration is fast enough, the crash sensors are triggered, and they
notify the control unit to inflate the airbag.
Airbag
Crash
sensors
Crash
The computer system that controls an airbag in a car is an embedded system.
Example: Cruise Control
A system that automatically controls the speed of a motor vehicle. The
system takes over the throttle of the car to maintain a steady speed as set
by the driver.
The observed speed is
lower than 90 km/h à The car starts to
increase the speed accelerate beyond
Driver sets the
automatically until 90 90 km/h à brake
desired speed
km/h is reached! automatically
to 90 km/h
2
2012-09-03
Example: Adaptive Cruise Control
Further development of the
Cruise Control
Maintains distance to car in
front by slowing down
vehicle.
Radar is used to measure
distance
Example: Electronic Damper Control (EDC)
Adjusts shock absorbers – better driving comfort
Relies on a number of sensors
• Steering wheel sensor
• Speed sensor
• Acceleration sensors
3
2012-09-03
Example: Vehicle Dynamic control (VDC)
Dynamic Stability Control (DSC)
• Steering wheel sensor
• Acceleration sensors
• Rotary movement sensors
• Brake pressure sensors
Electronic Stability Program (ESP)
• Steering wheel sensor
• Acceleration sensor
VDC, DSC & ESP help driver in
• Over-steering
• Under-steering
• Roll-over
Example: embedded systems in a car
…and many other functions performed by embedded computers in
modern cars…
4
2012-09-03
Other application areas…
Embedded systems control many devices in common use today – we’ll
check some examples…
Example: Home appliances
• Microwave oven - Almost every household
has one.
• However, few people realize that a computer
processor and software are involved in the
preparation of their lunch or dinner
Example: Consumer Electronics
• Personal digital assistants (PDAs), mp3
players, mobile phones, videogame
consoles, digital cameras, DVD players,
GPS receivers…
Other application areas…
Example: Medical equipment
• designed to aid in the diagnosis,
monitoring or treatment of medical
conditions
• Usually rigorous safety standards
Example: Military and aerospace
• Safety-critical systems
• High requirements on functional
and temporal correctness
• Usually subjects to rigorous
certification procedures
5
2012-09-03
…and many others industrial applications…
Embedded
computers
98%
Desktop
computers 2%
Embedded system vs PC
Desktop PC
• A general purpose product
• Performs many different things
• Significant system resources
• Advanced GUI
• Executes at its own pace
Embedded system
• A single purpose product
• Does one or a few things efficiently
• Often simpler and more application specific
hardware
• Often primitive and dedicated user interface
ECU
(no mouse, keyboard and screen)
• Execute at a pace determined by the
environment
6
2012-09-03
Embedded system vs PC
However, a PC interfaces to numerous embedded systems
• a keyboard and a mouse are embedded systems, i.e., they each
contain a processor and software and are designed to perform a
specific function
• Another example is a modem – peripheral designed to send
and receive digital data over an analog telephone line
Characteristics of embedded systems
Dedicated towards a certain application
• Usually designed for one single task, the
functionality will never change
• Knowledge about behavior at design time can be
used to minimize resources and to maximize
robustness.
Must be efficient
• Energy efficient
• Code size efficient
• Run-time efficient
• Weight efficient
• Cost efficient – often a mass product
Pacemaker battery
• All unneeded features are a disadvantage! lifetime is 7-12 years
7
2012-09-03
Characteristics of embedded systems
Reactive systems
• connected to physical environment through sensors Airbag
and actuators
• execute at a pace determined by the environment
Reliable (dependable)
• How reliable the result product must be
• Depends very much on the product:
o An antilock braking system for a car most always work
o A children's toy may still be useful even if it contains minor bugs
Making the system reliable must not be an after-thought, it must be
considered from the very beginning! Let’s see some examples...
A failure of a safety-critical embedded system
can lead to catastrophic consequences
Therac-25 Ariane 5 USS Yorktown
Computer controlled Exploded on June 4 1996, Computer crash
radiation therapy machine. only 39 seconds from brought down USS
launching Yorktown missile
6 accidents 1985 – 1987. carrier for 2 days.
Three people died of A 64 bit float was truncated
radiation burns. to a 16 bit integer in a Total systems failure
“non-critical” software when bad data was
Error in the Man-Machine- component fed into the ship’s
Interface computers - the
The erroneous component
Bug "Race Condition" (a method) was inherited/ Yorktown lost control
caused a simple erroneous reused from Ariane 4 and of its propulsion
input operation to deliver had no practical use in system because its
deadly doses Ariane 5. computers were
unable to
divide by zero!
8
2012-09-03
Real-time embedded systems
We have said that embedded systems usually are
• Specialized
• Efficient
• Reliable
• Reactive
Moreover, in many cases it is not enough just to react – the system
has to react to the environment at the right time instance, e.g., the
airbag must be inflated within a certain time interval after the crash.
Hence, in order to fulfill dependability, efficiency and timing
requirements, many embedded systems are implemented as real-
time systems!
Real-time systems
“A real-time system is a system that reacts upon outside events and
performs a function based on these and gives a response within a certain
time. Correctness of the function does not only depend on correctness of
the result, but also the timeliness of it”.
Non-real-time systems System does
• Correct function if produced the right thing
result is correct
Real-time systems System does ...and it does
• Correct function if the right thing... it on time
produced result is correct
and delivered on time +
9
2012-09-03
Example: medical device
Medical equipment must detect changes in the patient and respond on
time...
Example: medical device
…otherwise…
Delayed signal
Response to a critical event must be given on time !
10
2012-09-03
Example: Anti-lock Braking System (ABS)
ABS: makes possible to steer the vehicle while braking
3. Wheel disc
2. Pressure
brakes
passed to the
squeezed
brake fluid
1. Brake
pedal
pushed
5. Controller releases 6. The fluid is
the pressure on the pumped back to 4. If the brake pedal is
discs by releasing some repeat the pushed too hard, the
brake fluid in a presure on the wheel will lock à a
container discs sensor detects this and
notifies the controller
Embedded Controller
7. Entire process is repeated about 15 times/sec – real-time operation
Example: video processing
Picture 1 Picture 2 Picture 3 Picture 4 Picture 5
Displayed
pictures
per second
Perceived as
30 smooth video
24
Not perceived as
15 smooth video
10
11
2012-09-03
Example: Airbag
Let’s look again on our example with the airbag….
Airbag
Crash
sensors
Crash
REAL-TIME:
The decision to deploy an airbag is made within 15 to 30 milliseconds
after the onset of the crash, and the airbags are inflated within
approximately 50-80 milliseconds.
Example: Airbag
The airbag must not be inflated too late, nor too early!
Collision
Too early Too late
time
Real-time ≠ fast !
Real-Time = predictable!
12
2012-09-03
Real-time is NOT equivalent to fast
Real-time systems are rather predictable than fast
• Fast calculation: minimize average response time for entire system
• Real-time: fulfil individual time constraints for each task
”A man drowned in a river with an average depth of 20 centimetres”
How?
Predictable vs fast
A robot arm with good
timing catches the
passing boll.
13
2012-09-03
Predictable vs fast
To be fast is not enough !
Too fast robot arm
misses the passing
boll.
Hard and soft real-time systems
A real-time timing constraint is called hard, if not meeting that
constraint could result in a catastrophe. All other constraints are called soft.
Hard real-time
• Hard deadlines – catastrophe if deadline is missed
• Worst-case system behavior considered
• E.g. automotive, airplanes, industrial control, …
Soft real-time
• Fuzzier deadlines – can miss some deadlines
• Average-case considered
• E.g., consumer electronics
14
2012-09-03
Embedded real-time systems
Most embedded systems must real-time
fulfill real-time requirements
embedded
real-time
Most real-time systems are
embedded in products embedded
Embedded systems has to be designed with timing in mind !
(desktop systems only has to deal with functionality)
The embedded software architecture, and its interaction with the
system hardware, play a key role in ensuring that all deadlines
are met.
We’ll have a look on typical HW/SW configuration of embedded
real-time systems…
Embedded system components
A processor and some software
• Large variety of embedded processors Memory
• Most rather simple Inputs Outputs
CPU
A place to store the data and the
executable code
• Might be contained within the same chip as the
processor or reside in external memory chips
Some type of inputs and outputs
• Example of inputs: sensors and probes, communication
signals, or control knobs and buttons
• Example of outputs: displays, communication signals, or
actuators (for changes to the physical world)
• Converters (Analog-Digital and Digital-Analog)
15
2012-09-03
Embedded system hardware
There exists a large variety of hardware
platforms for embedded systems
• General-purpose processors
• Application-specific instruction set processors
(ASIP)
• Microcontrollers
• DSPs (digital signal processors)
• Programmable hardware (FPGA)
• Application-specific integrated circuits (ASICs)
Furthermore, the same CPU can be used with various
hardware configurations (memories, ports, …)
A hardware platform is most often tailored specifically to
the application
• Thereby, lowering system costs
• Unnecessary circuitry is eliminated and hardware resources
are shared wherever possible
Embedded system software
The software is very important!
• Gives characteristics to the product
• Allows the same HW to be used in many different ways
• CPU often cheaper than special HW
ES software often very HW specific
• Software developed for one HW platform need to be
modified to fit another HW platform (e.g., due to
different port addresses etc.)
Different programming languages used
• Assembly, C++, C, Java, Ada, …
• Best support for C
16
2012-09-03
Embedded system programming
Assembly languages
• today primarily used as a complement to a ...
high-level language MOVE (_X),D0
CMP D0,#5
• Usually only for startup system code or small BGT L1
code pieces which cannot be written in any MUL D0,#3
MOVE D0
other way JMP L2
L1: ADD D0,#1
• Lacks code portability L2:
• Finding skilled assembly programmers is hard ...
C++
• An object-oriented superset of C ...
class Thread {
• offers greater opportunities for expression, public:
encapsulation, re-use than C Thread();
int Start(void *arg);
• Increasingly popular among embedded protected:
int Run(void * arg);
programmers static void *Entry(void*);
…
• Hard to make C++ code as compact and };
Thread::Thread() {}
efficient as C code
Embedded system programming
Ada
• Object-oriented language
with Ada.Text_IO;
• Includes many features suitable for ES
procedure Hello is
development (strong typing, parallel begin
processing, run-time checking,…) Ada.Text_IO.Put_Line(“Hi!");
end Hello;
• Not used much outside defense and
aerospace industries
Java
• Object-oriented language
...
• Increasingly popular among high-end ES class RunnableThread
implements Runnable
programmers {
− However, only subsets of the Java Thread runner;
public RunnableThread() {}
environment is normally used public RunnableThread(String
− Java’s byte code interpretation might be threadName)
{
slower and less predictable than running runner = new Thread(this,
precompiled machine code threadName);
runner.start();
• There exists special processors running Java }
byte code (picoJava, ARM926RJ-S,…) }
…
17
2012-09-03
Embedded system programming
C – “the language of embedded programmers”
C has several features making it suitable for ES
• C is a “mid-level” with “high-level” features (such as support for
functions and modules), and a “low-level” features (such as good
access to hardware via pointers)
• It is very efficient, popular and fairly simple to learn
• C compilers are available for almost every CPU in use
• There is a large variety of C support tools available
• There is a large body of experienced C programmers
• Books, courses, code samples widely available
• C is highly processor-independent – allows programmers to
concentrate on algorithms and applications rather than on the details
of a particular processor architecture
Embedded software development
To meet cost demands the resources are often limited
• Low processing power, memory, battery,..
• The rules for writing firmware gets different from the rules for
writing software for a PC
− E.g., using standard dynamic memory allocation functions can
cause fragmentation, and eventually the system may cease to
operate
Reusable software
• Writing reusable code is useful to aid transition to new projects
• This cannot always be done, since many ES are very individual
Development tools
• There is a large variety of ES development tools
• They are usually less powerful and easy to use than the
corresponding PC development tools
18
2012-09-03
Embedded software development
Hardware knowledge
• An ES developer gets close to the hardware
• Things like integrated circuits, boards, buses, attached devices,
schematics, and oscilloscopes must be well understood
Efficient and robust code
• An ES is typically designed with the least powerful and most cost-
effective CPU that meets the performance requirements
• Many embedded systems are expected to run without user
interaction for many years
Peripheral interfaces
• Embedded developers need to know how to communicate with the
different devices or peripherals in order to have full control of the
devices in the system
Common ES design requirements
The range of typical values of the presented design requirements (a
guideline, should not be taken as strict delineations)
Criterion Low Medium High
Processor 4- or 8-bit 16-bit 32- or 64-bit
Memory < 64 KB 64 KB to 1 MB > 1 MB
Development cost < $100,000 $100,000 to > $1,000,000
$1,000,000
Production cost < $10 $10 to $1,000 > $1,000
Number of units < 100 100 to 10,000 > 10,000
Power consumption > 10 mW/MIPS 1 to 10 mW/MIPS < 1 mW/MIPS
Lifetime Days, weeks, or Years Decades
months
Reliability May occasionally Must work reliably Must be fail-proof
fail
19
2012-09-03
Real-time requirements affecting design
How important is the timeliness of computations
• Not simply about speed – a faster CPU is not always the solution
An embedded real-time system must be predictable
• The main concern is to guarantee that all hard deadlines of the
system are always met
The embedded software architecture, and its interaction
with the system hardware, play a key role in ensuring that
all deadlines are met:
• Is polling sufficient or should interrupts be used?
• What priorities should be assigned to tasks and interrupts?
Example low level requirements
Pedometer
• Count steps, keep time, averages, etc.
• Identify when a step is actually taken
• 8-bit processor, runs ~forever on a
single battery
Lego Mindstorm robotic kit
• Standard microcontroller chip
• 8-bit Renesas H8/300 CPU
• 64 kB of memory
• Interface to motors and sensors
20
2012-09-03
Example medium requirements
Forestry machines
• Controlling arms & tools
• Navigating the forest
• Communicate with
remote database
• Tough environment
− -40°C at startup, +100°C when
running
• 16-bit C167 processors
• CAN network
Mobile phones
• Multiprocessor
− 8/16/32-bit for UI
− DSP for radio
− 32-bit ARM in IR port
− 32-bit ARM in Bluetooth
− 10-200 MHz main CPU
• Huge memories
• Huge amount of software
Example high requirements
Mobile base stations
• Massive signal processing
• Several processing tasks per connected mobile
phone
• 1000s of independent parallel tasks
• Based on DSPs
− Standard or custom
− 500-1000 MHz
− 100s of processors
Automotive
• Multiple networks
• CAN for body electronics: 30+ nodes
• CAN for engine control: few nodes
• LIN for instruments
• MOST for infotainment
• Many diverse processors
• 8-bit - door locks, lights, etc.
• 16-bit - most functions
• 32-bit - engine control, airbags
21
2012-09-03
This course...
Today, all advanced products contain embedded systems…
Mars Pathfinder
…they are tricky…. Mars, July 4, 1997
Lost contact
due to embedded
software failure.
Ariane 5
…they are risky…. French Guyana, June 4, 1996
$800 million
embedded software
failure
…but they are highly relevant!
After taking this course, you should be prepared to
develop real-world embedded system applications!
This course…
Upon successful completion of this course, you will:
• Acquire a basic knowledge about embedded systems and how to
program those.
• Be able to identify the hardware components that can be a part of an
embedded system, and that influence the choice of the programming
model used.
• Be able to develop and debug simple computer programs for
embedded systems, where the communication with the environment
is done directly via the peripheral devices (e.g., via interrupts)
• Be able to develop and debug more complex software for embedded
systems by using the support from a real-time operating system.
• Be able to develop applications with predictable timing behavior, so
called real-time applications, for embedded systems.
• Be able to perform different performance evaluations, e.g., CPU and
memory usage, in embedded devices.
• Be able to use different tools to develop embedded systems, e.g.,
RTOS, debuggers, and IDEs.
22