A State-Based Programming Model for Wireless Sensor Networks
A State-Based Programming Model for Wireless Sensor Networks
A State-Based Programming Model for Wireless Sensor Networks
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
6.2. OSM Language Mapping 113<br />
Esterel-Code Generation from OSM<br />
The exact details of mapping OSM to Esterel are only of secondary importance.<br />
There<strong>for</strong>e, and due to space constraints, we will present the mapping by example<br />
only. Appendix A.1 shows the OSM program PROG_PAR depicted in<br />
Fig. 6.2, its mapping to Esterel, and the C code generated by the Esterel compiler.<br />
The program is a parallel composition of the OSM state machines presented<br />
in Programs 6.1 and 6.2. It has 10 states and contains most features of<br />
OSM. Table 6.1 compares the sizes (in terms of lines of code) of the original OSM<br />
implementation and the generated C and Esterel mapping code.<br />
Compilation<br />
Unit<br />
# Lines Comment<br />
test.osm 49 original OSM implementation<br />
test.h 80 variable mapping (C)<br />
test.strl 307 control structure mapping (Esterel)<br />
test.c 616 control structure mapping (C)<br />
Table 6.1: Number of lines of code <strong>for</strong> an OSM program and its mappings in C<br />
and Esterel.<br />
In this section we demonstrate that the event-driven code generated by OSM<br />
does not introduce unacceptable overhead. To this end, we analyze the variable<br />
memory and code size of OSM programs. As described previously, the OSM<br />
code is first translated into Esterel code, from which C code is generated. There<strong>for</strong>e<br />
we analyze the object code generated from C code by a C compiler. Since<br />
our target plat<strong>for</strong>m is the BTnode, we compile <strong>for</strong> the Atmel AVR 128 microcontroller,<br />
the BTnode’s CPU. The compiler used is GCC <strong>for</strong> AVR (avr-gcc), version<br />
3.4.3.<br />
We start by analyzing the Programs 6.1 and 6.2 from the last section. Using<br />
these programs as base modules, we the build more complex programs by sequential<br />
and parallel composition.<br />
C-Code Generation from Esterel<br />
The Esterel compiler has several code generation modes and target languages.<br />
We use ANSI C in the sorted equations mode. The original C output of the<br />
Esterel compiler <strong>for</strong> program P ROG_P AR depicted in Fig. 6.2 is shown in Appendix<br />
A.4.1. The state transition function basically compiles into a long list of<br />
boolean equations that operate on a large amount of boolean variables. These<br />
variables store the machine’s internal program state as well as temporary state<br />
during the function’s execution in two large array of chars. The representation<br />
of boolean values as chars is inherently memory inefficient. There<strong>for</strong>e we modify<br />
the Esterel-generated C code to use bitfields instead, as exemplified below.<br />
Bitfields are a C mechanism <strong>for</strong> addressing individual bits of a struct. The necessary<br />
modifications are made by a Perl script but currently require some human<br />
intervention, though the task could be fully automated. Note that these modifications<br />
are required only when compiling <strong>for</strong> the BTnode. Development and<br />
initial program testing is typically per<strong>for</strong>med in the BTnode emulation environment<br />
on a PC, where size is not an issue.