Deeply Embedded Python, a virtual machine for embedded systems
Johan Lilius and Iván Porres Paltor
1 Introduction
An embedded system is a computer-based system controlling a device that
interacts with the physical world. Mobile telephones or modern elevators
are examples of embedded systems.
Traditionally embedded systems have been programmed in assembler and
high-level languages like C or C++, to provide optimal implementations
in terms of cost and efficiency. However, if one considers the whole product
cycle then it is not at all clear that only optimising for single product
cost and efficiency will give the best revenue
(cf.[[1]]).
Indeed recently other issues such as portability, security, simplicity
and the ever-shorter time-to-market requirements have become increasingly
important concerns of the design cycle of an embedded system. This has
sparked interest in alternative solutions.
For embedded systems where most of the added value is in the user application,
while the hardware interface remains relatively stable,
Java*
[[2]] has been seen as an interesting
alternative. Recent articles in EDN [[3]
,[4]]
discuss its use as a viable programming language for embedded systems.
The articles identify a number of advantages of Java for embedded systems:
- portability,
- design reuse, and
- location independence of development
The article also notes a number of disadvantages:
- speed,
- to much memory is needed,
- no deterministic performance, due to garbage-collection, and
- no pointers.
In the DePython project we have tried to address some of these problems.
2 The DePython project
Python is an interpreted, object-oriented programming language developed
by Guido van Rossum[[5],
[6]].
Although Python is copyrighted, the source code is freely available, and
unlike GNU software, it can be commercially re-sold. This is distinct advantage
over Java whose community licence forbids selling and requires the user
to submit any changes back to SUN [[7]].
In the DePython (Deeply Embeddable Python) project we have created
a stripped-down version of Python that provides a platform for implementing
embedded systems in the Python language. Specifically the DePython
system provides the following advantages of Javatm:
- absolutely free, even for commercial use (including resale),
- small footprint (<200K)
- easy maintenance of software: objects and methods can be replaced ``on-the-fly''
- reference counting garbage-collection giving more deterministic performance
On the downside Python programs are in general expected to run slower that
Java programs. But according to Guido van Rossum [
[8]] Python programs are typically 3-5 times shorter that equivalent
Java programs. Especially Pythons powerful polymorphic list and dictionary
types, for which rich syntactic support is built straight into the language,
find a use in almost every Python program.
2.1 The architecture of DePython
The software of an embedded system is typically organised in a number of
layers:
- The Hardware abstraction layer provides an adaptation of the hardware to
fit the OS.
- The Operating system layer provides an abstraction of the hardware, together
with the traditional services of an operating system.
- The services layer: Usually the OS has to be adapted with some extra drivers,
or some other functionality has to be added.
- The final layer is the actual application.
Depending on the complexity of the system, either the Hardware layer, the
OS or the services layer (or all) may be missing in the application.
In many cases the layers 1-3 are very stable and the user application
layer is used to customise the system. An example of this are set-top boxes,
where the basic delivery system is the same, but each cable TV provider
requires their own user interface to the system. DePython is aimed at exactly
this kind of systems, where most of the added value is in the user application
layer.
The Python language is a bytecode-interpreted language that runs on
the Python virtual machine. The virtual machine executes the Python programs
on the target hardware. Any programming environment always includes a number
of dependencies on the target system. These can be classified as follows:
- Dependencies on particular processor, such as size of address space, FPU,
etc; for example: the Hitachi SH1 micro-controller does not have FPU.
- Dependencies on particular hardware, such as the I/O, for example: the
board we are running DePython on has a LCD screen, small keypad and two
RS-232 ports for I/O, while a SGI may have very complex graphics hardware.
- Dependencies on a particular operating system, such as threads, interrupts,
file system etc; in our case the SH1 evaluation board does not have an
operating system.
The Python system comes with a number of add-on modules that add functionality
to the system. These are:
- The extension modules (this includes things like support for regular expressions)
- The OS modules (this includes the file system, signalling, threading),
- The hardware modules (this includes support for specific hardware graphics)
and
- The command line interface.
In the DePython project we have isolated the Python VM, removed the dependencies
with the Operating System and designed a simple hardware wrapper layer
for interfacing to the SH1 evaluation board.
2.2 The Hardware
Currently DePython runs on a Hitachi SH1 evaluation board with some extra
hardware. The SH1 is a 32 bits RISC micro-controller running at 16Mhz.
T he evaluation is equipped with 256Kb of RAM, 64Kb of ROM, two RS-232
ports, and a number of I/O ports. We have added some extra hardware to
the board to make it more usable. The system now contains a 320x240 pixel,
16 grey level LCD panel together with a small numeric keyboard for character
and graphical I/O and 6 analogue input channels. We are
using the GNU ToolChain as our development tool. The VM can thus be ported
to any system with a GNU compiler.
2.3 Future plans
We have defined an architecture for extending the Python interpreter with
classes for devices. Next we plan to add an ethernet interface to the SH1
board and develop some embedded internet applications. Specifically we
are interested in the possibility to dynamically reconfigure the system
over the internet. We are also planning to add a real-time operating system
under the Python VM. This will allow real-time tasks to run with higher
priority than the non-real-time Python tasks.
3 More information
Version 0.1 of the system can be downloaded from
[[9]].
Also see [[10]] for more
details on the board that we are using for running DePython.
4 People
Most of the programming in the DePython project has been done by Raúl
Parra Bacete, and César López Sáenz in 1999.
5 References
* Java is a trademark
of Sun Microsystems, Inc.
[[2]] James
Gosling, Bill Joy and Guy Steele, "The Java™ Language Specification",
Addison-Wesley, 1996
[[6]] Mark Lutz, "Programming
Python", O'Reilly & Associates 1996.