Blink nc configuration Blink implementation components Main Blink
Blink. nc configuration Blink { } implementation { components Main, Blink. M, Single. Timer, Leds. C; Main. Std. Control -> Blink. M. Std. Control; Main. Std. Control -> Single. Timer. Std. Control; Blink. M. Timer -> Single. Timer; Blink. M. Leds -> Leds. C; }
Blink. M. nc implementation { command result_t Std. Control. init() { call Leds. init(); return SUCCESS; } module Blink. M { provides { interface Std. Control; } uses { interface Timer; interface Leds; } } command result_t Std. Control. start() { return call Timer. start(TIMER_REPEAT, 1000) ; } command result_t Std. Control. stop() { return call Timer. stop(); } event result_t Timer. fired() { call Leds. red. Toggle(); return SUCCESS; } }
Blink experiments • Program a mote with the Blink application • Modify Blink to include multiple timers Timer 3 0 1 5 Timer 3 10 Timer 2 Timer 1 - LED blinks for 5 secs, then stops for 5 secs, and so on….
Blink. M { Blink: : components Main, Blink. M, Timer. C, Leds. C uses : interface Timer as Timer 1 : Interface Timer as Timer 2 Blink. M. Timer 1 -> Timer. C. Timer[unique(“Timer”)]; interface Timer as Timer 3 Blink. M. Timer 2 -> Timer. C. Timer[unique(“Timer”)]; : : : Timer 3 0 1 TIMER_ONE_SHOT 5 10 Timer 2 Timer 1 Timer 3 Timer 1 - LED blinks for 5 secs, then stops for 5 secs, and so on…. Timer 1 fires start Timer 2 and Timer 3 fires stop Timer 2
Sense Application Module Sense. M { provides { interface Std. Control; } uses { interface Timer; interface ADC; interface Std. Control as ADCControl; interface Leds; } } Timer ADC Std. Control Sense. M ADControl Leds
Sense Application Sense. nc configuration Sense { // this module does not provide any interface } implementation { components Main, Sense. M, Leds. C, Timer. C, Photo; Main. Std. Control -> Timer. C; Main. Std. Control -> Sense. M; Sense. M. ADC -> Photo; Sense. M. ADCControl -> Photo; Sense. M. Leds -> Leds. C; Sense. M. Timer -> Timer. C. Timer[unique("Timer")]; } Timer. C Std. Control Sense. M Timer ADControl Leds Photo Timer. C
Event-Driven Sensor Access Pattern command result_t Std. Control. start() { SENSE return call Timer. start(TIMER_REPEAT, 200); } event result_t Timer. fired() { return call sensor. get. Data(); Timer Photo } event result_t sensor. data. Ready(uint 16_t data) { display(data) return SUCCESS; } • • clock event handler initiates data collection sensor signals data ready event data event handler calls output command device sleeps or handles other activity while waiting LED
display(7 -((data>>7) &0 x 7)); result_t display(uint 16_t value) { if (value &1) call Leds. yellow. On(); else call Leds. yellow. Off(); if (value &2) call Leds. green. On(); else call Leds. green. Off(); if (value &4) call Leds. red. On(); else call Leds. red. Off(); return SUCCESS; }
Tasks • provide concurrency internal to a component – longer running operations • are preempted by events • not preempted by tasks • able to perform operations beyond event context • may call commands • may signal events {. . . post Tsk. Name(); . . . } task void Tsk. Name {. . . }
Sense Application • • Upload Sense Change sampling frequency Include Sounder component Make Sounder beep when Photo sensor senses no light. • Make Sounder beep when Temperature sensor detects an increase in temperature.
- Slides: 10