Adam Dunkels on Embedded Sensor Networks 31
tl writes "netzstaub has
posted an
extensive interview with Adam
Dunkels, a computer scientist working in the field of wireless sensor networks and author of the open source lwIP and uIP embedded TCP/IP stacks,
the Contiki OS, and
the Protothreads library. The interview touches on protothreads, sensor networks, TCP/IP, Contiki, and embedded software
development. Many Slashdot readers probably remember the tiny Contiki OS from
previous
articles
where, not surprisingly, clustering
has
been
discussed.
From reading the interview, it seems Contiki clusters now have come
true."
Article tesxt (Score:3, Informative)
I discovered Protothreads through a link in Chris Double's weblog on Saturday. This is a fascinating tiny library, written by Adam Dunkels, a researcher at the Swedish Insitute of Computer Science. The Protothreads library implements user-level in threads in portable ANSI C in a mere 20 lines of code, and each thread uses only 2 bytes of RAM! While having a few important limitations, this comes in handy for a lot of problems, especially when writing single-threaded network servers (using Protothreads, you don't have to use state machines to do protocol handling). While checking out Protothreads, I stumbled across the very interesting link list that Adam Dunkels compiled while writing his library. From there, I got hooked and browsed the rest of Adam's website.
He has written two incredible TCP/IP stacks aimed at embedded systems. The first one, uIP, is targeted at 8bit microcontrollers, and has a very low RAM usage (it runs with as few as 128 bytes RAM for full TCP/IP support). The development version of uIP uses Protothreads to offer a BSD-style socket interface while maintaining its low RAM usage. The second stack, lwIP, is targeted at bigger embedded systems, and offers a BSD-style API.
Adam is a computer scientist working in the field of sensor networks, which are a part of the research field of ubiquitous computing. Sensor networks consist of a myriad of little embedded systems gathering environmental data through a set of sensors. However, the real value of sensor networks stems from the communication between all these systems. As Adam put it, "the nodes are interchangeable: it is the data generated by the sensors that are the primary interest". Besides uIP, which he uses as a mean to communicate between the sensor nodes, Adam works on Contiki, an embedded operating system. Contiki allows the dynamic loading of code on sensor nodes, which proves to be very useful when deploying sensor networks.
I emailed Adam a few questions about his software, embedded programming and sensor networks. He was very kind to provide exhaustive and very interesting answers. Enjoy the interview
Protothreads
These first three questions are about Protothreads, the minimal threading library Adam has written for his embedded platforms. Protothreads are inspired by coroutines, which can be sort of implemented in C using a neat little trick.
Question: Adam, what was your motivation to write protothreads?
Answer: The driver behind the development of protothreads was many years of writing event-driven code. After a while, one sees the need to have a nicer abstraction than finite state machines. Ordinary threads have many of the good properties of such an abstraction, but they have two problems: the RAM overhead is prohibitive on systems with very small memory resources ---the typical target system for uIP---, and they require a fair amount of platform specific code. As I wanted to keep both uIP and Contiki as portable as possible, this was definitely a problem.
After thinking long and hard about this, as well as reading lot of papers on the subject of concurrency, the protothreads concept dawned on me. Very simple, yet powerful. Very little RAM overhead and possible to
implement in pure C. Perhaps the nicest thing is the extremely small size of the implementation. With all comments removed, the entire library can be reduced to 20 lines of code (that goes into a header file, no less!).
Question: What kind of software uses Protothreads currently?
Answer: Currently, the Contiki OS and the development version of the uIP TCP/IP stack are using protothreads. Among other things, they are used to implement a network API called "protosockets", which are similar to the BSD socket API but based on protothreads. This means that they can be used without underlying full multithreading, which subsequently means less RAM overhead.
Question: What kind of software do you think will use Protothreads in the future?
Answer: I
Slashdotted already (Score:2, Informative)
Read the coroutine article (Score:4, Informative)
http://www.chiark.greenend.org.uk/~sgtatha
It is nice for a change to read about an "ugly trick" which is used to increase readability!
Re:Protothreads source? (Score:1, Informative)
Re:Protothreads source? (Score:3, Informative)