Maxim Kharchenko is the original author of LING, the alternative implementation of Erlang. Now he is a CTO at Cloudozer, the company that aims to build a better cloud solution using LING. In addition Cloudozer adapts LING/Erlang for MIPS MCUs and other embedded platforms.

Why remain in the 70s?

If there is an island of stability amid the white waters of programming, it is definitely the embedded sector. In this sector, the C programming language still plays the major role and many approaches have not changed over decades.

Back in the day, there was a clear reason to stick with these proven techniques, since embedded hardware was limited in the matters of power consumption, memory size, and CPU speed.

Time has flown by quickly, and we now have much more powerful hardware platforms entering the arena. This shifted the focus to areas where proven embedded technologies had never been considered. Rapid interactive development, extended integration abilities, introspection, hot code swapping – how could C be good enough for that?

An ideal programming language for embedded applications

Everybody knows there is no such thing as a silver bullet, especially in programming. Yet newly emerging hardware platforms urge embedded developers to seek more convenience from scripting languages and other technologies from the world of big software.

Surely, such nifty tools as Python or Lua simplify and speed up development, but there are technologies which fit embedded needs even better.

One of these is Erlang, a programming language and an associated runtime developed by Ericsson in the 90s.

Introducing Erlang

Surprisingly, Erlang was developed to implement firmware and nothing else. Erlang served as a basis for firmware development for AXD301, a switch that could serve all telephony needs of a small country back in 1998. From the very beginning, the language itself emerged as a Holy Grail for the embedded world.

A distributed, fault-tolerant, concurrent, garbage-collected programming language which supports soft real-time guarantees, code hot swapping, message passing, reactive programming, and introspection? All of these features sounded like music for many ears.

Erlang also looked like a natural choice for IoT since it can be used to write tons of highly-integrated, heavily maintained code for new powerful embedded platforms.

Making Erlang run on MIPS-based PIC32 MCUs

However, everything comes with strings attached. In the case of Erlang case it is the VM (virtual machine), which nobody can call small. There were a number of projects trying to adopt BEAM (the mainstream Erlang VM) for embedded applications. Their success was limited due to requirements imposed by the standard VM. One must be prepared to run it over Linux, to have a plenty of RAM, to provide lots of disk space and a conventional filesystem.

Such requirements did not fit most of the smaller microcontrollers, including the MIPS-based PIC32 microcontroller family from Microchip Technology.

dsPIC_DSC Block Diagram_Figure1Under the hood of the MIPS-based PIC32 microcontroller

Fortunately, oftentimes there are options. A small company Cloudozer LLP has developed an alternative Erlang implementation called LING. LING runs Erlang programs in the cloud over bare (virtual) metal. Being minimalistic and self-contained, LING can be easily ported to many architectures and environments. A few such efforts are under way: POSIX (Linux), ARM (Raspberry Pi), and now MIPS (PIC32).

To shrink the size of the LING virtual machine a few things were left out (e.g. regular expressions and cryptographic functions) which shrank the resulting image size to about 1M. This meant that LING consumed roughly 50% of Program RAM. The Data RAM was used for heaps of Erlang processes.

The demo program calculated a few prime numbers as seen on the screenshot.

Erlang on MIPS-based PIC32A demo program written using Erland running on a PIC32 MCU

What is next?

Of course, this was just the first step on a long road. The PIC32 port shows that smaller MCUs can run Erlang; the garbage-collected dynamic nature of the language may shorten the development cycle and improve reliability of embedded software with a tolerable impact on performance.

Cloudozer is currently working on a statically compiled version of LING (codenamed Project L) that does not require a virtual machine to run. The L compiler spits unikernels – applications compiled with an OS-like microkernel, which could be deployed on bare metal.

From the very beginning, Project L was intended to support MIPS architecture and the open-source version is expected to arrive in 2016.

Interested in the latest news and updates from Imagination? Make sure to follow us on Twitter (@ImaginationTech, @MIPSguru, @MIPSdev), LinkedIn, Facebook and Google+

About the author: Guest Blog

Profile photo of guestblog