You are on page 1of 11

Embedded Software

Ingo Sander

Embedded Real-Time Software


Developing correct embedded real-time

software is efficiently is a very challenging
David B. Stewart [Ste99a, Ste99b] states that

the same mistakes are repeated over and over

most real-time software developers are not aware
that some of the methods they use are

IL2212 Embedded Software

Embedded Real-Time Software


Stewart lists 30 pitfalls and claims that

correcting just one of them can lead to

weeks or months in saving of manpower

significant increase in robustness and quality

For each problem

misconception or source of problem is presented

possible solution is presented

IL2212 Embedded Software

Embedded Real-Time Software


Remember that the later a design error is

detected in the design flow, the more
expensive it is to correct the error

When the product is shipped to the customer, not

only correcting the error is expensive, but also the
company will lose a lot of its reputation

IL2212 Embedded Software

Some Pitfalls

#26 Interactive and incomplete tests

Tests require often user input

Many tests test only changes in the program and
not the entire program
Tests should be automated and should test the
entire system

IL2212 Embedded Software

Some Pitfalls

#22 No analysis of hardware peculiarities before

starting the software design

Software designers do not analyze the characteristics

of the underlying hardware

Does it take more time to add two 32-bit numbers than two 16
bit numbers?
How much time does it take to add two floats, integer and

Capabilities and limitations of target processor(s) have

to be understood!
IL2212 Embedded Software

Some Pitfalls

#17 I dont have time to take a break

Many programmers continue to write code

although they are tired or exhausted

Inefficient use of working time

Lack of concentration can cause new bugs

Be disciplined, when you do not make progress,

take a break to refresh your mind

IL2212 Embedded Software

Some Pitfalls

#14 Only a single design diagram

Many software systems are designed by a single

or no diagram

There are diagrams for different purposes of the

A good diagram properly reflects the ideas of the

IL2212 Embedded Software

Some Pitfalls

#11 Error detection and handling are an afterthought and

implemented through trial and error

Software design focuses mainly on normal operation (assuming

the absence of errors)
Exception and error handling are added after finalizing the
Maintenance of system becomes a nightmare

Error detection and error handling need to be incorporated from

the start

IL2212 Embedded Software

Some Pitfalls

#10 No memory analysis

Even in embedded systems many programmers

have no idea what the memory implications are
for any of their designs

Performance depends very much on efficient use of

Caches or on-chip memory are significantly faster then
external SDRAM

Memory accesses should be analyzed

IL2212 Embedded Software


Some Pitfalls

#8 The first right answer is the only answer

Getting an embedded system or peripheral to

work is difficult and often frustrating
Thus many programmers will never change a
working code, although it might be very poor

significant maintenance costs

Recheck your working code and improve it, if it is

poorly designed
IL2212 Embedded Software


Some Pitfalls

#6 Documentation was written after


General rule in most projects

significant increase in maintenance costs

Documentation should be written before and

during coding
If documentation is not correct, revise document
before you change the code
IL2212 Embedded Software


Some Pitfalls

#5 No code reviews

Many programmers do not want to show their

code to colleagues

messy code is not improved

Formal code reviews ensure robustness and will

detect bugs and sources for bugs efficiently

IL2212 Embedded Software


Some Pitfalls

#4 Indiscriminate use of Interrupts

Interrupt handlers are often overloaded with code and even make
I/O requests
Interrupt handlers reduce the schedulable time for normal
periodic tasks
Interrupts are very difficult to debug
Minimize the use of interrupts
Interrupt handler shall be short and shall only be used to signal
another task that a specific event has occurred
Take interrupt overhead into account

IL2212 Embedded Software


Some Pitfalls

#3 Using global variables

Global variables are shared automatically between all processes,

since an RTOS usually are implemented as lightweight
processes and share the same address space
Problems with race conditions can occur
To prevent race conditions semaphores are often used, but they
can create priority inversion
Try to avoid global variables or use them very carefully

IL2212 Embedded Software


Some Pitfalls

#2 No naming and style convention

If no convention for a project is introduced, each

programmer will have its own way to write

Code review will take considerable time and it may be

much more difficult to detect bugs
Systems are designed by several programmers, which
share code with each other

Introduce naming and style convention

IL2212 Embedded Software


Some Pitfalls

#1 No measurements of execution time

Many programmers have no idea of the execution

time of their code
Easy to introduce synchronization errors in parallel
Measure execution time for processes and interrupt
Incremental measuring:

Measure each line of code, each loop, each function,

IL2212 Embedded Software


What do we learn from this?

There are many pitfalls in Embedded Real-Time

Software development

Stewart listed 30, but I am sure there are more

C as a language is dangerous (The Top 10 Ways to get

screwed by the C programming language)
The role of communication and the risk for race conditions will
increase, since systems will consist of more components

Be aware of the possible problems and try to

develop your programs and systems using
methodology that ensures high quality
IL2212 Embedded Software


This is important

since the number of embedded systems is

increasing and in many systems can safe life
but also cost life, if not designed properly
You do not want to be listed in the following

Software Horror Stories

Thus keep in mind that you have a large

responsibility as embedded software
IL2212 Embedded Software


Read Further

[Ste99a] David B. Stewart, 30 Pitfalls for

Real-Time Software Developers, Part 1,
Embedded Systems Programming, October,
[Ste99a] David B. Stewart, More Pitfalls for
Real-Time Software Developers, Embedded
Systems Programming, November, 1999.

IL2212 Embedded Software


IL2212 Embedded Software