Vous êtes sur la page 1sur 6

Introduction to Embedded Systems Part I

Shibu K V









C++ & Java for Embedded
Development
























E EE E
M MM M
B BB B
E EE E
D DD D
D DD D
E EE E
D DD D

P PP P
R RR R
O OO O
G GG G
R RR R
A AA A
M MM M
M MM M
I II I
N NN N
G GG G

Introduction to Embedded Systems Part I

Shibu K V

C++ for Embedded Development

The programming language C is considered as the most popular choice for embedded
development for various reasons like, rich compiler/cross-compiler support, rich support for
system level programming, code efficiency, performance etc. When it comes to the desktop
application development C++ is considered as a good candidate for object oriented
development. Though C++ is a popular choice for object oriented programming in desktop
environment, when it comes to embedded application development C++ is not able to gain
much attention due to various reasons like, large memory footprint of compiled code,
performance bottlenecks etc. However it is very interesting to note that certain language
specific features offered by C++, like operator overloading, Object Oriented concepts,
exception handling mechanism etc can be effectively utilized in the embedded programming
arena.

The concept of Embedded C++ (The C++ version for embedded development) is introduced
by the Embedded C++ Technical Committee, a consortium of Japanese companies. Please
visit the website http://www.caravan.net/ec2plus for more details on the EC++ technical
committee and the EC++ standards. Embedded C++ is a subset of the full draft standard C++
language. EC++ implements only the relevant concepts from standard C++ and omits the
concepts and language specific features which are not relevant in embedded programming.
The compiler/cross-compiler for EC++ needs to be designed properly to handle these
changes.

The full draft standard C++ language features like multiple inheritance, virtual base class,
Run time Type identification, exception handling, templates, namespace etc are not essential
and relevant features when comes to conventional embedded programming for non OS based
embedded systems. Use of these features may increase the compiled code size, poor
execution speed etc which are not acceptable for embedded applications. The full draft
standard C++ library also needs to be tailored for embedded C++ for stripping down the
features which are not relevant.

The full draft standard C++ language has certain novel language specific features which can
implement certain requirements with fewer lines of code and a clean syntax when compared
to C language for conventional non-OS based embedded programming. The C++ concept of
class can effectively implement the allocation of memory for multiple types of variables;
their initialization etc which when implemented using C language requires more lines of
code. The C++ concept of operator overloading brings the idea of user defined meaning for
standard operators like =, <, >, + etc. in embedded application development.

The (cross) compilers for EC++ are different from the normal compilers for standard C++
language. Green Hills Software, Metrowerks, Hiware etc are some of the companies offering
compilers for EC++ based application development.

When it comes to the development for Embedded Operating System (GPOS/RTOS) based
products, standard C++ is a good candidate for implementing application features which are
closely aligning with Object Oriented architecture. Object Oriented device drivers are typical
examples for it. The C++ concept of classes and member functions can be used for the
effective modeling of the hardware.

Introduction to Embedded Systems Part I

Shibu K V

Java for Embedded Development

Java being considered as the popular language for enterprise applications due to its platform
independent implementations, but when it comes to embedded application development
(firmware and software), it is not so popular due to its inherent shortcomings in real time
system development support. In a basic java development, the java code is compiled by a
java class compiler to platform independent code called java bytecode. The java bytecode is
converted into processor specific object code by a utility called Java Virtual Machine (JVM).
JVM abstracts the processor dependency from Java applications. JVM performs the operation
of converting the bytecode into the processor specific machine code implementations. During
run time, the bytecode is interpreted by the JVM for execution. The interpretation technique
makes java applications slower than the other (cross) compiled applications. JVM can be
implemented as either a piece of software code or hardware unit. Nowadays processors are
providing built-in support for java bytecode execution. The ARM processor implements
hardware JVM called jazelle for supporting java. The figure given below illustrates the
implementation of Java applications in an embedded device with Operating System.

Embedded Hardware
Embedded OS (RTOS/GPOS)
Java Applications
Java Virtual Machine (JVM)


Figure: Java based embedded application development

As mentioned earlier, JVM interprets the bytecode and thereby greatly affects the speed of
execution. Another technique called Just In Time (JIT) compiler speeds up the java program
execution by caching all the previously interpreted bytecode. This avoids the delay in
interpreting a bytecode which was already interpreted earlier.

The limitations of standard Java in embedded application development are:

1. The interpreted version of Java is quite slower and is not meeting the real time
requirement demanding by most embedded systems (For Real Time Applications)
2. The garbage collector of Java is non-deterministic in execution behavior. It is not
acceptable for a hard real time system.
3. Processors which dont have a built-in JVM support or an off the shelf software JVM,
require the JVM ported for the processor architecture.
4. The resource access (Hardware registers, memory etc) supported by Java is limited
5. The runtime memory requirement for JVM and Java class libraries or JIT is a bit high
and embedded systems which are constrained on memory cannot afford this.

