Академический Документы
Профессиональный Документы
Культура Документы
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
Prerequisites
Module 1
Basic concepts of Operating Systems
Basic concepts of Object-oriented Design and
Analysis
Basic concepts of Computer Networks
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
Traditional OS Architectures
Application 2
Application 1
I/O
I/O
Micro-kernel
Monolith-kernel
VM
NFS
Application 1
Scheduler
IPC
HW
Scheduler
HW
VM
Application
Component
COMM .
TinyOS
Application
Component
.
NO Kernel
Direct hardware manipulation
NO Process management
Only one process on the fly.
NO Virtual memory
Single linear physical address space
NO Dynamic memory allocation
Assigned at compile time
NO Software signal or exception
Function Call instead
Goal: to strip down memory size and system overhead.
TinyOS Overview
Application = scheduler + graph of components
Compiled into one executable
Event-driven architecture
Single shared stack
No kernel/user space differentiation
Main (includes Scheduler)
Application (User Components)
Actuating
Communication
Sensing
Communication
Hardware Abstractions
Messaging Component
Internal Tasks
Commands
Internal State
Events
10
processing
data acquisition
communication
Data Collection
Network Maintenance
Majority of operation
Triggered Events
But must be reported
quickly and reliably
Long Lifetime
Months to Years without
changing batteries
Power management is the key
to WSN success
Power
Detection/Notification
Infrequently occurs
sleep
Time
12
Design Principles
Key to Low Duty Cycle Operation:
Sleep majority of the time
Wakeup quickly start processing
Active minimize work & return to sleep
13
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
The mote revolution: Low Powr
Wireless Sensor Network
14
Power Consumption
Energy Consumption
Idle listen:receive:send = 1:1.05:1.4
[Introduction_2]: Figure 3
17
[Introduction_2]: Table 2
18
TinyOS 2
An operating system for tiny, embedded, and
networked sensors
NesC language
A dialect of C Language with extensions for components
Three Limitations
Application complexity
High cost of porting to a new platform
reliability
TinyOS 2
Static binding and allocation
Every resource and service is bound at compile time and all
allocation is static
TinyOS 2
The scheduler has a fixed-length queue, FIFO
Task run atomically
Interrupt handlers can only call code that has the async
keyword
Complex interactions among components
Event
In most mote applications, execution is driven solely by
timer events and the arrival of radio messages
ATmega128 has two 8-bit timers and two 16-bit timers
Ref: P. Levis, et al. T2: A Second Generation OS For Embedded Sensor
Networks
TinyOS 2
sync code is non-preemptive,
when synchronous (sync) code starts running, it does not relinquish the
CPU to other sync code until it completes
Tasks
enable components to perform general-purpose "background"
processing in an application
A function which a component tells TinyOS to run later, rather than
now
TinyOS 2
Platforms
MicaZ, Mica2, etc;
Compositions of chips
Chips
MCU, radio, etc
Each chip follows the HAA model, with a HIL
implementation at the top
TinyOS 2
A T2 packet has a fixed size data payload
which exists at a fixed offset
The HIL of a data link stack is an active
message interface
Zero-copy
Device Drivers in T2
Virtualized
Dedicated
Shared
Ref: Section 3 of [Energy_1]
T2 Timer Subsystem
MCU comes with a wide variation of hardware
timers
ATmega128: two 8-bit timers and two 16-bit times
MSP430: two 16-bit timers
[TinyOS_1]: Section 5
30
T2 Timer Subsystem
See interface at:
tos/lib/timer/Timer.nc
AppM
AppM
Sensor Interface
Initialize Interface
SensorC
AppC
Notation
Parameterized Interfaces
An interface array
Ref: D. Gay, et al. Software Design Patterns for TinyOS, Section 2.3
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
44
Example - VirtualizeTimerC
Ref:
/tos/lib/timer/VirtualizeTimerC.nc
Section 7.1 of TinyOS Programming Manual
/tos/lib/timer/VirtualizeTimerC.n
46
Virtualized Timer
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
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
No blocked or waiting threads on the receiver
Behaves like any other events
Single buffering
Double Check!!!!!!!
TinyOS Component
Two types of components
Module: provide implementations of one or more
interfaces
Configuration: assemble other components
together
Messaging Component
Internal Tasks
Commands
Internal State
Events
Structure of a Component
Command Handlers
Event Handlers
Set of Tasks
Frame
(containing state information)
TinyOS Component
Preempt
events
POST
FIFO
commands
commands
Interrupts
Hardware
Time
TinyOS Applications
In most mote applications, execution is driven
solely by timer events and the arrival of radio
messages
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
UHCL
Terminal 1 of PC B# java
net.tinyos.tools.Listen -comm
sf@140.158.130.239:9002
Option 3: Listen connects to
remote SerialForwarder
PC B at UHCL
Terminal 2 of PC B# java
net.tinyos.sf.SerialForwarder -comm
sf@140.158.130.239:9002
Terminal 3 of PC B# java
net.tinyos.tools.Listen -comm
sf@localhost:9002
Option 4: One local SerialForwarder connects
to a remote SerialForwarder. Listen connects
to local SerialForwarder
Terminal 1 of PC A# java
net.tinyos.tools.Listen -comm
serial@/dev/ttyUSB1:micaz
Run
BlinkToRadio
MTS300
Option 1: Listen connects to local
+ MicaZ
serial ports
Internet
MIB520
+ MicaZ Run
BaseStation
PC A at Lamar Univ. with IP
140.158.130.239
Terminal 2 of PC A# java
net.tinyos.sf.SerialForwarder -comm serial@/
dev/ttyUSB1:micaz
Terminal 3 of PC A# java
net.tinyos.tools.Listen -comm
sf@localhost:9002
Option 2: Listen connects to SerialForwarder
running on a local machine
UHCL
Terminal 1 of PC B# java
net.tinyos.tools.Listen -comm
sf@140.158.130.239:9002
Option 3: Listen connects to
remote SerialForwarder
PC B at UHCL
Terminal 3 of PC B# export
MOTECOM=sf@140.158.130.239:9002
Terminal 3 of PC B# oscilloscope/java/run
Option 4: oscilloscope connects to remote
SerialForwarder
Terminal 1 of PC A# export
MOTECOM=serial@/dev/
ttyUSB1:micaz
Terminal 1 of PC A# oscillloscope/
java/run
Run
OscilloscopeC.nc
MTS300
Option 1: Oscilloscope connects to
+ MicaZ
local serial ports
Internet
MIB520
+ MicaZ Run
BaseStation
PC A at Lamar Univ. with IP
140.158.130.239
Terminal 2 of PC A# java
net.tinyos.sf.SerialForwarder -comm serial@/
dev/ttyUSB1:micaz
Terminal 3 of PC A# export
MOTECOM=sf@localhost:9002
Terminal 3 of PC A# oscilloscope/java/run
Option 2: Oscilloscope connects to
SerialForwarder running on a local machine
MTS300
+ MicaZ
Terminal 2 of PC#
MultihopOscilloscope/java/run
Text Interface
Terminal 3 of PC# java
net.tinyos.tools.Listen -comm
serial@/dev/ttyUSB1:micaz
MIB520
+ MicaZ
MTS300
+ MicaZ
Run
MultihopOscilloscopeC.nc
Run
MultihopOscilloscopeC.nc
MTS300
+ MicaZ
Run
MultihopOscilloscopeC.nc
MTS300
+ MicaZ
Run
MultihopOscilloscopeC.nc
Terminal 1 of PC A#java
net.tinyos.sf.SerialForwarder -comm
serial@/dev/ttyUSB1:micaz
Lamar
Run MViz
Internet
Terminal 1 of PC B#tos-mviz -comm
sf@140.158.130.239:9002 -dir /opt/
tinyos-2.x/apps/Mviz MVizMsg
Terminal 2 of PC B#java
net.tinyos.tools.Listen -comm
sf@140.158.130.239:9002
MTS300
+ MicaZ
Run MViz
MTS300
+ MicaZ
Run MViz
MIB520
+ MicaZ
PC A with IP:
140.158.130.239
MTS300
+ MicaZ
MTS300
+ MicaZ
Run MViz
Run MViz
1. Add SENSORBOARD=mts300 when compile
2. Modify MVizSensorC.nc to add related sensors
3. Based on MultihopOscilloscopeC.nc, the root id should be 0
3.a For root node: make micaz install,0 mib510,/dev/ttyUSB0
3.b For non-root node (e.g. node 1): make micaz install,1
mib510,/dev/ttyUSB0
4. chmod 666 /dev/ttyUSB*
5. add CFLAGS += -DCC2420_DEF_RFPOWER=3 in Makefile to
change transmission power
6. How to configurate light, temperature sensors? Modify:
6.a $TOSROOT/tos/platforms/micaz/DemoSensorC.nc
6.b $TOSROOT/tos/sensorboards/mts300/DemoSensorC.nc
6.c $TOSROOT/apps/Mviz/MVizSensorC.nc
MViz
Lamar University
University of Houston,
Clear Lake
TelosB
Run MViz
Run MViz
TelosB
Run MViz
TelosB
Internet
PC A with IP:
140.158.130.239
TelosB
TelosB
Run MViz
Run MViz
Data
Collection
Run
Octopus
MIB520 +
MicaZ
Data
Collection
Data
Dissemination
Data
Dissemination
MTS300
+ MicaZ
MTS300
+ MicaZ
Run Octopus
Data
Dissemination
MTS300
+ MicaZ
Run Octopus
Data
Collection
Data
Dissemination
http://csserver.ucd.ie/~rjurdak/Octopus.htm
MTS300
+ MicaZ
Run Octopus
Octopus
Data
Collection
Data
Collection
Run
Octopus
TelosB
Data
Collection
Data
Dissemination
Data
Dissemination
TelosB
TelosB
Run Octopus
Data
Dissemination
TelosB
Run Octopus
Data
Collection
Data
Dissemination
TelosB
Run Octopus
Run BlinkToRadio
OscilloScope
GUI Interface
1. run java net.tinyos.sf.SerialForwarder comm serial@/dev/ttyUSB0:telosb
2. Under Oscilloscope/java, run ./run
Text Interface
1. run java net.tinyos.tools.Listen comm serial@/dev/ttyUSB0:telosb
Run BaseStation
TelosB
Mote
TelosB
Mote
Run
OscilloscopeC.nc
TelosB
Mote
Run
OscilloscopeC.nc
MultihopOscilloscope
GUI Interface
1. run java net.tinyos.sf.SerialForwarder -comm
serial@/dev/ttyUSB0:telosb
2. Under MultihopOscilloscope/java, run ./run
TelosB
Run
MultihopOscilloscopeC.nc
Run
MultihopOscilloscopeC.nc
TelosB
Run
MultihopOscilloscopeC.nc
Text Interface
1. run java net.tinyos.tools.Listen comm serial@/dev/ttyUSB0:telosb
TelosB
TelosB
Run
MultihopOscilloscopeC.nc
TelosB
Run
MultihopOscilloscopeC.nc
MViz
1. run java
net.tinyos.sf.SerialForwarder
-comm serial@/dev/
ttyUSB0:telosb
UHCL
Lamar Univ.
TelosB
Run MViz
Run MViz
Machine in UHCL
TelosB
Run MViz
TelosB
Internet
run tos-mviz -comm
sf@140.158.130.239:9002 -dir /opt/
tinyos-2.x/apps/Mviz MVizMsg
IP: 140.158.130.239
TelosB
Run MViz
TelosB
Run MViz
Octopus
1. run java
net.tinyos.sf.SerialForwarder
-comm serial@/dev/
ttyUSB0:telosb
Lamar Univ.
2. run
2.a export
MOTECOM=serial@/dev/
ttyUSB0:telosb
TelosB
Run Octopus
Run Octopus
TelosB
Run Octopus
TelosB
IP: 140.158.130.239
TelosB
Run Octopus
TelosB
Run
Octopus
Lab 1
a) Write a PingPong application that runs on
two nodes. When a node boots, it sends a
broadcast packet using the AMSend interface.
When it receives a packet, it a) wait one
second; b) sends a packet; c) toggle an LED
whenever a node sends a packet.
Lab 2
b) Please add the reliable data transmission feature to the PingPong
application from the Application and Link layer, respectively. Suppose that
two motes A and B are talking to each other.
I. Application Layer: When mote A sends a broadcast pack P to node B,
mote A will start a timer T. When mote B receives the packet P, mote B
will send an ACK to node A.
b.1 If the timer T expires before mote A receives the ACK from mote B
(either the packet P or the ACK is lost), mote A will retransmit the packet;
b.2 If mote A receives the ACK from mote B before the timer T expires,
mote A will do nothing when the timer T expires.
b.3 If mote B receive a packet which has already been received (based on
sequence number), node B just drop this packet.
There is a sequence number included in the payload of the packet P. The
sequence number starts from 0. When a packet P is received, the receiver
will display the bottom three bits (through LEDs) of the sequence number
in the packet P.
Lab 2 - continue
II. Link Layer: In TEP 126 (http://www.tinyos.net/tinyos2.x/doc/html/tep126.html), it says:
PacketLink: This layer provides automatic retransmission
functionality and is responsible for retrying a packet
transmission if no acknowledgement was heard from the
receiver. PacketLink is activated on a per-message basis,
meaning the outgoing packet will not use PacketLink unless it
is configured ahead of time to do so
Therefore, as an alternative, you may also configure
PacketLink to provide automatic retransmission functionality.
Assignment
1. What is the relationship among all the
application components in the Oscilloscope
application?
2. please give two examples of split-phase
operations in TinyOS 2.
3. What is the usage of Active Message in
TinyOS 2?
4. Why doesnt TinyOS 2 make every
statement async?