TinyOS and nesC
 
 Lesson 1 !

advertisement
TinyOS and nesC
Lesson 1
!
Distributed Embedded Software and Networks
TDDI07#
!
Ekhiotz Vergara
12/11/15
Summary
! 
Lab environment and rules
! 
TinyOS
! 
" 
Goals
" 
Features
" 
Operation
nesC
" 
Features supporting TinyOS
" 
Keywords
! 
Component example
! 
Real interface example
! 
TinyOS Application example
12/11/15
1
Lab environment
! 
Work in pairs
! 
Real sensor nodes
! 
Unscheduled time
! 
" 
Lab preparation
" 
Report
Scheduled time
" 
! 
12/11/15
Work in the labs with the sensor nodes
Deadlines
2
Lab rules
! 
Use of real hardware:
" 
Sensor nodes only available during lab hours
" 
You are responsible for the sensor nodes and USB cables
" 
You are required to demonstrate the labs running in the
nodes during lab hours
" 
You are required to prepare for the labs in advance to be
able to finish before the deadline
! 
Plagiarism cases will be reported
! 
Report template for each lab
12/11/15
3
Labs
LESSON 2
LESSON 1
! 
Lab 1: PhotoMeter
" 
Illuminance measurement and display
! 
Lab 2: Traffic Light
! 
Lab 3: Energy efficient wireless communication
12/11/15
" 
Wireless communication
" 
Energy consumption
4
Summary
! 
Lab environment and rules
! 
TinyOS
! 
" 
Goals
" 
Features
" 
Operation
nesC
" 
Features supporting TinyOS
" 
Keywords
! 
Component example
! 
Real interface example
! 
TinyOS Application example
12/11/15
5
Sensing applications
Bridge vibration monitoring
Monitoring the microclimate
12/11/15
Underwater sensing
Body sensor 6networks
Building monitoring
TinyOS Goals
! 
Hardware abstraction
! 
Limited resources
" 
Low cost and small devices
! 
Low power operation
! 
Flexibility
! 
12/11/15
" 
Hardware
" 
Applications
TinyOS
Min. size
400 bytes!
Efficient processing
7
TinyOS Platform example
! 
Resource constrained device
! 
! 
12/11/15
Low power consumption
8
MSP430 microcontroller
" 
8 MHz 16 bit RISC
" 
10kB RAM
! 
1 MB external flash
! 
250 kbps low power radio
! 
AA Batteries
TinyOS Features
10 KB
Stack
! 
Concurrency model: Reactive
" 
! 
! 
Global
0 KB
Single stack
Applications are composed by components
" 
! 
Sequential and event-driven processing
Simple memory model
" 
Modularity provided by components used as building blocks
Specialized operating system integrated with applications
" 
Application is built with the components that compose the
operating system
" 
12/11/15
Free
TinyOS is a “library”
9
TinyOS Components
! 
Provide operating system abstraction layers
! 
Encapsulate set of services or functionalities
" 
! 
Interfaces are bidirectional
" 
! 
Interfaces
Use or provide a functionality
Modules implement components
Interface
Module X
Component X
12/11/15
10
TinyOS Components - Wiring
! 
Applications created wiring components
" 
! 
Reusability of components
Main component is application starting point
Component App
App Module
Interface
Interface
Module X
Component X
12/11/15
11
TinyOS Operation
! 
Event-driven nature
" 
! 
Asynchronous hardware interrupts (timer, radio, sensor…)
Synchronous sequential tasks
" 
Run to completion – keep tasks short!
" 
Standard scheduler FIFO policy
" 
Tasks are atomic to other tasks, but not to interrupt handlers
or commands and events they invoke
! 
12/11/15
Split-phase operation
" 
Commands
" 
Events
Interface A
Interface B
Module
Interface C
12
TinyOS Operation example
! 
Asynchronous code
! 
Timer interruption (TI)
post a task that switches LEDs on/off according to a shared variable X
! 
Synchronous code (tasks)
TI LEDs
" 
Switch on/off the LEDs (LEDs)
" 
Heavy computation
" 
Update the shared variable X (U)
TI LEDs
Computation
Delayed hardware
interrupt!
Responsiveness
U TI LEDs U
Time
TI LEDs
12/11/15
Computation
TI LEDs
13
U TI LEDs
atomic
Time
Summary
! 
Lab environment and rules
! 
TinyOS
! 
" 
Goals
" 
Features
" 
Operation
nesC
" 
Features supporting TinyOS
" 
Keywords
! 
Component example
! 
Real interface example
! 
TinyOS Application example
12/11/15
14
nesC – Language support
! 
nesC: network embedded system C
! 
TinyOS written in nesC
! 
Component-based
! 
12/11/15
" 
Similar to objects
" 
Discrete unit of functionality
Local namespace
" 
Implementing functions
" 
Declare functions that it calls
15
nesC Keywords
! 
Includes
! 
Interface
! 
Module, configuration
" 
! 
provide, uses, as
Implementation
" 
components
! 
Task – post
! 
Event – signal
! 
Command – call
! 
Atomic
12/11/15
16
Configuration - Wiring
Component App
! 
! 
Connect interfaces
" 
User -> provider
" 
Provider <- user
" 
Provider = provider
Interface X
Interface X
Module X
Component X
Interpretation of arrows:
" 
" 
12/11/15
App Module
-> : Get functionality of this interface from this component
! 
ApplicationC.InterfaceX -> ComponentX;
! 
ApplicationC.InterfaceX -> ComponentX.InterfaceX;
= : forward the functionality from this component
17
Summary
! 
Lab environment and rules
! 
TinyOS
! 
" 
Goals
" 
Features
" 
Operation
nesC
" 
Features supporting TinyOS
" 
Keywords
! 
Component example
! 
Real interface example
! 
TinyOS Application example
12/11/15
18
Component example (1)
Status
! 
Provided Interfaces
Control
Baker
interface Status {
command uint32_t timeLeft();
command void setTime(uint32_t time);
}
interface Control {
command void startBaking(uint32_t cakeType);
event void cakeReady();
}
" 
Commands called by user and implemented by provider
! 
" 
call
Events implemented by user and signalled by provider
! 
12/11/15
Oven
signal
19
Component example (2)
! 
Used interface
interface Oven {
command void setTemperature(uint32_t temp);
event void temperatureReady();
}
Status
Control
Baker
Oven
12/11/15
20
Component example (3)
! 
Implementation
module Baker {
provides
{
interface Control;
interface Status;
}
uses interface Oven;
}
implementation {
event void Oven.temperatureReady()
{
// do some stuff
}
}
12/11/15
21
Status
Control
Baker
Oven
Component example (4)
! 
Status
Configuration
" 
Wiring
Status
configuration BakerC {
provides {
interface Control;
interface Status;
}
}
implementation {
components OvenC;
BakerC.Oven -> OvenC;
}
12/11/15
Control
Control
Baker
Oven
Oven
OvenC
BakerC
22
Summary
! 
Lab environment and rules
! 
TinyOS
! 
" 
Goals
" 
Features
" 
Operation
nesC
" 
Features supporting TinyOS
" 
Keywords
! 
Component example
! 
Real interface example
! 
TinyOS Application example
12/11/15
23
Real interface example
! 
Timer interface
interface Timer
{
command void startPeriodic (uint32_t dt);
command void startOneShot(uint32_t dt);
command uint32_t getNow();
event void fired();
…
}
…..
Timer
… = It has more commands and events
12/11/15
24
Real application example
BlinkAppC.nc
BlinkAppC.nc
module BlinkC {
uses interface Timer<TMilli> as Timer0;
uses interface Timer<TMilli> as Timer1;
uses interface Leds;
uses interface Boot;
}
implementation
{
event void Boot.booted()
{
call Timer0.startPeriodic( 250 );
configuration BlinkAppC
{
}
implementation
{
components MainC, BlinkC, LedsC;
components new TimerMilliC() as Timer0;
components new TimerMilliC() as Timer1;
BlinkC -> MainC.Boot;
call Timer1.startPeriodic( 500 );
BlinkC.Timer0 -> Timer0;
BlinkC.Timer1 -> Timer1;
BlinkC.Leds -> LedsC;
}
event void Timer0.fired()
{
call Leds.led0Toggle();
}
}
How many different interfaces?
How many components?
How does the application start?
How many commands are used?
What is the flow of the application?
12/11/15
event void Timer1.fired()
{
call Leds.led1Toggle();
}
}
26
Application exercise
! 
Draw the diagram
Interface
Command
Component
Event
BlinkC
Boot
booted&
Timer0
Timer1
startPeriodic&
startPeriodic&
fired&
fired&
led0Toggle&
led1Toggle&
Boot
Timer0
Timer1
Leds
MainC
TimerMilliC
(Timer0)
TimerMilliC
(Timer1)
LedsC
BlinkAppC
12/11/15
Leds
28
TinyOS Directory
12/11/15
29
TOSSIM
! 
TinyOS Simulator
" 
Python interface
" 
Simulate nodes using debug messages
" 
Same code of real hardware
http://docs.tinyos.net/tinywiki/index.php/TOSSIM#Compiling_TOSSIM
>>> m.isOn()
1
>>> m.turnOff()
>>> m.isOn()
0
>>> m.bootAtTime(560000)
>>> t.runNextEvent()
DEBUG (32): Application booted.
1
12/11/15
30
AVRORA
! 
Simulator to test the programs
" 
Cycle accurate execution of AVR microcontrollers
" 
Same code of real hardware
http://avrora.cvs.sourceforge.net/avrora/
12/11/15
31
References
! 
TinyOS: An operating system for sensor networks
P. Levis, S. Madden, J. Polastre, R. Szewczyk, K. Whitehouse, A. Woo, D. Gay, J. Hill,
M. Welsh, E. Brewer, and D. Culler. TinyOS: An operating system for sensor networks ambient
intelligence. In Werner Weber, Jan M. Rabaey, and Emile Aarts, editors, Ambient Intelligence,
chapter 7, pages 115–148. Springer Berlin Heidelberg, Berlin/Heidelberg, 2005.
! 
TinyOS programming
http://www.tinyos.net/tinyos-2.x/doc/pdf/tinyos-programming.pdf
! 
TinyOS website
http://www.tinyos.net
! 
Datasheet of TelosB sensor node
http://www.willow.co.uk/TelosB_Datasheet.pdf
12/11/15
32
Download