310 likes | 614 Views
TinyOS Tutorial. Faisal Karim Shaikh DEWSNet Group Dependable Embedded Wired/Wireless Networks www.fkshaikh.com/dewsnet . Outline. Hardware Details Introduction to TinyOS Introduction to nesC Introduction toTOSSIM Lab Task 1 (Blink Application) Lab Task 2 (Energy Hole Application).
E N D
TinyOS Tutorial Faisal KarimShaikh DEWSNet Group Dependable Embedded Wired/Wireless Networks www.fkshaikh.com/dewsnet
Outline • Hardware Details • Introduction to TinyOS • Introduction to nesC • Introduction toTOSSIM • Lab Task 1 (Blink Application) • Lab Task 2 (Energy Hole Application)
Mica2 and Mica2Dot • ATmega128 CPU • Self-programming • 128KB Instruction EEPROM • 4KB Data EEPROM • Chipcon CC1000 • Manchester encoding • Tunable frequency • 315, 433 or 900MHz • 38K or 19K baud • Lower power consumption • 2 AA batteries • Expansion • 51 pin I/O Connector 1 inch
MicaZ characteristics AVR ATMega 128L microcontroller @ 8MHz IEEE 802.15.4 Zigbee compliant with 2.4 GHz 128K of program memory 4KB SRAM for volatile data and 4KB EEPROM for persistent data Radio: CC2420 51 pin connector for connecting to a programming board Three visible LEDs serve as feedback MicaZ
TelosB characteristics: MSP430 microcontroller @ 8MHz Communicate via a 250 kbps IEEE 802.15.4 Zigbee transceiver Memory: 10K of RAM, 48K of Flash, Radio: CC2420 Three visible LEDs serve as feedback Integrated humidity, light and temperature sensors TelosB
TinyOS • “Operating system” for Wireless Sensor Networks • Event driven • Light weight • Component based • An open-source development environment • Programming language: nesC • Supported platforms include Linux, Windows with Cygwin
Download http://www.tinyos.net/download.html Directory Structure /apps /Blink /Forwarder /contrib /doc /tools /java /tos /interfaces /lib /platform /mica /mica2 /mica2dot /sensorboard /micasb /system /types From within the application’s directory: make <platform> (re)install.<node id> <node id> is an integer between 0 and 255 <platform> may be mica2, mica2dot, or all Example: make mica2 install.0 make pc Generates an executable that can be run a pc for Install TinyOS and the ‘make’
Components Define two scopes: Specification of interfaces Implementation Use and provide interfaces events Commands Two types of components: Modules: Implement the application behavior Configurations: Wires components together Connect via interfaces Connections called “wiring” Wiring B A
nesC Programming language for TinyOS Used for writing libraries and applications in TinyOS Extension of C Built out of components, atomic statements with well-defined, interfaces Component: module file (BlinkC.nc) Configuration file (BlinkAppC.nc)
nesC-Interfaces Interfaces: Bidirectional Multi-function interaction channel between two components, the provider and the user Specifies a set of commands: to be implemented by the provider of interface Specifies set of events: to be implemented by the user of interface Example: interface SendMsg { command result_t send(uint16_t address, uint8_t length, TOS_MsgPtrmsg); event result_tsendDone(TOS_MsgPtrmsg, result_t success); }
nesC-Atomic Statements Atomic Statements: Similar to “as-if” Used to implement mutual exclusion, for updates to shared data structures etc. Should be short Forbids calling commands or signaling events A simple example is: bool busy; // global void f( ) { bool available; atomic { available = !busy; busy = TRUE; } if (available) do_something; atomic busy = FALSE; }
nesC-Wiring Wiring: Connect interfaces, commands, events Three wiring statements in nesC: interface1 = interface2 (equate wires) interface1 -> interface2 (link wires) interface2 <- interface1 Determine relationships between interfaces component that uses an interface is on the left component provides the interface is on the right Uses -> provides Example: BlinkM.Timer -> SingleTimer.Timer;
TOSSIM: Simulator for TinyOS Requirements Scalability Completeness No change to application required Tested code can be deployed right away Replaces hardware with software components Allows user to drive, monitor, debug simulation Time is kept at 4MHz granularity TinyViz as GUI Simulates: large scale sensor networks network at bit error per link repeatable loss rate asymmetric links each individual hardware every interrupt in the system
Further Reading TinyOS Tutorial: http://www.tinyos.net/tinyos-1.x/doc/tutorial/index.html Help archive: http://www.tinyos.net/search.html FAQ: http://www.tinyos.net/support.html#lists nesC Manual:http://www.tinyos.net/tinyos-1.x/doc/nesc/ref.pdf Publication:David Gay, Philip Levis, David Culler, Eric Brewer, nesC: A Programming Language for Deeply Networked Systems, 2003. TOSSIM Manual:www.eecs.berkeley.edu/~pal/pubs/nido.pdf http://www.eecs.berkeley.edu/~pal/research/tossim.html Hardware http://www.xbow.com/ webs.cs.berkeley.edu/papers/hotchips-2004-mote-table.pdf
Lab Task 1: Blink Application • "Blink“: • The simple test program • Causes the three LEDs on the mote to turn on and off. • Composed of two components: • a module file, called "BlinkC.nc“ • a configuration file, called "BlinkAppC.nc" • BlinkC.nc configuration BlinkAppC { } Implementation { components MainC, BlinkC, LedsC; components new TimerMilliC() as Timer0; components new TimerMilliC() as Timer1; components new TimerMilliC() as Timer2; BlinkC -> MainC.Boot; Instance Interface
Lab Task 1: Blink Application(Cont) BlinkC.Timer0 -> Timer0; BlinkC.Timer1 -> Timer1; BlinkC.Timer2 -> Timer2; BlinkC.Leds-> LedsC; } Provider User Interface
Lab Task 1: Blink Application configuration BlinkAppC{ }states it is a configuration called BlinkAPPC Implementation { …. } actualconfiguration is implemented within this block MainC, BlinkC, LedsC, TimerMilliCare components Timer0, Timer1, Timer2 are instances of TimerMilliC component BlinkC -> MainC.Bootinitializes LedsC and Timer components in BlinkC BlinkC.Timer0 -> Timer0; wires Timer0(instance of Timer<TMilliC> interface) used by BlinkCto the Timer<TMilliC> interface provided by Timer0 (instance of TimerMilliCcomponent) BlinkC.Leds-> LedsC; wires Leds interfaceused by BlinkCto the Ledsinterface provided by LedsC
Lab Task 1: Blink Application BlinkM.nc module BlinkC() { uses interface Timer<TMilli> as Timer0; uses interface Timer<TMilli> as Timer1; uses interface Timer<TMilli> as Timer2; uses interface Leds; uses interface Boot; } continued… module BlinkCdeclares the interfaces it provides and uses BlinkM module also usesthreeinterfaces: Timer<TMilli>, Ledsand Boot Timer<TMilli>interface Sets a periodic timer that repeats after a specified time. Ledsinterface defines commands of LedsLed0On(),Led0Off(), Led0Toggle() etc
Lab Task 1: Blink Application Boot interface notifies components when TinyOS booted. BlinkC.nc: continued implementation { event void Boot.booted() { call Timer0.startPeriodic( 250 ); call Timer1.startPeriodic( 500 ); call Timer2.startPeriodic( 1000 ); } event void Timer0.fired() { dbg("BlinkC", "Timer 0 fired @ %s.\n", sim_time_string()); call Leds.led0Toggle(); }
Lab Task 1: Blink Application event void Timer1.fired() { dbg("BlinkC", "Timer 1 fired @ %s \n", sim_time_string()); call Leds.led1Toggle(); } event void Timer2.fired() { dbg("BlinkC", "Timer 2 fired @ %s.\n", sim_time_string()); call Leds.led2Toggle(); } } • Timer0.startPeriodic( 250 ) starts periodic timer at 250ms • Timer0.fired() event is triggered after 250 ms • the Leds.Led0Toggle() toggles the red LED