Download presentation
Presentation is loading. Please wait.
Published byGervais Robbins Modified over 9 years ago
1
Blink Blink.nc configuration Blink { } implementation { components Main, BlinkM, SingleTimer, LedsC; Main.StdControl -> BlinkM.StdControl; Main.StdControl -> SingleTimer.StdControl; BlinkM.Timer -> SingleTimer.Timer; BlinkM.Leds -> LedsC; }
2
BlinkM.nc module BlinkM { provides { interface StdControl; } uses { interface Timer; interface Leds; } } implementation { command result_t StdControl.init() { call Leds.init(); return SUCCESS; } command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 1000) ; } command result_t StdControl.stop() { return call Timer.stop(); } event result_t Timer.fired() { call Leds.redToggle(); return SUCCESS; } }
3
Blink experiments Program a mote with the Blink application Modify Blink to include multiple timers Timer1 Timer2 Timer3 0 Timer1 10 1 5 - LED blinks for 5 secs, then stops for 5 secs, and so on…. Timer3 Timer2
4
Timer1 Timer2 Timer3 0 Timer1 10 1 5 - LED blinks for 5 secs, then stops for 5 secs, and so on…. Timer3 Timer2 BlinkM { : uses interface Timer as Timer1 Interface Timer as Timer2 interface Timer as Timer3 : Blink: components Main, BlinkM, TimerC, LedsC : BlinkM.Timer1 -> TimerC.Timer[unique(“Timer”)]; BlinkM.Timer2 -> TimerC.Timer[unique(“Timer”)]; : Timer1 fires start Timer2 and Timer3 Timer3 fires stop Timer2 TIMER_ONE_SHOT
5
Sense Application Module SenseM { provides { interface StdControl; } uses { interface Timer; interface ADC; interface StdControl as ADCControl; interface Leds; } } SenseM StdControl Timer ADC ADControl Leds
6
Sense Application Sense.nc configuration Sense { // this module does not provide any interface } implementation { components Main, SenseM, LedsC, TimerC, Photo; Main.StdControl -> TimerC; Main.StdControl -> SenseM; SenseM.ADC -> Photo; SenseM.ADCControl -> Photo; SenseM.Leds -> LedsC; SenseM.Timer -> TimerC.Timer[unique("Timer")]; } SenseM StdControl Timer ADC ADControl Leds TimerC Photo TimerC
7
Event-Driven Sensor Access Pattern 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 command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 200); } event result_t Timer.fired() { return call sensor.getData(); } event result_t sensor.dataReady(uint16_t data) { display(data) return SUCCESS; } SENSE Timer Photo LED
8
display(7-((data>>7) &0x7)); result_t display(uint16_t value) { if (value &1) call Leds.yellowOn(); else call Leds.yellowOff(); if (value &2) call Leds.greenOn(); else call Leds.greenOff(); if (value &4) call Leds.redOn(); else call Leds.redOff(); return SUCCESS; }
9
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 TskName();... } task void TskName {... }
10
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.