INTRODUCTION TO TINYOS 2.

X AND NESC

Anatomy of TelosB Mote
2

       

Limited computational and communication resources MSP430 16-bit microcontroller 10kB RAM 250 kbps, high data rate radio Sensors (temperature, humidity, light) Data collection and programming via USB interface 48kB of flash program memory IEEE 802.15.4 compliant A pair of AA batteries (4 days)
http://www.willow.co.uk/TelosB_Datasheet.pdf

Typical WSN Application
3

Periodic  Data Collection  Network Maintenance Triggered Events  Detection/Notification  Infrequently occurs Long Lifetime  Months to Years without changing batteries  Power management is the key to WSN success

processing data acquisition communication

Power

sleep
Time

MAIN AIM: saving power! 2nd AIM: easy development of applications! TinyOS applications and systems. low-power microcontrollers motes have.TinyOS 4     TinyOS is designed for the small. . as well as the OS itself is written in nesC a dialect of C.

libraries. applications written in nesC NesC language  A dialect of C Language with extensions for components Features a task scheduler  Automatically puts the microcontroller to sleep when there is no code to execute  Allows for concurrency  Lets execution be split-phase .TinyOS 5    Component-based architecture Event-driven operating system Developed for resource constrained wireless sensor networks  Ultimately not limited by WSN’s.    TinyOS.

Software Challenges 6    Power efficient  Put microcontroller and radio to sleep Non-preemptable FIFO task scheduling Function call (event and command) interface between commands Small memory footprint  Efficient modularity    Application specific Concurrency-intensive operation Event-driven architecture  No user/kernel boundary  .

Has small footprint as it uses a non-preemtable FIFO task scheduling. .TinyOS 7     Component based architecture allows frequent changes while still keeping the size of code minimum. It is power efficient as it makes the sensors sleep as soon as possible. Event based execution model means no user/kernel boundary and hence supports high concurrency.

What TinyOS provides
8

Things to make writing applications easier:  A component model which allows you to write small, reusable pieces of code and compose them into larger abstractions;  application programming interfaces (APIs), services, component libraries and an overall component structure that simplify writing new applications and services.

COMPONENT BASED ARCHITECTURE

Component-Oriented Programming
10

A nesC application consists of components
 Components

can be reused  Components can be replaced  Components can be hardware or software

.Component-Oriented Programming 11  Object-Oriented Programming:  Focuses on the relationships between classes that are combined into one large binary executable  Component-Oriented Programming:  Focuses on interchangeable code modules that work independently and don't require you to be familiar with their inner workings to use them.

No inheritance. such as Circle and Rectangle. Components have only private variables. must provide implementations for the methods of the abstract class GraphicObject.nesC vs C and C++ 12 Each non-abstract subclass of GraphicObject. .

