Lab4: Introduction to nesC
Objective:
The objective of this lab is to introduce the students to nesC and its various
programming constructs.
Learning Outcomes
Students will be able to understand and write simple programs in nesC. Students will be acquainted with basic concepts and programming model of nesC.
About nesC
nesC (network embedded system C) is an extension to C language used to build
applications in TinyOS and is designed such a way to exhibit the concepts and
execution model of TinyOS. [1]
It has a programming model which is based on components and interfaces. The
components interact via an interface. It has an event-based concurrency model
with run to completion tasks and interrupts handlers. This run-to-completion
model does not allow blocking calls.
In nesC programs are made of components and these components are wired
i.e. as assembled to form whole programs. The components further can consist
of tasks which can provide internal concurrency. The interfaces can be
provided or used by components. The provided interfaces are intended to
represent the functionality that the component provides to its user; the used
interfaces represent the functionality the component needs to perform its job.
[2].
Therefore nesC programs can be said to be assemblies of components wired
via named interfaces. Modules are components that are implemented with C
code. Configurations are components implemented by wiring other
components together. Commands can be considered as invocation by user to
the provider. While the events take place from the provider to the user. We can
also say that provider component provides an interface that user component
uses to get the service. [3]
In the case of lengthy or system services like sending a packet or sampling a
sensor known as split-phase operations, where a command to start the
operation returns immediately and a callback event indicates when the
operation completes.
Why use nesC for wireless sensor networks?
The main emphasis of nesC is on taking all possible decisions at the
compile time this model is also known as a static programming model.
By using this type of model it improves the efficiency and also saves lot
of time and memory.
nesC can optimize the call paths across components and also eliminate
any dead code and variables.
But due to this static model nesC does not support dynamic behavior.
The traditional programming languages use pointers and other methods
to achieve dynamic behavior for e.g. a variable can have allocation of
address at runtime. But such requirements are not really of that
importance in wireless sensor networks.
Improved speed, energy and memory utilization therefore is provided by
using nesC. [3]
Note: You can find all the mentioned files in this document in the resources
folder for the Labs.
Understanding a Sample Program in nesC:
We can understand nesC and TinyOS better by following the tutorial that
explains the simplest TinyOS program. Read the tutorial given on the TinyOS
Website
http://docs.tinyos.net/index.php/The_simplest_TinyOS_program
Exercises (20 Points):
1. Explain why there was a need of new programming language for wireless
sensor networks? (2 Points)
2. Give three of the important features of nesC.(3 Points)
3. Explain the concept of wiring. (5 Points)
4. Compile and Execute the Blink Application following steps mentioned in
the TinyOS Tutorial.
http://docs.tinyos.net/index.php/Getting_Started_with_TinyOS#Blink:_An
_Example_Application
Run and execute the program with Mica2 Motes. (10 points)
Run and execute the program with Telosb Motes. (10 points)
5. Modify the Blink application to cause pressing the user button to rotate
the leds through a counter among 0, 1, 2, and 3, with the following
properties:
· At 0, no timer is _red.
· At 1, Timer 0 with period 1s is _red.
· At 2, Timer 0 and Timer 1 (period 2s) are _red.
· At 3, Timer 0, Timer 1, Timer 2 (period 4s) are _red.
Timer 0 toggles led0, Timer 1 toggles led1, Timer 2 toggles led2.
Note: Multiple instantiations of the same interface can be made by using the 'as'
keyword. For example:
interface Timer as Timer0;
interface Timer as Timer1;
Run and execute the program with Mica2 Motes. (15 points)
Run and execute the program with Telosb Motes. (15 points)[8]
References:-
1.http://en.wikipedia.org/wiki/NesC
2. http://nescc.sourceforge.net/
3. http://sing.stanford.edu/pubs/a22-gay.pdf
4. http://nescc.sourceforge.net/papers/nesc-ref.pdf
5. http://www.eecs.harvard.edu/~mdw/talks/nesc-msr.pdf
6. http://www.cs.berkeley.edu/~pal/pubs/nesc-pldi03.pdf
7. http://cs-people.bu.edu/gtw/motes/
8. http://ds.informatik.rwth-aachen.de/teaching/ws0809/tinyos/lab1.pdf
|