Networks
While I use the C programming language throughout this thesis, others have investigated the use of new programming languages and programming models for programming memory-constrained networked embedded systems.
4.3.1
Macro-programming and New Programming Lan-
guages
Research in the area of software development for sensor networks has led to a number of new abstractions that aim at simplifying the programming of sensor networks [4, 13]. Approaches with the same goal include macro-programming of aggregates of sensor nodes [19, 24, 56, 68], high-level database abstractions of sensor networks [47], and network neighborhood abstractions [54, 68, 71]. The work in this thesis differs from these sensor network programming abstrac- tions in that I target the difficulty of low-level event-driven programming of individual sensor nodes, programming-in-the-small, rather than the difficulty of developing application software for sensor networks, programming-in-the- large.
Kasten and R¨omer [36] have also identified the need for new abstractions for managing the complexity of event-triggered state machine programming. They introduce OSM, a state machine programming model based on Harel’s StateCharts[27] and use the Esterel language. The model reduces both the complexity of the implementations and the memory usage. Their work is dif- ferent from protothreads in that they help programmers manage explicit state machines, whereas protothreads are designed to reduce the number of explicit state machines. Furthermore, OSM requires support from an external OSM
4.3 Programming Models for Wireless Sensor Networks 25
compiler to produce the resulting C code, whereas the prototype implementa- tions of protothreads only make use of the regular C preprocessor.
Script languages are another alternative for programming embedded sys- tems. Script languages do not need special compilers as the script code is interpreted by the embedded systems. However, existing structured script lan- guages are typically too large for the memory-constraints considered in this thesis. The SensorWare system [12] uses a reduced version of Tcl to provide a script-based programming environment for sensor networks. However, the system is designed for sensor nodes with an order of magnitude more memory resources than the systems considered in this thesis; for example, the Sensor- Ware system occupies 180 kilobytes of memory.
Rappit [25] is a development framework for scripting languages for em- bedded systems. Rappit uses a host environment running Python that sends commands to the embedded systems. The host environment runs on a resource- rich server system outside of the sensor network that translates commands into simpler messages that are executed by the embedded system. Tapper [72] is a command language and lightweight stack-based script engine for sensor nodes built with Rappit. The Tapper language provides primitives for accessing hard- ware devices such as analog to digital converters and for sending and receiving radio packets. Both Rappit and Tapper require assistance from a host system for interpreting the commands.
4.3.2
Virtual Machines
Virtual machines have been investigated for sensor networks as an approach to reduce the distribution energy costs for software updates. The code size of the programs running on top of the virtual machine can be kept to a minimum since the virtual machine can be tailored to the needs of an application for a specific domain such as sensor networks. The drawback of virtual machines is the increased execution overhead over native code. The virtual machine approach is different from the approach taken in this thesis as virtual machines need both special compilers that can produce code for the virtual machine as well as a virtual machine running on the embedded system.
Mat´e [42] was the first virtual machine specifically targeted to wireless sen- sor networks. Mat´e is a stack-based virtual machine that runs on top of TinyOS. Mat´e instructions are 8 bits wide. Each virtual machine instruction is executed in a separate TinyOS run-to-completion task. Levis et al. [43] have further in- vestigated the use of application specific virtual machines (ASVMs) that are compiled for the needs of a particular application or set of applications. Other
26 Chapter 4. Related Work
examples of stack-based virtual machines for sensor networks are DVM [7] and my CVM Contiki virtual machine (Paper E). There are also Java-based virtual machines for sensor networks apart from the Java VM in Paper E, such as the VM⋆system [38].
Chapter 5
Conclusions and Future
Work
5.1
Conclusions
In this thesis I investigate three aspects of programming memory-constrained networked embedded systems: the use of the TCP/IP protocol stack for memory-constrained systems; the novel protothread programming abstraction for state machine-based programs for event-driven systems; and the use of dy- namic loading and linking of native code in an operating system for memory- constrained embedded systems. A general theme throughout this work is how applicable standard or general-purpose mechanisms and methods are to memory-constrained systems. I have identified and quantified trade-offs in both the use of general-purpose mechanisms for memory-constrained systems and the use of a general-purpose programming language for reducing the com- plexity of memory-efficient programming for memory-constrained systems.
In this thesis I show that the standard TCP/IP protocol stack can be im- plemented efficiently enough to be usable even in memory-constrained sys- tems, but that such an implementation leads to a significant decrease in net- work throughput. Furthermore, the results show that protothreads reduces the complexity of state machine-based event-driven programs, while having a very small memory and run-time overhead. Finally, the Contiki operating system shows that dynamic loading and run-time dynamic linking of native code is a feasible mechanism for memory-constrained networked embedded systems.
28 Chapter 5. Conclusions and Future Work
There are at least two conclusions that can be drawn from my research. First, in many cases it is possible to use standard protocols and mechanisms developed for general-purpose computers even in memory-constrained embed- ded systems. However, there are trade-offs in terms of both memory footprint and energy. Second, protothreads show that it is possible to combine features from multi-threading and event-driven programming; sequential programming from the multi-threaded model and a small memory overhead from the event- driven model. Since a slightly limited version of protothreads can be imple- mented in the general-purpose C programming language, it is possible to do memory-efficient sequential programming in C without requiring the use of a special-purpose programming language. However, there are trade-off due to the limitations of the C-based implementation of protothreads.