Tiny OS
Tiny OS
Learning Objectives
• Understand TinyOS – the dominant open
source operating systems for WSN
– Hardware abstraction architecture (HAA)
– TinyOS architecture and component model
– Main characteristics of TinyOS 2
• Understand NesC programmng
• Learn representative WSN applications
Prerequisites
• Module 1
• Basic concepts of Operating Systems
• Basic concepts of Object-oriented Design and
Analysis
• Basic concepts of Computer Networks
Software Challenges - TinyOS
• Power efficient
– Put microcontroller and radio to sleep
• Small memory footprint
– Non-preemptable FIFO task scheduling
• Efficient modularity
– Function call (event and command) interface between
commands
• Application specific
• Concurrency-intensive operation
– Event-driven architecture
– No user/kernel boundary
http://www.tinyos.net 4
TinyOS Hardware Abstraction
Architecture (HAA)
[TinyOS_1]: Table 2 5
TinyOS Hardware Abstraction
Architecture (HAA)
Monolith-kernel Micro-kernel
HW HW
Hardware Abstractions
TinyOS Component Model
– Tasks: computation
– Interface:
• Command
Commands Events
• Event
Power
quickly and reliably
• Long Lifetime
– Months to Years without
changing batteries sleep
– Power management is the key
to WSN success
Time
• Sleep
– Majority of the time
– Telos: 2.4mA
– MicaZ: 30mA
• Wakeup
– As quickly as possible to process and return to sleep
– Telos: 290ns typical, 6ms max
– MicaZ: 60ms max internal oscillator, 4ms external
• Active
– Get your work done and get back to sleep
– Telos: 4-8MHz 16-bit
– MicaZ: 8MHz 8-bit
[Introduction_2]: Figure 3 17
Code and Data Size Breakdown
[Introduction_2]: Table 2 18
WSN Protocol Stack
• Virtualized
• Dedicated
• Shared
[TinyOS_1]: Section 5 30
T2 Timer Subsystem
• See interface at:
– tos/lib/timer/Timer.nc
One Example TinyOS Application -
BlinkC
• http://docs.tinyos.net/index.php/TinyOS_Tutor
ials
One Example of Wiring
•Ref: D. Gay, et al. “Software Design Patterns for TinyOS”, Section 2.3
unique and uniqueCount
•Ref: D. Gay, et al. “Software Design Patterns for TinyOS”, Section 2.4
async
• Functions that can run preemptively are
labeled with async keyword
• Command an async function calls and events
an async function signals must be async
• All interrupt handlers are async
• atomic keyword
– Race conditions, data races
Figure 4 of [TinyOS_1] 48
Timer Subsystem
• HplTimer[0-3]C provide dedicated access to
the two 8-bit and two 16-bit timers of
ATmega128 MCU
• T2 subsystem is built over the 8-bit timer 0
• Timer 1 is used for CC2420 radio
message_t
• tos/types/message.h
• Ref. TEP 111
• Every link layer defines its header, footer, and
metadata structures
Relationship between CC1000 Radio
Implementation and message_t
• tos/chips/cc1000/CC1000Msg.h
Relationship between CC2420 Radio
Implementation and message_t
• tos/chips/cc2420/CC2420.h
Relationship between Serial Stack
Packet Implementation and message_t
• tinyos-2.x/tos/lib/serial/Serial.h
Active Message (AM)
• Why do we need AM?
– Because it is very common to have multiple
services using the same radio to communicate
– AM layer to multiplex access to the radio
• make micaz install,n
– n: unique identifier for a node
Active Message
• Every message contains the name of an event handler
• Sender
– Declaring buffer storage in a frame
– Naming a handler
– Requesting Transmission
– Done completion signal
• Receiver
– The event handler is fired automatically in a target node
Double Check!!!!!!!
TinyOS Component
• Two types of components
– Module: provide implementations of one or more
interfaces
– Configuration: assemble other components
together
TinyOS Component Model
• Component has:
Messaging Component
– Frame (storage)
Internal Tasks Internal State
– Tasks: computation
– Interface:
• Command
• Event
Commands Events
TinyOS Component
TinyOS Two-level Scheduling
• Tasks do computations
– Non-preemptable FIFO scheduling
– Bounded number of pending tasks
• Events handle concurrent dataflows
– Interrupts trigger lowest level events
– Events prempt tasks, tasks do not
– Events can signal events, call commands, or post tasks
Preempt Tasks
POST FIFO
events
commands
commands
Interrupts
Time
Hardware
TinyOS Applications
• In most mote applications, execution is driven
solely by timer events and the arrival of radio
messages
How to Program motes Under TinyOS
• make telosb install,n mib510,/dev/ttyUSB0
• make telosb install,1 mib510,/dev/ttyUSB0
Representative WSN Applications
• BaseStation – Listen – BlinkToRadio
– One-hop WSN application to collect sensed values
• OscilloScope
– one-hop WSN application with GUI interface
• MultiOscilloScopre
– multihop WSN application
• Octopus
– multi-hop WSN application with a more dynamic display
of network topology and data dissemination functions
Application Example - BaseStation,
Listen and BlinkToRadio
UHCL Lamar
Terminal 1 of PC A# java
Terminal 1 of PC B# java net.tinyos.tools.Listen -comm
Run
net.tinyos.tools.Listen -comm serial@/dev/ttyUSB1:micaz
BlinkToRadio
[email protected]:9002 Option 1: Listen connects to local MTS300
serial ports + MicaZ
Option 3: Listen connects to
remote SerialForwarder Internet
MIB520
+ MicaZ Run
BaseStation
PC A at Lamar Univ. with IP
PC B at UHCL 140.158.130.239
Terminal 2 of PC A# java
Terminal 2 of PC B# java
net.tinyos.sf.SerialForwarder -comm serial@/
net.tinyos.sf.SerialForwarder -comm
dev/ttyUSB1:micaz
[email protected]:9002
Terminal 3 of PC A# java
Terminal 3 of PC B# java
net.tinyos.tools.Listen -comm
net.tinyos.tools.Listen -comm
sf@localhost:9002
sf@localhost:9002
Option 4: One local SerialForwarder connects Option 2: Listen connects to SerialForwarder
to a remote SerialForwarder. Listen connects running on a local machine
to local SerialForwarder
Application Example - Oscilloscope
UHCL Lamar
Terminal 1 of PC A# export
MOTECOM=serial@/dev/
ttyUSB1:micaz
Terminal 1 of PC B# java Run
Terminal 1 of PC A# oscillloscope/
net.tinyos.tools.Listen -comm OscilloscopeC.nc
java/run
[email protected]:9002 MTS300
Option 1: Oscilloscope connects to + MicaZ
Option 3: Listen connects to local serial ports
remote SerialForwarder Internet
MIB520
+ MicaZ Run
BaseStation
PC A at Lamar Univ. with IP
PC B at UHCL 140.158.130.239
Terminal 2 of PC A# java
Terminal 3 of PC B# export net.tinyos.sf.SerialForwarder -comm serial@/
[email protected]:9002 dev/ttyUSB1:micaz
Terminal 3 of PC B# oscilloscope/java/run
Terminal 3 of PC A# export
Option 4: oscilloscope connects to remote MOTECOM=sf@localhost:9002
SerialForwarder Terminal 3 of PC A# oscilloscope/java/run
• http://csserver.ucd.ie/~rjurdak/Octopus.htm
Octopus
Data
TelosB
Collection
Run Octopus
Data
Collection TelosB Data
Run Dissemination
Octopus
Data Run Octopus
TelosB Dissemination
Data
Data Collection
Data Data
Collection Dissemination Collection
TelosB
Data
Dissemination Run Octopus
Data TelosB
Dissemination Run Octopus
BaseStation – Listen - BlinkToRadio
Run BaseStation
run java net.tinyos.tools.Listen -
comm serial@/dev/ttyUSB0:telosb
TelosB
Mote
GUI Interface
1. run java net.tinyos.sf.SerialForwarder - Run BaseStation
comm serial@/dev/ttyUSB0:telosb
2. Under Oscilloscope/java, run ./run TelosB
Mote
Run
OscilloscopeC.nc
TelosB
Text Interface Mote
1. run java net.tinyos.tools.Listen -
comm serial@/dev/ttyUSB0:telosb TelosB
Mote
Run
OscilloscopeC.nc
MultihopOscilloscope
GUI Interface
Run TelosB
MultihopOscilloscopeC.nc Run
1. run java net.tinyos.sf.SerialForwarder -comm
serial@/dev/ttyUSB0:telosb MultihopOscilloscopeC.nc
2. Under MultihopOscilloscope/java, run ./run TelosB
Run
MultihopOscilloscopeC.nc
TelosB
Text Interface
1. run java net.tinyos.tools.Listen -
comm serial@/dev/ttyUSB0:telosb
TelosB
TelosB
Run
Run
MultihopOscilloscopeC.nc
MultihopOscilloscopeC.nc
MViz
1. run java
net.tinyos.sf.SerialForwarder
-comm serial@/dev/
UHCL ttyUSB0:telosb Lamar Univ.
2. run tos-mviz -comm
sf@localhost:9002 -dir /opt/ TelosB
tinyos-2.x/apps/MViz Run MViz
MVizMsg TelosB Run MViz
Machine in UHCL TelosB
Run MViz
TelosB
Internet
run tos-mviz -comm
IP: 140.158.130.239 TelosB
[email protected]:9002 -dir /opt/ TelosB
tinyos-2.x/apps/Mviz MVizMsg
Run MViz
Run MViz
Octopus
1. run java
net.tinyos.sf.SerialForwarder
-comm serial@/dev/
ttyUSB0:telosb
Lamar Univ.
2. run