Information Technology Reference
In-Depth Information
NesC “Hello World” Program: Blink
To give an overview of the issues involved, we consider a simple application that
comes bundled with the TinyOS distribution, called Blink . As its name suggests,
the Blink application uses the on-board timer to periodically change the state of a
sensor node's LED, producing a blinking effect. The Blink application consists of
four connected components: Main, BlinkM, SingleTimer, and Leds, as seen in the
configuration declaration (
configuration Blink {
implementation {
components Main,BlinkM, SingleTimer, LedsC;
// connecting Main toSingleTimer and BlinkM through StdControl
Main.StdControl -> SingleTimer.StdControl;
Main.StdControl -> BlinkM.StdControl;
BlinkM.Timer -> SingleTimer.Timer; //connecting BlinkM to
BlinkM.Leds -> LedsC; //connecting BlinkM to LedC
In this example, we can note the following:
Components Main, BlinkM, SingleTimer, and LedC are used. Code for these
components is elaborated in separate files (for example, BlinkM code is found
In the last four lines before the ending bracket, we can see how these compo-
nents are interconnected - through “wiring” of their interfaces, using the nota-
tionUser.Interface -> Provider.Interface.
BlinkM, the central module of the application, provides the StdControl interface,
of which the implicit component Main is the user. The execution of the program
“begins” with Main issuing the commands “Init” and “Start” to BlinkM. In
response to these commands, BlinkM will start the timer, through the Timer inter-
face. As BlinkM is notified of timer tick events, it toggles the LED, by issuing
commands to the LedC component through the Leds interface.
//Implementation for Blink application:
// the red LED is toggled whenever Timer fires.
module BlinkM {
provides {
interface StdControl;
uses {
interface Timer;
interface Leds;
implementation {
//Handling of the Init command, issued by Main
// just pass the Init command on to the Leds component
command result_t StdControl.init() {
Search WWH ::

Custom Search