Вы находитесь на странице: 1из 2

Virtual Machines Running on Microcontrollers http://dev.emcelettronica.

com/print/51717

Your Electronics Open Source


(http://dev.emcelettronica.com)
Home > Blog > allankliu's blog > Content

Virtual Machines Running on


Microcontrollers
By allankliu
Created 04/04/2008 - 03:55

BLOG Electronics

A lot of users have experiences of using a virtual machine. These VMs are quite useful for
developers who have to work on multiple OS platforms. There are many VMs running on
embedded microcontrollers, too. These embedded VMs are dedicated for a specific purpose.
A lot of embedded applications leverage them to reduce system complexity, memory
footprint, and deploy the custom design quickly. It sounds incorrect, since running VM
requires extra resources of embedded microcontroller, and demands extra programming
skills, either. However embedded VM indeed can help developers to achieve those goals.

Pcode from PicoWeb

Let us check out an open source project, PicoWeb from


Lighter Engineering. It is an embedded Ethernet project,
running on an AVR microcontroller with a Realtek Ethernet
NIC. Several years ago, embedded connectivity was very
popular, since network connectivity is an enabling technology
for the era of Internet. PicoWeb is one of them, who
developed a small version of TCP/IP stack and an embedded
server running on microcontrollers. I have to say these guys
[1] are brilliant. But PicoWeb is more attractive among these

projects. Because I found that all the custom contents, not only the HTML pages, but also the
CGI scripts, are stored in the EEPROM and running on a VM. Before I knew it, I used to think
each embedded server should be programmed individually for its own task, and the code and
content had to be reprogrammed as soon as the requirement changed. Thanks to the VM
technology, the HTML/CGI can be stored in internal or external EEPROM; the firmware in
microcontroller is identical for all embedded servers. This approach dramatically reduces the
custom change requirement, code size and simplifies the runtime program structure,
compared to the native code..

Pcode, as the VM of PicoWeb, is a binary VM. The concept is as same as Java. A developer
can write the code with Pcode pseudo code, compile it into final binary Pcode. Then the
binary Pcode is downloaded to EEPROM, a Pcode VM interpreter will read the Pcode in the
EEPROM and run it. Of course you can argue with me that VM approach will bring more
complexity for extra VM runtime and complier support. Yes, indeed. But it is worthy. Let us
browse the Pcode instructions, you will find a lot of regular low-level instructions (i.e. MOV,
XOR, OR, NOT, CLR and JMP) as well as some high level application-specific instructions.
Since Pcode is designed for an embedded server, it has following application-specific high
level instructions:

1 din 2 01.05.2008 15:48


Virtual Machines Running on Microcontrollers http://dev.emcelettronica.com/print/51717

ps2ee:Copy SRAM to EEPROM,


ps2see: Copy SRAM to External EEPROM,
pwreebi: Write Byte to EEPROM,
pcrlf: Print CR,LF
psgetcto: Get Serial port character with timeout
pprintse: Print serial EEPROM string of length of n
poksetip: Check if "set IP" operation allowed
purl2int: Convert characters in URL line to 16bit integer
ps2x: Move bytes from memory to Ethernet transmit buffer
and more instructions are listed in the http://www.picoweb.net/download/pw1_pcode.pdf
[2]

Then we can conclude how and why this approach reduces the system software complexity
and reduce the code size. Inside the microcontroller, we can only put a real-time kernel,
drivers, and a Pcode runtime engine. A lot of application specific native codes are abstracted
and re-programmed in Pcode instructions, which are stored in external EEPROM.
Additionally, the developer can even hide its core competency inside the microcontroller with
the approach, while offers change flexibility in external EEPROM as well. For more
information about PicoWeb, please visit www.picoweb.com [3]. Some other electronics
designs can benefit from this idea, such as UI custom design, PLC, and any applications
need custom design.

Of course, there are many similar projects, either legacy or state-of-art technologies.

Sun's JavaCard, Java VM runtime, custom applications are written in Java, downloaded
and running on Smartcards. Embedded Java is a hot topic as well. You can easily find
open source projects for Java.http://java.sun.com/products/javacard/ [4]
Intel's BASIC interpreter. The project is quite old, but I still keep the code. If any
developer is interested in it, he has to port it to existing platform, since the original
version was designed for running in an external SRAM. And developer must understand
8051 assembly code very well, because all of the codes are developed by 8051
assembly. Intel's approach is different from PicoWeb’s, the user BASIC code must be in
the form of source code, the BASIC VM parses the source code and starts to interpret
and run.
BASIC Stamp from Parallax, a commercial BASIC interpreter for educational, robotics.
http://www.parallax.com/ [5]
nesC of TinyOS, an alternative runtime for sensor networking. http://www.tinyos.net/ [6]

Trademarks

Source URL: http://dev.emcelettronica.com/virtual-machines-running-microcontrollers

Links:
[1] http://www.picoweb.net/
[2] http://www.picoweb.net/download/pw1_pcode.pdf
[3] http://www.picoweb.com
[4] http://java.sun.com/products/javacard/
[5] http://www.parallax.com/
[6] http://www.tinyos.net/

2 din 2 01.05.2008 15:48

Вам также может понравиться