210 likes | 231 Views
TinyOS. Wireless and Mobile Networking Lab. Konkuk University. Outline. Installation Software Architecture NesC Programming Example codes Blink Moss SimpleRf. Installation. TinyOS install. Installation (con't). Cygwin install Cygwin setup. Installation (con't). RPM upgrade
E N D
TinyOS Wireless and Mobile Networking Lab. Konkuk University
Outline • Installation • Software Architecture • NesC Programming • Example codes • Blink • Moss • SimpleRf
Installation • TinyOS install
Installation (con't) • Cygwin install • Cygwin setup
Installation (con't) • RPM upgrade • rpm -Uvh tinyos-1.1.13May2005cvs-1.cygwin.noarch.rpm
Installation (con't) • msp-gcc install delete
Installation (con't) • msp-gcc path setup • export PATH=$PATH:/cygdrive/c/mspgcc/bin
Installation (con't) • overwriting some files
Software Architecture TinyOS Application Component Main Command Handler Event Handler Counter Clock INT_TO_LED Task LED Tiny Scheduler
Software Architecture (con't) • Relationship of Commands, Tasks, Events and two-level scheduler Higher Level Component • Both event and command can schedule tasks • Commands can not signal events • Tasks preemptive by events • Tasks non preemptive by tasks Signal Events Command Lower Level Component Task Task Task
NesC Programming • Wiring Module Configuration Provide Wiring Interface Use Implement Module
NesC Programming (con't) Module Configuration Provided components Used components • Wiring with interfaces • Declare interfaces using and providing • Implement commands and events
NesC Programming (con't) • Blink module BlinkM { provides { interface StdControl; } uses { interface Timer; interface Leds; } } implementation { uint8_t i; command result_t StdControl.init() { call Leds.init(); return SUCCESS; } command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 500); } command result_t StdControl.stop() { return call Timer.stop(); } event result_t Timer.fired() { i++; if(i%3 == 1) call Leds.blueToggle(); else if(i%3 == 2) call Leds.redToggle(); else if(i%3 == 0) call Leds.yellowToggle(); return SUCCESS; } }
NesC Programming (con't) • Blink (con’t) configuration Blink { } implementation { components Main, BlinkM, SingleTimer, LedsC; Main.StdControl -> SingleTimer.StdControl; Main.StdControl -> BlinkM.StdControl; BlinkM.Timer -> SingleTimer.Timer; BlinkM.Leds -> LedsC; }
NesC Programming (con't) • Moss #define MORSE_WPM 12 #define MORSE_UNIT (1200/MORSE_WPM) module MossM { provides { interface StdControl; } uses { interface Timer; interface Leds; interface HPLUART as UART; } } implementation { command result_t StdControl.init() { call UART.init(); call Leds.init(); call Leds.redOff(); call Leds.yellowOff(); call Leds.greenOff(); 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() { static char *morse = "... .-.. .-.. -- "; static char *current; if(!current) current = morse;
NesC Programming (con't) • Moss (con’t) switch(*current) { case ' ': if(!call Leds.get()) { call Leds.yellowOn(); call Timer.start(TIMER_ONE_SHOT, 2*MORSE_UNIT); call UART.put(' '); } else { call Leds.yellowOff(); call Timer.start(TIMER_ONE_SHOT, 2*MORSE_UNIT); current++; } break; case '.': if(!call Leds.get()) { call Leds.redOn(); call Timer.start(TIMER_ONE_SHOT, MORSE_UNIT); call UART.put('.'); } else { call Leds.redOff(); call Timer.start(TIMER_ONE_SHOT, MORSE_UNIT); current++; } break; case '-': if(!call Leds.get()) { call Leds.greenOn(); call Timer.start(TIMER_ONE_SHOT, 3*MORSE_UNIT); call UART.put('-'); } else { ..
NesC Programming (con't) • SimpleRf configuration SimpleRf {} implementation { components Main, SimpleRfM, CC2420RadioC, CC2420ControlM, TimerC, LedsC; Main.StdControl -> TimerC.StdControl; Main.StdControl -> SimpleRfM.StdControl; SimpleRfM.Timer -> TimerC.Timer[unique("Timer")]; SimpleRfM.Leds -> LedsC; SimpleRfM.CC2420Control -> CC2420ControlM; SimpleRfM.RadioControl -> CC2420RadioC; SimpleRfM.RadioSend -> CC2420RadioC.Send; SimpleRfM.RadioReceive -> CC2420RadioC.Receive; }
NesC Programming (con't) • SimpleRf (con’t) module SimpleRfM { provides { interface StdControl; } uses { interface Leds; interface Timer; interface CC2420Control; interface StdControl as RadioControl; interface BareSendMsg as RadioSend; interface ReceiveMsg as RadioReceive; } } implementation { TOS_MsgPtr pData; TOS_Msg Data; uint8_t count = 0; task void sendDATA() { pData->addr = 0x0001; pData->length = 1; pData->data[0] = count; count++; call Leds.yellowToggle(); call RadioSend.send(pData); }
NesC Programming (con't) • SimpleRf (con’t) command result_t StdControl.init() { pData = &Data; call Leds.init(); call RadioControl.init(); return TRUE; } command result_t StdControl.start() { // Set CC2420 channel // Valid channel values are 11 through 26. call CC2420Control.TunePreset(11); call RadioControl.start(); if(TOS_LOCAL_ADDRESS == 0x0000) call Timer.start(TIMER_REPEAT, 1024); return TRUE; } command result_t StdControl.stop() { call RadioControl.stop(); call Timer.stop(); return TRUE; } event result_t Timer.fired() { post sendDATA(); return SUCCESS; }
NesC Programming (con't) • SimpleRf (con’t) event TOS_MsgPtr RadioReceive.receive(TOS_MsgPtr packet) { call Leds.redToggle(); return packet; } event result_t RadioSend.sendDone(TOS_MsgPtr msg, result_t success) { return SUCCESS; } }