21.08.2013 Views

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

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

110 Chapter 6. Implementation<br />

Program 6.5: Example of an OSM program containing several state variables<br />

side-by-side with the its variable mapping in the host language C.<br />

Every state mapps into a corresponding union, containing both<br />

the variables of that state plus a representation of the state’s substates.<br />

Sequential and parallel compositions of substates are represented<br />

as a union and a struct of substate representations, respectively.<br />

1 state PROG_5 {<br />

2<br />

3 state C {<br />

4 var int c;<br />

5<br />

6 state A {<br />

7 var int a1, a2;<br />

8 e / outA(c) -> B;<br />

9 } // end state A<br />

10 state B {<br />

11 var int b1, b2;<br />

12 f / -> A;<br />

13 } // end state B<br />

14<br />

15 } // end state C<br />

16 ||<br />

17 state D {<br />

18 var int d;<br />

19 }<br />

20<br />

21 } // end state PROG_5<br />

1 struct statePROG_5 {<br />

2 struct par_C_D {<br />

3 struct stateC {<br />

4 int c;<br />

5 union seq_A_B {<br />

6 struct stateA {<br />

7 int a1, a2;<br />

8<br />

9 } _stateA;<br />

10 struct stateB {<br />

11 int b1, b2;<br />

12<br />

13 } _stateB;<br />

14 } _seq_A_B;<br />

15 } _stateC;<br />

16<br />

17 struct stateD {<br />

18 int d;<br />

19 } _stateD;<br />

20 } _par_C_D;<br />

21 } _statePROG_5;<br />

is only true <strong>for</strong> the variable mapping. Control structures are first mapped to an<br />

intermediate representation in the imperative language Esterel [19, 18, 26]. From<br />

this representation, C code is generated by an Esterel compiler.<br />

The Esterel Synchronous Language<br />

Esterel is a synchronous language (see, <strong>for</strong> example, [17, 50, 95]) <strong>for</strong> the specification<br />

of reactive systems. Synchronous languages are reactive in that they react<br />

to input stimuli (i.e., events) in order to compute output events, typically also<br />

changing the internal program state. Synchronous languages are typically used<br />

to implement control systems, such as, industry process control, airplane and<br />

automobile control, embedded systems, bus interfaces, etc. They are built on<br />

the hypothesis that operations take no (real) time, that is, operations are atomic<br />

and the output of an operation is synchronous with its input (hence the name<br />

synchronous language). Synchronous languages have a discrete model of time<br />

where time progresses only on the occurrence of events.<br />

The Esterel language allows to specify concurrent processes, where individ-

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!