Embedded system

An **embedded system** is a computer that has been built to solve only a few very specific problems and is not easily changed. The word _embedded_ means it is built into the system. It is a permanent part in a bigger system. It usually does not look like a computer, often no keyboard or monitor or mouse. But like any computer it has a processor, software, input, and output.

For example, the controller embedded in an elevator tells the motor to move the elevator to different floors, based on buttons that are pushed. A decoder is embedded in a satellite television set-top box  to read a signal from the dish and send something that a TV understands.  Often this type of system must do its work in a specific amount of time.  This is called real-time computing.  If a set-top box got interrupted to do another task, you would see a bad picture on the TV, for example.  A general purpose computer will often have short pauses while it does something else, it is not real-time.

Embedded systems control many of the common devices  such as card readers in hotel door locks or several things in a car.  They can control small things like an MP3 player or a digital camera, and large things like traffic light systems, airplane<nowiki/>s, or assembly line<nowiki/>s in a factory.

## Examples of embedded systems

Embedded systems are used in many kinds of electrical devices, including:

- Telecommunications systems use them for telephones, cell phone network, and wi-fi routers.
- Consumer electronics include broadcast receivers, MP3 players, mobile phones, video game consoles, digital cameras, DVD players, GPS receivers, home security systems, and printers.
- Household appliances, like microwave ovens, washing machines, burglar alarm systems and dishwashers have embedded systems.
- Transportation uses embedded systems for everything from locomotives for trains, airplanes and automobiles.
- Industry uses electric motors with electronic controllers, card readers and CNC machines which automatically make metal parts.
- Medical devices like defibrillators, automated blood pressure readers, and automated insulin pumps.
- Military devices, like walkie-talkies, satellites and the guiding systems for missiles.

## Common features

- Embedded systems are designed to do a specific task, unlike general-purpose computers.
- They do not look like a computer - there may not be a monitor, keyboard or mouse.
- Many embedded systems must be able to do things in _real-time_ - in a short amount of time (almost instantly from a human view).
- Many embedded systems must be very safe and reliable, especially for medical devices or avionics controlling airplanes.
- Starts very quickly.  People don't want to wait a minute or two for their car or emergency equipment to start.
- It may use a special operating system (or sometimes a very small home-made OS) that helps meet these requirements called a real-time operating system.
- The program instructions written for embedded systems are referred to as firmware, and are stored in read-only memory or flash memory chips. They run with limited computer hardware resources: little memory, small or non-existent keyboard and/or screen.

Embedded systems are not always standalone devices. Sometimes they are built as a set, like the various parts of a car - the radio, the throttle control, the pollution control, etc. Sometimes they can communicate to the internet or a cell-phone network and they may have a USB reader or other connections.

## User interfaces

Embedded systems range from no user interface at all — only sending and receiving electric signals — to a full graphical user interface like on a modern computer. Quite often they will have a few push-buttons and a small display and some LEDs. A more complex system may have a touch screen, allowing the meaning of the buttons to change with each screen as in smart phones.

## Hardware

Hardware includes the chips, wires, circuit boards, buttons and displays.

### CPUs

The most important chip is the central processing unit or CPU.  This runs the software instructions. It can be a standard microprocessor or a microcontroller.  Microcontrollers include the microprocessor as well as simple peripheral equipment so the system can be smaller and cheaper.  They have less flexibility because those parts cannot be changed.  Usually these parts include Flash memory and support for serial ports, USB, etc.

Unlike a microprocessor for a general-purpose computer, bigger and faster is not always better.  Many embedded processors are very small.  Sometimes this is to use less space or less power, sometimes it is to be cheaper.  General-purpose computers will use microprocessors that read 32-bit or 64-bit words and run at speeds measured in GHz, but embedded processors are usually 4 to 32 bits and run at speeds usually measured in tens of MHz (a hundred times slower). (But the programs are also smaller and do not check for things that are not used).

### Ready made computer boards

There are _"ready-made"_ computer boards that can be used in some embedded systems. These often use Windows CE, Linux, NetBSD, or an embedded real-time operating system.

