tinyos tutorial

28
TinyOS Tutorial Faisal Karim Shaikh DEWSNet Group Dependable Embedded Wired/Wireless Networks www.fkshaikh.com/dewsnet

Upload: ansel

Post on 23-Feb-2016

98 views

Category:

Documents


0 download

DESCRIPTION

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). - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: TinyOS  Tutorial

TinyOS Tutorial

Faisal Karim Shaikh

DEWSNet GroupDependable Embedded Wired/Wireless Networks

www.fkshaikh.com/dewsnet

Page 2: TinyOS  Tutorial

Outline Hardware Details

Introduction to TinyOS

Introduction to nesC

Introduction toTOSSIM

Lab Task 1 (Blink Application)

Lab Task 2 (Energy Hole Application)

Page 3: TinyOS  Tutorial

3

UC Berkeley Family of Motes

Page 4: TinyOS  Tutorial

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

Page 5: TinyOS  Tutorial

MicaZ

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

Page 6: TinyOS  Tutorial

TelosB

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

Page 7: TinyOS  Tutorial

7

MTS300CA Sensor Board

Page 8: TinyOS  Tutorial

8

Programming Board (MIB510)

Page 9: TinyOS  Tutorial

9

Hardware Setup Overview

Page 10: TinyOS  Tutorial

10© DEEDS GroupSWFT WS ’07-08

Page 11: TinyOS  Tutorial

11© DEEDS GroupSWFT WS ’07-08

Page 12: TinyOS  Tutorial

12© DEEDS GroupSWFT WS ’07-08

Page 13: TinyOS  Tutorial

13

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

Page 14: TinyOS  Tutorial

Install TinyOS and the ‘make’ 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

Page 15: TinyOS  Tutorial

15

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”

BA Wiring

Page 16: TinyOS  Tutorial

16

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)

Page 17: TinyOS  Tutorial

17

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_MsgPtr msg); event result_t sendDone(TOS_MsgPtr msg, result_t success); }

Page 18: TinyOS  Tutorial

18

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; }

Page 19: TinyOS  Tutorial

19

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;

Page 20: TinyOS  Tutorial

20

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

Page 21: TinyOS  Tutorial

21

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

Page 22: TinyOS  Tutorial

22

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.ncconfiguration BlinkAppC { } Implementation { components MainC, BlinkC, LedsC ; components new TimerMilliC() as Timer0; components new TimerMilliC() as Timer1; components new TimerMilliC() as Timer2; BlinkC -> MainC.Boot;

© DEEDS GroupSWFT WS ’07-08

Interface

Instance

Page 23: TinyOS  Tutorial

23

Lab Task 1: Blink Application(Cont) BlinkC.Timer0 -> Timer0; BlinkC.Timer1 -> Timer1; BlinkC.Timer2 -> Timer2; BlinkC.Leds -> LedsC; }

© DEEDS GroupSWFT WS ’07-08

User

Interface

Provider

Page 24: TinyOS  Tutorial

24

Lab Task 1: Blink Application configuration BlinkAppC{ } states it is a configuration called

BlinkAPPC

Implementation { …. } actual configuration is implemented within this block

MainC, BlinkC, LedsC, TimerMilliC are components Timer0, Timer1, Timer2 are instances of TimerMilliC

component BlinkC -> MainC.Boot initializes LedsC and Timer components

in BlinkC BlinkC.Timer0 -> Timer0;

wires Timer0(instance of Timer<TMilliC> interface) used by BlinkC to the Timer<TMilliC> interface provided by Timer0 (instance of TimerMilliC component)

BlinkC.Leds -> LedsC; wires Leds interface used by BlinkC to the Leds interface provided by

LedsC

Page 25: TinyOS  Tutorial

25

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 BlinkC declares the interfaces it provides and uses BlinkM module also uses three interfaces: Timer<TMilli>,

Leds and Boot Timer<TMilli> interface

Sets a periodic timer that repeats after a specified time. Leds interface

defines commands of Leds Led0On() , Led0Off(), Led0Toggle() etc

Page 26: TinyOS  Tutorial

26

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(); }

Page 27: TinyOS  Tutorial

27

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

© DEEDS GroupSWFT WS ’07-08

Page 28: TinyOS  Tutorial

Discussion