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 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:
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. 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.
|