Upload
julie-long
View
218
Download
1
Embed Size (px)
Citation preview
April 15, 2005 TinyOS: A Component Based OS Page 1 of 27
TinyOS
A Component-Based Operating System for Networked Embedded Systems
Tom Bush
Graduate College of Union University
April 15, 2005 TinyOS: A Component Based OS Slide 2 of 27
Overview
Networked Embedded Systems Environment of TinyOS Implementation of TinyOS - nesC
Component model Concurrency model Compiler features
Basic Example Evaluation of nesC implementation
April 15, 2005 TinyOS: A Component Based OS Slide 3 of 27
Networked Embedded Systems
What is a networked embedded system? An interacting group of devices with computing
components embedded in purpose built devices Usually perform single task such as monitoring
an environmental characteristic Connected through some type of network Usually not mobile, typically very small Little if any human interaction
April 15, 2005 TinyOS: A Component Based OS Slide 4 of 27
Networked Embedded Systems
How NESs are used Structural integrity of buildings,
bridges Monitor vehicle movements/traffic Monitor movements of animals Utilities data collection Military uses
Replace minefields Sniper detection
April 15, 2005 TinyOS: A Component Based OS Slide 5 of 27
Networked Embedded Systems
RF Mote Mica2
Golum DustweC
UCB Spec
April 15, 2005 TinyOS: A Component Based OS Slide 6 of 27
Physical Constraints on NESs
Relatively slow processors Small amount of memory and storage Limited battery life Must be self contained Radio or other communication Asynchronous hardware triggers
April 15, 2005 TinyOS: A Component Based OS Slide 7 of 27
What is the TinyOS?
An event-based operating system designed for wireless networked sensors
Uses component based architecture Supports concurrent operations required by
networked sensors Special purpose Single application (no multi-programming) Supports tasks (not threads)
April 15, 2005 TinyOS: A Component Based OS Slide 8 of 27
TinyOS Environment
NES operating system must support Component based architecture Tasks and event-based concurrency Split-phase operations
Commands Events
April 15, 2005 TinyOS: A Component Based OS Slide 9 of 27
Introducing nesC
A programming language for NESs An extension of C Static language, no dynamic memory
allocation Supports concept of components and
event-based concurrency model Whole program analysis & optimization
April 15, 2005 TinyOS: A Component Based OS Slide 10 of 27
nesC Component Model
Two types of components Modules Configurations
Both types use and provide interfaces Only point of access to components Bi-directional; commands and events Detailed implementation provided by
components
Component A Component B
April 15, 2005 TinyOS: A Component Based OS Slide 11 of 27
Interfaces
A collection of 1 or more command and events
Defines interaction boundary between components
Providing component must implement the start and stop commands
Using component must implement the fired event
interface Timer {command result_t start(
char type, uint32_t interval);
command result_t stop();
event result_t fired();}
April 15, 2005 TinyOS: A Component Based OS Slide 12 of 27
Components
Configurations Wire other
components together
Connect interfaces used by one component to those provided by another
Top level application
Modules Provide application
code Implement one or
more interfaces
April 15, 2005 TinyOS: A Component Based OS Slide 13 of 27
Example applicationTop Level Application
Component C
Component A
Component B
Component EComponent D
ProvidesUses
April 15, 2005 TinyOS: A Component Based OS Slide 14 of 27
Component Implementations
configuration Blink {}implementation {
components Main, BlinkM, SingleTimer, LedsC;
Main.StdControl -> SingleTimer.StdControl; Main.StdControl -> BlinkM.StdControl; BlinkM.Timer -> SingleTimer.Timer; BlinkM.Leds -> LedsC;}
April 15, 2005 TinyOS: A Component Based OS Slide 15 of 27
Component Implementationsmodule BlinkM {
provides interface StdControl;uses {
interface Timer;interface Leds;
}}implementation {
command result_t StdControl.init( ) {call Leds.init( );return SUCCESS;
}
command result_t stdControl.start[int id](char type, uint32_t interval) {
return call Timer.start(Timer_Repeat, 1000);}
command result_t StdControl.stop[int id]( ) {return call Timer.stop( );
}
event result_t Timer.fired( ) { call Leds.redToggle( ); return SUCCESS; }}
April 15, 2005 TinyOS: A Component Based OS Slide 16 of 27
Concurrency Model
Two types of concurrency in TinyOS Tasks
Travel down application graph (to HW) Events (HW Interrupts)
Travel up application graph (away from HW)
April 15, 2005 TinyOS: A Component Based OS Slide 17 of 27
Tasks
Delayed computations Posted by components
Calls are non-blocking Handled by event scheduler (FIFO) Run to completion Can be preempted Do not preempt
April 15, 2005 TinyOS: A Component Based OS Slide 18 of 27
Events
Signify either completion of a command (split-phase
operation) Hardware interrupt (environmental trigger)
Run to completion Preempt tasks and other events Can call commands, post tasks, signal other
events
April 15, 2005 TinyOS: A Component Based OS Slide 19 of 27
Event/Task Exampletask void HandleFire() {
uint8_t i; setIntervalFlag = 1;if (mState) {
for (i=0;i<NUM_TIMERS;i++) {if (mState&(0x1<<i)) {
mTimerList[i].ticksLeft -= (mInterval+1) ; if (mTimerList[i].ticksLeft<=2) {
if (mTimerList[i].type==TIMER_REPEAT) {mTimerList[i].ticksLeft += mTimerList[i].ticks;
} else {// one shot timer mState &=~(0x1<<i);
}enqueue(i);post signalOneTimer();
}}
}}adjustInterval();
}
async event result_t Clock.fire() {post HandleFire();return SUCCESS;
}
April 15, 2005 TinyOS: A Component Based OS Slide 20 of 27
Concurrency Model
Asynchronous code (AC) – reachable from at least one interrupt handler
Synchronous code (SC) – code only reachable from tasks
To prevent race conditions Shared variables updated by SC only or in atomic code
Must implement “atomic” keyword to disable interrupts when processing SC
Keep atomic sections short to keep system reactive
April 15, 2005 TinyOS: A Component Based OS Slide 21 of 27
Component Model Analysis
Application ModulesOS Modules
(% of full OS)
OS Modules (% of
application)Lines
OS Lines(% of
full OS)
OS Lines (% of
application)
Surge 31 27 (25%) 87% 2860 2160 (14%) 76%
Maté 35 28 (25%) 80% 4736 2524 (17%) 53%
TinyDB 65 38 (35%) 58% 11681 4160 (28%) 36%
April 15, 2005 TinyOS: A Component Based OS Slide 22 of 27
Concurrency Model Analysis
nesC version 1.0 No race condition analysis No atomic function
nesC version 1.1 Added both 103 race conditions Fixed by tasking or atomic statements
April 15, 2005 TinyOS: A Component Based OS Slide 23 of 27
Fixing race conditions
/* Contains a race: */
if (state == IDLE) { state = SENDING; count++; // send a packet
}
/* Fixed Version */
uint8_t oldState;atomic {
oldState = state;if (state == IDLE) {
state = SENDING;}
}
if (oldState == IDLE) {count++;// send a packet
}
April 15, 2005 TinyOS: A Component Based OS Slide 24 of 27
Compiler Optimization
Uses component model restrictions: Eliminate unreachable code Inline small functions
ApplicationCode Size Code
ReductionInlined Noninlined
Surge 14794 16984 12%
Maté 25040 27458 9%
TinyDB 64910 71724 10%
April 15, 2005 TinyOS: A Component Based OS Slide 25 of 27
Support FunctionsTinyOS Simulator
/*====== Core mote modes =============*/ DBG_BOOT = DBG_MODE(0), /* the boot sequence */ DBG_CLOCK = DBG_MODE(1), /* clock */ DBG_TASK = DBG_MODE(2), /* task stuff */ DBG_SCHED = DBG_MODE(3), /* switch, scheduling */ DBG_SENSOR = DBG_MODE(4), /* sensor readings */ DBG_LED = DBG_MODE(5), /* LEDs */ DBG_CRYPTO = DBG_MODE(6), /* Cryptography/security */
/*====== Networking modes ============*/ DBG_ROUTE = DBG_MODE(7), /* network routing */ DBG_AM = DBG_MODE(8), /* Active Messages */ DBG_CRC = DBG_MODE(9), /* packet CRC stuff */ DBG_PACKET = DBG_MODE(10), /* Packet level stuff */ DBG_ENCODE = DBG_MODE(11), /* Radio encoding/decoding */ DBG_RADIO = DBG_MODE(12), /* radio bits */
April 15, 2005 TinyOS: A Component Based OS Slide 26 of 27
Conclusions
nesC implements TinyOS concurrency and component models effectively ↑
nesC also provides compile time optimizations and race condition detection ↑
Component swapping ↑ TOSSIM and TinyViz support functions ↑ Rapidly changing hardware ↓ Everyone knows C ↑
April 15, 2005 TinyOS: A Component Based OS Slide 27 of 27
Conclusions
TinyOS provides great interface for distributed applications ↑
Not perfect for all applications ↓ 18 pages of code to blink 1 LED?