.nc)  Configuration (suffixed with AppC.Component-Oriented Programming 13  File name and types in TinyOS:  Module (suffixed with P.nc)  Collectively.nc) – At Lower level  Interface (suffixed with .nc) – At TOP level  Configuration (suffixed with C. a Configuration and a Module are combined to create a Component.

Implement interface definitions Modules are like the IC’s on a circuit board that actually do something. Use interfaces from other modules.Modules 1/3 14      Define functionality that make your application run. Don’t care what’s behind the interface.  . Provide interfaces to other modules.

A Component has: – Frame (internal states) e. – Tasks (data processing) – Interface(s) (commands/events) Commands and Events are function calls   . variables. functions. etc.Modules 2/3 15  Each component is specified by an interface.g.

Implementation 16 Implementation of a module defines how the component works  Application code  All commands and events declared as provided in the interface MUST be implemented  .Modules 3/3 .

laying out wiring that connects modules together. Wrap modules.Configurations 17    Wire interfaces from several modules together.  . Configurations are like a Printed Circuit Board. Are implemented by connecting interfaces of existing components.

All interface commands MUST be implemented for users to call Use .All interface events MUST be implemented for providers to signal .Interface: Commands/Events 18  Define the interactions between modules  Commands   Implemented by the module providing the interface Called by the module using the interface  Events   Signaled by the module providing the interface Captured by the module using the interface  Components either provide or use an interface   Provide .

event result_t fired()..e. must implement the event fired. a components that invokes commands. command result_t stop(). i.nc * filename for a bidirectional interface interface Timer { command result_t start (char type uint32_t interval).Interface Example 19 Timer. The User of this interface. }   The Provider (implementor) of this interface must implement the start and stop commands. .

A HELLO-WORLD EXAMPLE .

Component Diagram 21 CONFIGURATION HelloC .

HelloC Configuration 22 configuration HelloC { } implementation { } .

Component Diagram 23 HelloP MODULE HelloC .

HelloC Configuration 24 configuration HelloC { } implementation { components HelloP. } .

HelloP Module 25 module HelloP { } implementation { } .

Component Diagram 26 void myFunctions() {…} HelloP FUNCTIONALITY HelloC .

interface Leds. } } implementation { } .HelloP Module 27 module HelloP { uses { interface Boot.

net/tinyos-2. } Boot sequence provides one interface:  Boot for signaling that the system has successfully booted TinyOS 2.x Boot Sequence http://www.Boot Interface 28 interface Boot { event void booted().x/doc/html/tep107.tinyos.html .

} } USE an interface.booted() { Commands/Events) } } . CAPTURE all of its events! The HelloP module MUST implement the booted() event that is provided by the Boot Interface (see slide Interface: implementation { event void Boot. interface Leds.HelloP Module 29 module HelloP { uses { interface Boot.

… command void set(uint8_t val). command void led0Toggle(). command void led0Off().Leds Interface 30 interface Leds { command void led0On(). } .

booted() { call Leds. Keyword “as” is used when multiple usages of an } interface is required (similar } to the “new” keyword of Java/c++) implementation { event void Boot. interface Leds as MyLeds. } } .led0On().HelloP Module 31 module HelloP { uses { interface Boot. interface Leds as MySecondLeds.

Component Diagram 32 void myFunctions() {…} Leds HelloP Boot INTERFACES HelloC .

Component Diagram 33 CONFIGURATIONS void myFunctions() {…} Leds LedsC Boot MainC HelloC HelloP .

// USES -> PROVIDES } HelloP.MyLeds -> LedsC. LedsC. MainC. HelloP. . SecondLedsC.MySecondLeds -> SecondLedsC. HelloP.HelloC Configuration 34 configuration HelloC { } implementation { components HelloP.Boot.Boot -> MainC.

Component Diagram 35 PROVIDES void myFunctions() {…} Leds LedsC Boot MainC HelloC USES HelloP .

RADIO COMMUNICATION .

Actual completion of the operation is signaled by a separate callback. one of the goals of TinyOS is to have a flexible hardware/software boundary.Split-Control 1/4 37    Because sensor nodes have a broad range of hardware capabilities. . In a split-phase operation the request that initiates an operation completes immediately.

software writes to a few configuration registers to start a sample. When the ADC sample completes. to acquire a sensor reading with an analog-to-digital converter (ADC).Split-Control 2/4: Example 1 38   For example. and the software reads the value out of a data register. . the hardware issues an interrupt.

then to bits and ultimately driving the RF circuits to send the bits. involving converting the packets to bytes. one by one.Split-Control 3/4: Example 2 39    Packet send method in Active Messages component. This is a long operation. A call to a split-phase operation returns immediately .

. return SUCCESS. ComponentB signal Interface.doSomething().Split-Control 4/4 40 ComponentA call Interface.done().

Radio Stacks 41 Your Application AMSend SplitControl Receive Message Queue ActiveMessage CSMA / Acknowledgements Transmit / Receive / Init Radio Hardware .

Main Radio Interfaces 42  SplitControl  Provided by ActiveMessageC  AMSend  Provided by AMSenderC  Receive  Provided by AMReceiverC .

MainC.AMSend -> AMSenderC. new AMSenderC(0). // send an AM type 0 message new AMReceiverC(0).Boot -> MainC. MyAppP.Setting up the Radio: Configuration 43 configuration MyAppC { } implementation { components MyAppP. // receive an AM type 0 message MyAppP.SplitControl -> ActiveMessageC. MyAppP. } . MyAppP. ActiveMessageC.Receiver -> AMReceiverC.

Setting up the Radio: Module 44 module MyAppP { uses { interface Boot. } } implementation { … } . interface Receive. interface AMSend. interface SplitControl.

The SplitControl is connected to the ActiveMessageC (radio component of the mote) event void SplitControl. } message_t sendbuf. } Destination address Pointer to send buffer event void SplitControl.SplitControl -> ActiveMessageC.Turn on the Radio 45 event void Boot.startDone(error_t error) { call AMSend.booted() { call SplitControl.start().send(AM_BROADCAST_ADDR. sizeof(sendbuf)). MyAppP.stopDone(error_t error) { } Size of msg .& sendbuf.

error_t error) { // Successful transmission } .Send Messages 46 event void AMSend.sendDone(message_t *msg.

} . void *payload.Receive a Message 47 event message_t *Receive.led0Toggle(). uint8_t length) { call Leds. return msg.receive(message_t *msg.

Payloads 48  A message consists of:  Header  Payload  Optional Footer .

nx_uint8_t data[TOSH_DATA_LENGTH]. . } message_t. nx_uint8_t footer[sizeof(message_footer_t)].TinyOS message_t 49 typedef nx_struct message_t { nx_uint8_t header[sizeof(message_header_t)]. nx_uint8_t metadata[sizeof(message_metadata_t)].

Payloads : Use Network Types 50 (MyPayload. enum { AM_MYPAYLOAD = 0x50. }. #endif .h) #ifndef MYPAYLOAD_H #define MYPAYLOAD_H typedef nx_struct MyPayload { nx_uint8_t count. } MyPayload.

getPayload(&sendbuf).send(AM_BROADCAST_ADDR.Example: Filling out a Payload 51 message_t sendbuf.& sendbuf. payload->count = (myCount++). } . call AMSend. sizeof(sendbuf)). void createMsg() { MyPayload *payload = (MyPayload *) call AMSend.

return msg. call Leds.receive(message_t *msg. } .set(payload->count).Example: Receiving a Payload 52 event void Receive. uint8_t len) { MyPayload *payload = (MyPayload *) payload. void *payload.

http://docs.tinyos.php/Mote-mote_radio_communication . The receiver of the message displays the counter's three least significant bits on the three LEDs.net/index.Tutorial Mote-mote radio communication 53    Consider two nodes running the same application. Each node increments a counter and sends a message with the counter value over the radio.

X INSTALLATION .TINYOS 2.

tinyos.net/index.Installing TinyOS 2.net/index.net/index. http://docs.step_install_on_your_host_OS_with_Debian_packages 2.tinyos.php/Running_a_XubunTOS_Virtual_Machine_Image_in_VMware_Player#Wi ndows_VMware_Player_Installation .tinyos.1#Two.php/Running_a_XubunTOS_Virtual_Machine_Image_in_VMware_Player#Debian_Li nux_VMware_Player_Installation Windows http://docs. 2 easy choices On Ubuntu: Running a XubunTOS Virtual Machine Image in VMware Player: a) On Ubuntu b) On http://docs.x 55  1.php/Installing_TinyOS_2.

PROGRAMMING A TELOSB MOTE .

tinyos. LED1 to turn on and off at 2Hz. The effect is as if the three LEDs were displaying a binary count of zero to seven every two seconds.php/Getting_Started_with_TinyOS#Blink:_An_Example_Application .Blink Application 57   It simply causes the LED0 to to turn on and off at 4Hz.net/index. http://docs. and LED2 to turn on and off at 1Hz.

motelist 58 .

tinyos. <NODE ID> bsl.2C_telosb.<Serial Port> e.29 .net/index.Program a specific mote 59 To compile a program for telosb platform: make telosb  To flash/upload the program to a telosb mote: make telosb install.g.php/Getting_Started_with_TinyOS#Installing_on_telos-family_mote_.  http://docs.28telosa.

Successful programming! 60 .

SenseWALL 61     Protocol/algorithm implementation Experimental comparison. validation and evaluation Actuation etc … .

sample some sensors. Nodes running this application periodically wake up.Example Application 1/2 62   Consider a basic data-collection application. . and send the data through an ad hoc collection tree to a data sink.

a timer. .Example Application 2/2 63  The four TinyOS APIs the application uses: low power settings for the radio. sensors. and a data collection routing layer.

sourceforge.php/Installing_TinyOS_2.tinyos.php/TinyOS_Tutorials Documentation and TEPs http://www.tinyos.1.0/doc/ TinyOS API http://www.tinyos.1. hermes.upatras.net/index.x/doc/pdf/tinyosprogramming.1 TinyOS reference http://www.net/tinyos-2.tinyos.tinyos.gr Theofanis Raptis References        TinyOS Wiki http://docs.net/index.net/tinyos-2.cti}.References 64 For questions: traptis@{ceid.php/Main_Page TinyOS installation http://docs.net/papers/nesc-ref.net/index.1.net/tinyos-2.pdf TinyOS Tutorials http://docs.pdf NesC reference http://nescc.html .tinyos.0/doc/nesdoc/telosa/index.

Sign up to vote on this title
UsefulNot useful