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:

The article also notes a number of disadvantages: 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:

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:
  1. The Hardware abstraction layer provides an adaptation of the hardware to fit the OS.
  2. The Operating system layer provides an abstraction of the hardware, together with the traditional services of an operating system.
  3. The services layer: Usually the OS has to be adapted with some extra drivers, or some other functionality has to be added.
  4. 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:

The Python system comes with a number of add-on modules that add functionality to the system. These are:

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.

[[1]] Philip Koopman., "Embedded System Design Issues -- The Rest of the Story", Proceedings of the 1996 International Conference on Computer Design, Austin, October 7-9 1996, available as http://www.cs.cmu.edu/~koopman/iccd96/
[[2]] James Gosling, Bill Joy and Guy Steele, "The Java™ Language Specification", Addison-Wesley, 1996
[[3]] Graham  Prophet, "New Java variants target deeply embedded system", EDN Magazine Online, March 3 1999: http://www.ednmag.com/reg/1999/030499/05ecs.htm
[[4]] Richard A. Quinnell, "Java perks up embedded systems ", EDN Magazine Online, August 1997: http://www.ednmag.com/reg/1997/080197/16cs.htm
[[5]] The Python home page: http://www.python.org/
[[6]] Mark Lutz, "Programming Python", O'Reilly & Associates 1996.
[[7]] Sun's Community Source License Program: http://www.sun.com/software/communitysource/java2/
[[8]] Guido van Rossum, "Comparing Python to Other Languages", http://www.python.org/doc/essays/comparisons.html
[[9]] The DePython home page: http://www.abo.fi/~iporres/python/small.html
[[10]] The Sound Recorder Machine: http://www.abo.fi/~iporres/sr/hw.html