ece693_mobile_programming_ece_lecture13.pdf
DESCRIPTION
tinyosTRANSCRIPT
TinyOS Overview
Lecture 13
EE 693
Programming for Mobile Devices
Outline
TinyOS Overview
Why TinyOS 2.x
Difference between TinyOS 1.x and 2.x
Installing TinyOS 2.x
IRIS-XM2110
Atmel Atmega1281
2.4GHz
8KB RAM
128KB Program
Flash
51 pin I/O Connector
ADC 0-7 UART 1 I2C Bus
2 AA
MIB520CB Mote Interface Board
Mib520
IRIS interface
Sensor Board
Our testing sensor board with IRIS
TinyOS Overview
TinyOS Architecture
Component-oriented Programming
Concurrency Model
TinyOS Architecture
Sensing Comms Other Libraries
Application
Main (scheduler)
Hardware Abstractions (ADC, CLOCK, I2C, LEDS, PHOTO, UART, SPI)
Component-oriented Programming
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.
Three File Types
Module (suffixed with C.nc, P.nc)
Configuration (suffixed with C.nc, P.nc)
Interface (suffixed with .nc)
Public Module (suffixed with C.nc)
Private Module (suffixed with P.nc)
Component-oriented Programming
Configuration
Assemble other used components together
Wire interfaces used by components to interfaces provided by others
Can provide and use interfaces
Top-configuration and sub-configuration
Component-oriented Programming
Configuration
Assemble other used components together
Wire interfaces used by components to interfaces provided by others
Can provide and use interfaces
Top-configuration and sub-configuration
Top-configuration does not provide or use interface
Component-oriented Programming
Component-oriented Programming
Module
Declare provided and used interfaces
Implement the functions to make your application run
Does not care what is behind the interfaces and components
A configuration and a module combined to form a component
Component-oriented Programming
Interface
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
Command, Event, Task are all functions
Command is used for requesting actions
Event is used for notifying occurrence
Task is used for long time operations
Component-oriented Programming
15
Component Example BlinkAppC wires BlinkC.Timer to TimerC.Timer
module BlinkC {
uses interface Timer<TMilli>
as Timer0
provide interface xxxx}
implementation {
int c;
void increment() {c++;}
event void Timer0.fired()
{
call Leds.led0Toggle();
}
}
configuration BlinkAppC
{
}
implementation
{
components MainC, BlinkC, LedsC;
components new TimerMilliC()
as Timer0;
BlinkC.Timer0 -> Timer0;
BlinkC -> MainC.Boot;
BlinkC.Leds -> LedsC;
}
TimerC BlinkC Timer
Singletons and Generics
Singleton components are unique: they exist in a global namespace
Generics are instantiated: each instantiation is a new, independent copy
configuration BlinkC { … }
implementation {
components new TimerC();
components BlinkC;
BlinkC.Timer -> TimerC;
}
Interfaces
Collections of related functions
Define how components connect
Interfaces are bi-directional: for A->B
Commands are from A to B
Events are from B to A
Can have parameters (types)
interface Timer<tag> { command void startOneShot(uint32_t period); command void startPeriodic(uint32_t period); event void fired(); }
Interface (provide and use)
User
Provider
Interface
Commands
Events
Module BlinkC { use interface xxxx; provide interface xxxxxxx; ......... }
Concurrency Model
Task “background” processing, run later, rather than now.
Hardware Event Handler handle hardware interrupt
Split-phase Operation split invocation and completion into two separate
phases
Blocking operation
if (send() == SUCCESS) {
sendCount++;
}
Concurrency Model
Split-phase operation
// start phase
send();
// completion phase
void sendDone (error_t error) {
if (error == SUCCESS) {
sendCount++;
}
}
Tasks
TinyOS has a single stack: long-running computation can reduce responsiveness
Tasks: mechanism to defer computation
Tells TinyOS “do this later”
Tasks run to completion
TinyOS scheduler runs them one by one in the order they post
Keep them short!
Interrupts run on stack, can post tasks
TinyOS Execution Model
Xxxxxx;
event void Timer0.fired()
{
xxxxxx;
xxxxxx;
xxxxxx;
xxxxxx;
call Leds.led0Toggle();
xxxxxx;
xxxxxx;
post remainingwork();
}
xxxxx;
remainingwork(){xxxx;};
xxxxx;
......
Stack Task Queue
Timer0.fired
......
Timer0.fired
Led0Toggle
......
remainingwork
main
main
remainingwork
main
......
TinyOS/nesC Summary
Components and Interfaces Programs built by writing and wiring components
modules are components implemented in C
configurations are components written by assembling other components
Execution model Execution happens in a series of tasks (atomic with respect to
each other) and interrupt handlers
No threads
System services: startup, timing, sensing (so far) (Mostly) represented by instantiatable generic components
This instantiation happens at compile-time! (think C++ templates)
All slow system requests are split-phase
24
“Make”: The Tool Chain
ncc
gcc
int main() { scheduler_init(); ... }
Native binary:
03 2F 77 9A F2 FF ...
The “Make” System
Native binary:
03 2F 77 9A F2 FF ...
make micaz install mib520, /dev/ttyS0
automates nesC, C compilation, mote installation
TinyOS
App
PC Applications
Build PC Applications
Native binary:
03 2F 77 9A F2 FF ...
TinyOS Java, C, Python apps
Talk with motes
java classname -comm serial@/dev/ttyS0:micaz
PC Applications: Extracting Information from TinyOS
mig
ncg
Java, C or Python app
packet formats
constants
TinyOS
“Make”: Install Applications
Native binary:
03 2F 77 9A F2 FF ...
pybsl, uisp, etc
deluge
PC Applications: Talking to Motes
Java, C or Python app
sf
packet libs
packet libs
TinyOS Installation
VMware Player
Ubuntu & Dropbox
TinyOS
g++/python