Some movements to overcome these limitations is in the process and lot of novel ideas are
emerging out to make java suitable for embedded applications. The Ahead-of Time (AOT)
compilers for Java is intended for converting the java bytecodes to target processor specific

Introduction to Embedded Systems Part I

Shibu K V

assembly code during compile time. It eliminates the need for a JVM/JIT for executing java
code. However there should be a piece of code for implementing the garbage collection in
place of JVM/JIT. AOT compiler also brings the advantage of linking the compiled bytecode
with other modules developed in languages like C/C++ and Assembly.

Java provides an interface named Java Native Interface (JNI), which can be used for invoking
the functions written in other languages like C and Assembly. The JNI feature of java can
be explored for implementing system software like, user mode device drivers which has
access to the JVM. Since JVM runs on top of the OS, device drivers which are statically
linked with the OS kernel during OS image building or drivers which are loaded as shared
object cannot be implemented using Java. In the Java based drivers, the low level hardware
access is implemented in native languages like C.

The Java Community Process within the Safety Critical Java Technology expert group has
come up with a real-time version for the JVM which is capable of providing comparable
execution speed with C and also with predictable latency and reduced memory footprint.

Java Platform Micro Edition (Java ME), which was known as J2ME earlier, is a customized
Java version specifically designed for Embedded application software development for
devices like mobile phones, PDAs, Set Top Boxes, printers etc. Java ME applications are
portable across devices. Java ME provides flexible User Interface (UI), built-in network
protocols, security etc. Sun Microsystems has also released an embedded version of the Java
Standard Edition (Java SE) with optimized memory footprint requirements for Embedded
application software development. The Embedded edition of the Java SE supports multicore
processors.

Java Micro Edition (Java ME) for embedded software application Development

Java ME is a collection of technologies and specifications for building a platform which
provides a complete Java run time environment for meeting the requirements of embedded
device like, mobile phone devices, IP Phone handsets, consumer and office automation
products etc. Java Platform, Micro Edition (Java ME/JME) provides a robust, flexible
environment for applications development for embedded devices like mobile phones,
Personal Digital Assistants (PDAs), Set Top Boxes, printers etc. Java ME includes flexible
user interfaces, robust security, built-in network protocols, and support for networked and
offline applications that can be downloaded dynamically. Applications based on Java ME are
portable across many devices, yet leverage each device's native capabilities. The figure
shown below illustrates the major elements of Java ME technology.










The Java ME Technology
Profile
(MIDP, Foundation Profile etc)
Configuration
(CLDC, CDC etc)
Optional Packages
(3D API, Mobile Media API etc)


Introduction to Embedded Systems Part I

Shibu K V

Configuration:
It contains the most basic set of libraries and a Java Virtual Machine (JVM) supporting a
broad range of devices. Connected Devices Configuration (CDC) and Connected Limited
Devices Configuration (CLDC) are the two common configurations supported by Java ME.
CDC is targeted for high end embedded devices with more memory capacity. CDC supports
the feature sets for a broad range of embedded devices. CLDC is a specially designed version
of CDC for embedded devices with resource constraints like low memory, processing and
graphical capabilities.

Profile:
Profile is the specifications from Java ME which defines a set of high level Application
Programming Interfaces (APIs) for application development. The Mobile Information Device
Profile (MIDP) is a typical example for a profile supported by Java ME. The profile in
combination with the Configuration gives a complete Java application environment for an
embedded device.

Optional Packages:
The Optional Packages is a set of technology specific Application Programming Interfaces
(APIs) which can be used with a specific category of devices. The optional packages extend
the functionality of a java application environment. 3D graphics APIs, Mobile multimedia
APIs, Wireless Messaging APIs etc are examples of Optional Packages.

A Java ME Application environment contains a configuration, which can be a CDC or a
CLDC depending on the capabilities of the embedded device, a profile which specifies the
standard set of APIs and a set of Optional Packages. As a typical example a Java ME
powered mobile device contains a CLDC configuration, a Mobile Internet Device Profile
(MIDP), and a set of Optional packages like Mobile Media API. The following figure
illustrates the same.



Optional Packages
(Mobile Media API, Wireless
Messaging API etc)

Mobile Information
Device Profile (MIDP)


CLDC


Embedded Operating
System
(E.g. Symbian)
Mobile Handset


The Java ME enabled Mobile Handset

Introduction to Embedded Systems Part I

Shibu K V

CLDC and MIDP provide standardized Java run time environment and exposes a rich set of
APIs. Application developers can make use of these APIs to develop a variety of applications
like Gaming, Business functions etc. The applications like, games, business applications,
other mobile applications etc developed by a Java ME developer using CLDC and MIDP is
known as MIDlets. MIDlets are Develop once and deploy on any device conforming to the
specifications supported CLDC and MIDP for Java ME.

The Java ME applications developed for CDC configuration are commonly known as Xlets.

References:
Java ME at a Glance
http://java.sun.com/javame/index.jsp
Java Documentation
http://www.forum.nokia.com/Resources_and_Information/Documentation/Java/