April
1998, Issue 93
Software
Development for RTOSs
REAL-TIME
PROGRAMMING LANGUAGES
The
most common is development language for real-time PC
development is C. As you likely already know, C was
developed originally to implement Unix in a portable
way and has now been around for quite some time.
C
has been a favorite with embedded-systems developers,
too. While not as efficient as coding in assembler language,
C is portable and enables the programmer to access memory
and I/O port resources.
C
compilers exist for almost any microprocessor architecture
from supercomputer architectures like Cray, and 64-
and 32-bit processors, like Pentium and PowerPC, all
the way down to PIC processors. Well, OK, I havent
seen a C compiler for a DEC PDP-8.
While
its possible to use assembly language in all PC-based
RTOSs, it is probably wise to avoid coding in assembly
unless absolutely necessary. Most modern C compilers
are good at optimizing code for particular architectures
(i.e., i486 vs. Pentium).
It
is almost never necessary to code in assembly language
for speed. Besides, unless your application is very
high volume, the increased time and costs associated
with developing in using assembly are almost always
higher than just going with a faster processor.
For
example, it may take 80% of the development effort to
squeeze that last 20% of speed from an application by
coding up critical routines in assembly language and
hand-optimizing them. Speed increases achieved by using
a faster CPU and bigger faster cache architecture are
usually cheaper.
About
the only time you want to code in assembly, is when
youd like to implement low-latency interrupt service
routines, or stubs for ISRs, which allow setting up
the environment necessary to call C routines. Luckily,
many RTOS vendors have done a good job providing these
stubs as part of their API.
C++
has been popular in desktop systems for quite some time
now and is starting to become more popular in embedded
systems. While there is nothing magic about using C++,
tool support for C++ in development systems for RTOS
has been slow in coming. However, currently many RTOS
vendors have tool and library support for C++.
However,
just because you code your applications in C++ doesnt
mean youre necessarily using object-oriented programming
(OOP) methodology. But, OOP isnt simply a methodology.
You can also do OOP in C or assembly language. C++ is
just a tool.
Another
OOP language you may have heard getting a lot of press
lately is Java. Java was developed by Sun Microsystems
as a new network programming technology.
The
idea here is to use the Java programming language to
develop code, which gets compiled into byte code to
be executed in an interpreter on a target systems. It
promises architecture-independent application development.
Several
RTOS vendors offer Java support, but there are still
some issues to be worked out. In particular, the Java
run time relies on garbage collection, which in its
current reference implementation from Sun is nondeterministic
and thus not suitable for hard real-time applications.
Work is being done on this, but more about Java in a
later column.
Fortran
is still used in embedded systems. In particular, there
are numerical libraries which are coded in Fortran.
These libraries represent much time in development,
testing, and tuning.
Since
its harder to find a Fortran compiler that can
be hosted on current development platforms, some libraries
are being converted to C. One solution is to use Fortran-to-C
converters, which you can find on the Internet.
Unless
you code for the government or systems that need to
be flight qualified, you probably wont see ADA.
ADA is a good for implementing large systems where many
developers are working in different organizations, but
its sometimes difficult to use for expressing
real-time issues.
Thats
not to say that there arent some RTOSs for embedded
systems which are written in Ada. For example, RTEMS,
which is developed by the US Army and distributed for
free, is available in Ada or C source.
Also,
theres trend towards using high-level behavioral
modeling language for systems. In these systems, the
modeling language describes what the system components
do. Typically, hardware components modeled in these
systems are then synthesized into hardware-description
languages like VHDL or Verilog, and software components
with languages like in Ada or C, which are then compiled
using standard compilers.