Embedded Processors
Contents
-
What are embedded systems?
-
What/how do they control?
-
Languages and cross-language interfaces
Without embedded systems..
From Ball Embedded Microprocessor Systems
You get into your car and turn the key on.
You take a 3.5" floppy disk from the glove compartment,
insert it into a slot on the dashboard, and drum your fingers
on the steering wheel until the operating system prompt appears
on the dashboard LCD. Using the cursor keys on the centre console
you select the program for electronic ignition, then turn the key
to start the engine.
On the way to work you want to listen to some music, so you
insert the program CD into the player, wait for the green light to
flash indicating that the digital signal processor in the player
is ready, then put in your music CD.
You get to work and go to the cafeteria for a pastry.
Someone has borrowed the mouse from the microwave but has not
unplugged the microwave itself, so the operating system is still up.
You can heat your breakfast before starting work.
With embedded systems...
-
You don't need a traditional user interface to decide which programs
should be running - the car's electronic ignition program will
respond to the car key, and the microwave doesn't need a mouse
-
You don't need to load programs into your devices - the ones
needed to make it work should already be loaded
(although in some new mobile phones you can download
extra programs)
-
You don't need to waste time waiting
for the O/S to load - if one is needed,
then it doesn't have baggage that make it slow to load
-
You don't need to load programs or data from a slow disk drive -
most information needed will be in fast ROM
Embedded systems
From Ball again: an embedded system has the following characteristics
-
Dedicated to controlling a specific real-time device or function
-
Self-starting, not requiring human intervention to begin.
The user cannot tell if the system is controlled by a
microprocessor or by dedicated hardware
-
Self-contained, with the operating program in some kind
of non-volatile memory
Embedded Systems
An embedded microprocessor system will generally have
-
A microprocessor
-
RAM
-
Nonvolatile storage, such as EPROM, ROM, etc
-
I/O - not necessarily a keyboard, mouse or monitor
Micro-controllers/processors
Micro-controller
Micro-processor
How are things controlled?
- Switches
- Switches can be used to switch things on or off e.g.
lights can be on or off
- Switches
- They can also be used to switch between values
e.g a heater can be set to a number of values
- Sensors
-
Sensors can tell if something is on or off
- Sensors
-
Sensors can tell you the value of something e.g. temperature
- Timers
- Timers can control the duration of other activities, such
as how long a light is on
- Analogue controllers
-
Things such as voltage can be set for analogue devices such
as motors
What can be controlled?
These are some of the things in a house that can be controlled
by embedded systems
-
Security and alarm systems
-
Lighting
-
Entertainment systems e.g. which channel, volume
-
Heating and airconditioning
-
Garden watering systems
-
Showers, baths
-
Toilets
Advantages of communicating devices
-
The caller id of someone phoning can be shown on the TV
-
The TV can turn its volume down when the phone rings
-
The VCR will turn itself on for the phone call
-
All of the clocks can synchronise time instead of needing
to be individually set
-
Turn off the watering system if it is raining
-
When the alarm system goes off and you are in your car,
then the car is told
-
Your phone number list is shared by your phone, mobile, fax, PDA
and PC without you having to do anything
Realtime
-
Embedded systems usually need to respond in a timely manner
-
A hard realtime system guarantees that a response
to and event will occur within a specified fixed time e.g. a
car braking system must respond to a braking action within 1/10
of a second
-
A soft realtime system will try to respond to an event
within an average response time e.g. a watering system will
try to turn off a sprinkler within 5 seconds of the request
-
Hard realtime systems must limit the amount of uncontrolled
activity that can occur e.g. a background virus scan of a
20Gb disk can severely affect response time
Software
-
Each microprocessor has its own instruction set
-
Usually the vendor will supply an assembler or cross-assembler
for the microprocessor
-
Assembly level programming is hard
-
It is possible to do e.g. O/O style programming in Assembler,
but only with a great deal of discipline
-
Higher-level programming may or may not be better
C programming
Limits of C
-
C cannot perform every operation required for an embedded system
-
before an application runs, the function call stack
must be initialised to empty, but a C program starts with
a call to
main()
. So a C program cannot initialise
the call stack
-
one way of implementing semaphores (for mutual exclusion) is
to disable interrupts; C cannot do this
-
C code cannot perform context switching, required when
switching from user-level to privileged level for O/S calls
-
C code may not be as efficient as hand-coded Assembler
-
It is harder to predict space/time usage for C code than
for hand-built Assembler - important for realtime systems.
e.g. it is easy to write recursive functions in C (to handle
trees, graphs) and these can blow stack
C/Assembler interface
-
When a call to a function is made in C, a stack frame is pushed.
This contains
-
Information to allow return from the procedure call:
base of previous stack frame, code location of function call
-
Space for local variables
-
In parameters for the call
-
Function return value
-
The exact format of this stack frame must be understood by any
Assembler function called
-
e.g. a C function can have a variable number of arguments, unlike
languages such as Pascal. This is used in functions such
as
printf()
. This forces a particular order of the
input parameters on the stack, which is slightly more time
consuming to process than
the "pascal" order
C Stack Frame
The function
int f(int a1, int a2, int a3) {
int local1, local2,local3;
....
}
has a call stack frame of
On call, the arguments are pushed onto the stack and space is resevered
for local variables.
The argument values, return address and local variabels can all be accessed
from the frame pointer. On return, the stack frame is discarded by restoring
the stack pointer from the frame pointer value.
Higher level languages: C++
-
C++ is designed to be forward compatable with C
-
Many
C programs will compile as C++ programs (many restrictions exist)
-
At the link level, most C functions can be called from C++,
giving a high degree of compatability
-
This has come at the
expense of making C++ a horribly difficult, inconsistent and
complex language
Higher level languages: Java
-
Java has two defined mechanisms for interfacing with C code
-
The first still exists as legacy code within most Java
virtual machines (e.g. most of the AWT is written in C using
this legacy interface)
-
The second official interface (JNI) was never supported by
Microsoft and was a factor in the loss of their Java license
-
C functions called from Java must follow a fixed format
-
There is a set of C functions to manipulate Java objects
-
The protection mechanisms for Java code (e.g. array bounds
checks) do not exist for native C code, so coding at this
level can introduce unchecked bugs
-
By use of JNI, Java code can call C code which in turn can call
Assembler code
-
Java 2 Standard Edition and Enterprise Edition are memory
hogs, so a variety of "lightweight" Java versions have been
invented, and not all of these include JNI
Higher level languages: C#
-
C# is a Java clone invented by Microsoft in official ignorance
of the existence of Java
-
It makes minor changes to syntax and uses a more flexible virtual
machine
-
It allows easy inclusion of unsafe C-style code into programs
Conclusion
-
Embedded processors form the heart of internet devices
-
There is a huge body of knowledge about embedded processor
design
-
There is a huge variation in processor types and capabilities,
requiring specialist knowledge
-
Embedded processors can be programmed in a variety of languages
-
Use of high-level languages still requires use of lower-level ones,
so attention has to be paid to the coupling of function
calls in different languages
Jan Newmarch <jan@newmarch.name>
Last modified: Thu Feb 26 14:55:34 EST 2004
Copyright © Jan Newmarch, Monash University, 2007
This work is licensed under a
Creative Commons License
The moral right of Jan Newmarch to be identified as the author of this page has been asserted.