Sometimes it may be easier to use a circuit board that is already made.  These usually share many components with general purpose computers, but are smaller than one in a general purpose computer. Boards such as the VIA EPIA can run Microsoft Windows. The advantage is that it saves some electrical engineering time and can use the same software development tools used for PC-type software development. Examples of such embedded devices are the ATMs or displays in casinos.  This works well if the real-time requirements are not  strict (it doesn't matter much if a job takes eight seconds instead of five, for example).

### ASIC and FPGA solutions

If the device needs to be very small or will be sold in very big numbers (_"high-volume"_), it makes sense to make a custom or specialized chip that does exactly what is needed.  This is a system on a chip (SoC) which holds a complete system - processor, floating point unit, memory cache and interfaces on a single integrated circuit. SoCs can be made as a special-order application-specific integrated circuit or by using a field-programmable gate array which is programmed by the people building the embedded system.

### Peripherals

Embedded systems talk with the outside world or other components using peripherals such as:
- Serial Ports: RS-232, RS-422, RS-485.  This used to be quite common, with the 9-pin (or larger) connectors.
- Synchronous Serial Communication Interface: I²C Inter-Integrated Circuit, I²S Inter-Integrated Sound, SPI, MIcrowire, ...
- Universal Serial Bus (USB).
- Networks: Ethernet, Controller Area Network, LonWorks, ...
- Discrete Input/Output: General Purpose Input/Output.  This can be a single wire with an on/off signal.  It can be used for a small keypad, or to light an LED.
- Analog to Digital/Digital to Analog converters.  This measures something that changes in strength, like a light sensor or a motor control.
- Debugging: JTAG, ICSP port, for software engineers.

### Operating systems

Embedded systems often do not need a full operating system. Some use specially-built small and simple operating systems that start very quickly, others do not need one at all. Embedded systems are not adapted as easily, but they are built to perform their tasks much more reliably. Because the hardware is simpler, it is also often cheaper to build and runs faster.  In contrast to this, a general-purpose computer needs to be ready for new device drivers and software to run hardware it doesn't know about yet, like new printers or hard drive<nowiki/>s. It needs to run different application programs.

As embedded systems get bigger, things that used to be only on general-purpose computers or even mainframes are now becoming common on embedded systems. This includes protected memory space, and open programming environment including Linux, NetBSD, etc.

Some examples of operating systems, from simple to complex:
- Simple control loop - A timer and a loop is used to call different subroutines repeatedly.  This is often made by one person for smaller systems.
- interrupt controlled - The tasks are started by different kinds of events. The event could be something timed (every ten seconds, for example) or by a button press or data received.
- non-preemptive multitasking - Each task gets its turn to run, and when it finishes it calls a _scheduler_ in the OS to run the next task.
- preemptive multitasking or multi-threading - A task can be stopped after some amount of time to let another task run for a while.  No task can hog the system. At this level the system is considered to have an "operating system" kernel and can run tasks in parallel.  This type of OS is usually bought from a company that only works on embedded operating systems.

Real-time operating systems include products like MicroC/OS-II, Green Hills INTEGRITY, QNX or VxWorks.  Unlike MacOS or Windows 7, these operating systems are not known very well by most people.  But they are used in many places where time and safety is very important.  People use them every day and do not realise it.

Common examples of larger kernels are Embedded Linux and Windows CE.  Although these do not have the tight time limits needed for a strict real-time system, they are becoming more common, especially for more powerful devices such as Wireless Routers and GPS.  They allow re-use of code in the public domain for Device Drivers, Web Servers, Firewalls, and other code.  Software developers that are more comfortable writing applications for PCs will find this more familiar as well.  If needed, an FPGA or other special hardware can be used for things that do need tight time limits.

### Tools

Like other software, embedded system designers use compilers, assemblers, and debuggers to develop embedded system software. However, they may also use some more specific tools:

- For systems using digital signal processing, developers may use a math tools such as MATLAB, MathCad, or Mathematica.
- Custom compiler<nowiki/>s and linkers may be used to improve optimisation for the particular hardware.
- An embedded system may have its own special language or design tool, or add enhancements to an existing language like the one used by Basic Stamp.

Debugging tools:
- An in-circuit debugger, a hardware device that connects to the microprocessor via a JTAG interface. This starts and stops the microprocessor from outside as it runs  the software.  It also allows memory and registers to be read, and to store the software program in memory.
- External debugging using logging or serial port output to trace operation using either a flashing monitor (_printfs_).
- Interactive resident debugging - if the OS supports it, this is a shell on the embedded processor that runs commands typed by the developer (Linux, for example).
- An in-circuit emulator replaces the microprocessor on the board, providing full control over everything the microprocessor could do.
- A complete emulator simulates all the features of the hardware, allowing all of it to be controlled and modified.  The hardware doesn't really exist, but a pretend version of it (a _"virtual"_ machine) is on a normal PC.
- Checking external lines with a logic analyzer or multimeter.

Unless restricted to external debugging, the programmer can typically load and run software through the tools, view the code running in the processor, and start or stop its operation. The view of the code may be as assembly code or source-code.  Some integrated systems (like VxWorks or Green Hills) have special features, like keeping track of how much space the software takes as it runs, what tasks are running, and when things happen.

Depending on what kind of embedded system is being made will affect how it can be debugged.  For instance, debugging a single microprocessor system is different from debugging a system where processing is also done on a peripheral (DSP, FPGA, co-processor).

## Safety and Reliability

Embedded systems are often in machines that are expected to run for years without errors, and in some cases recover by themselves if an error occurs.  This means the software is usually developed and tested more carefully than that for personal computers, and unreliable mechanical moving parts such as disk drives and fans are avoided.

Places where safety and reliability are important:
- Some systems cannot safely be shut down for repair, or it is too difficult to repair. Examples include space systems (satellites, rovers), under-sea cables, and nuclear power plant controls.
- The system could kill people if it fails, such as aircraft controls, chemical factory controls, train signals, and heart defibrillators.
- The system will lose large amounts of money if it is shut down or if a mistake is made: Telephone switches, factory controls, cash registers, automated teller machines.

Ways to recover from errors — both software bugs such as memory leaks, and also soft errors in the hardware:

- Watchdog timer that restarts the embedded system if something stops working.
- Duplicate parts, where one system can take over if another one stops working.
- Software "limp modes" that provide partial function.
- Immunity Aware Programming

## Related pages

- Microprocessor
- Programming languages
- Firmware
- Real-time operating system

## References

- John Catsoulis, Designing Embedded Hardware, O'Reilly, May 2005, .
- Anoop MS, Security needs in embedded systems, Tata Elxsi, India, May 2008.

## Other websites

- The Embedded Systems Institute
- How a real time operating system works
- Embedded in Electronic Design
- Home of the _Embedded Systems Programming_ magazine
- Embedded System News