TinyOS Nesc PDF
TinyOS Nesc PDF
Outline
● Wireless sensor networks and TinyOS
● Networked embedded system C (nesC)
– Components
– Interfaces
– Concurrency model
– Tool chain
● Issues / conclusion
Wireless Sensor Networks
● Vision: ubiquitous computing
● Extreme dynamics
● Interact with environment using sensors and radio
● Immense scale
● Limited access
● Small, cheap, low-power systems
Concepts in Sensor Networks
● In-network processing and data aggregation
– Radio activity 1000 times as expensive as processing
● Duty-cycling: different modes of operation
– Power down unused hardware
● Systems run a single application
● Applications are deeply tied to hardware
– Require customized and optimized OS
Challenges
● Limited resources: energy consumption dominates
● Concurrency: driven by interaction with environment
● Soft real-time requirements
● Reliability: reduce run-time errors, e.g. races
● High diversity of platforms
● No well-defined software/hardware boundary
TinyOS
● Component-based architecture
– Reusable system components: ADC, Timer, Radio
● Tasks and event-based concurrency
– No user-space or context switching supported by hardware
– Tasks run to completion only preempted by interrupts
● All long-latency operations are split-phase
– Operation request and completion are separate functions
Introducing nesC
● A “holistic” approach to networked embedded
systems
● Supports and reflects TinyOS's design
● Extends a subset of C
● A static language
– All resources known at compile-time
– Call-graph fully known at compile-time
Design Decisions for nesC
● Components
● Bidirectional interfaces
● Simple expressive concurrency model
● Whole-program analysis
Components
● Challenge: platform diversity, flexible SW/HW
boundary, applications deeply tied to hardware
● Encourages modular design
● Restrict access to private data
● Allow underlying implementations to be replaced
easily
● Can abstract HW using thin wrappers
● Allow specialization of applications to hardware
Example Component Graph
Module Components
● Modules implement application code
● Modules have private state
– Sharing of data among components is discouraged
● Convention:
– Module names end with 'M', e.g. BlinkM
– Module variables start with 'm_', e.g. m_timers
Configuration Components
● Configurations wire other components together
● All applications have a top-level configuration
● A component interface may be wired zero or more
times
– Used for StdControl to implement power management
● Convention:
– Configuration names end with 'C', e.g. TimerC
(unless it is the top-level configuration ;-)
Modules and Configurations
/* BlinkM.nc */ /* Blink.nc */
module BlinkM { configuration Blink {
provides interface StdControl as Control; } implementation {
uses interface Timer; /* Declare used components. */
uses interface Leds; components Main, BlinkM, SingleTimer, LedsC;
} implementation {
command result_t Control.init() { /* Wire components together. */
call Leds.init(); Main.StdControl -> SingleTimer.StdControl;
return SUCCESS; Main.StdControl -> BlinkM.StdControl;
} BlinkM.Timer -> SingleTimer.Timer;
command result_t Control.start() { /* ... */ } BlinkM.Leds -> LedsC;
command result_t Control.stop() { /* ... */ } }
interface Timer {
command result_t start(char type, uint32_t interval);
command result_t stop();
event result_t fired();
}
/* SyncAlarm.nc */
interface SyncAlarm<Precision_t> {
command result_t armCountdown(Precision_t timeout);
command result_t armAlarmClock(Precision_t time);
command result_t stop();
event result_t alarm();
}
Parameterized Interfaces
module TimerM {
provides interface Timer[uint8_t id];
} implementation {
/* ... */
Timer_t m_timers[NUM_TIMERS];
command result_t Timer.isSet[uint8_t timer]() {
return m_timers[timer].isset;
}
task void timerCheck() {
uint8_t timer;
for (timer = 0; timer < NUM_TIMERS; timer++)
if (m_timers[timer].fired)
signal Timer.fired[timer]();
}
/* ... */
}