Network Kernel Architectures and Implementation (01204423) Single-Node Architectures Chaiporn Jaikaeo Department of Computer Engineering.

Slides:



Advertisements
Similar presentations
Single Node Architecture 1 By: Mahdi Sadeghizadeh Website: Sadeghizadeh.ir Advanced Computer Networks.
Advertisements

CSE 5392By Dr. Donggang Liu1 CSE 5392 Sensor Network Security Introduction to Sensor Networks.
Overview: Chapter 7  Sensor node platforms must contend with many issues  Energy consumption  Sensing environment  Networking  Real-time constraints.
PERFORMANCE MEASUREMENTS OF WIRELESS SENSOR NETWORKS Gizem ERDOĞAN.
1 University of Freiburg Computer Networks and Telematics Prof. Christian Schindelhauer Wireless Sensor Networks 6th Lecture Christian Schindelhauer.
Energy in sensor nets. Where does the power go Components: –Battery -> DC-DC converter –CPU + Memory + Flash –Sensors + ADC –DAC + Audio speakers –Display.
PEDS September 18, 2006 Power Efficient System for Sensor Networks1 S. Coleri, A. Puri and P. Varaiya UC Berkeley Eighth IEEE International Symposium on.
Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.
Mica: A Wireless Platform for Deeply Embedded Networks Jason Hill and David Culler Presented by Arsalan Tavakoli.
Jason Hill, Robert Szewczyk, Alec Woo Spring 2000 TinyOS Operating System for Networked Sensors Networked SensorsSystem Structure Composing Components.
Surrey Space Centre, University of Surrey, Guildford, Surrey, GU2 7XH ESA Wireless Sensor Motes Study George Prassinos, SSC, University of Surrey.
Tiny OS Optimistic Lightweight Interrupt Handler Simon Yau Alan Shieh CS252, CS262A, Fall The.
Integrated  -Wireless Communication Platform Jason Hill.
Computer Networks Group Universität Paderborn Ad hoc and Sensor Networks Single Node Architecture and Platforms Instructor: Wen, Chih-Yu Department of.
Generic Sensor Platform for Networked Sensors Haywood Ho.
CS526 Wireless Sensor Networks Instructor: KD Kang.
1 University of Freiburg Computer Networks and Telematics Prof. Christian Schindelhauer Wireless Sensor Networks 5th Lecture Christian Schindelhauer.
1 TinyOS Mohammad Rahimi CSCI599-Spring Motivation  The new class of distributed tiny devices  The new generation of software.
TinyOS Software Engineering Sensor Networks for the Masses.
1 University of Freiburg Computer Networks and Telematics Prof. Christian Schindelhauer Wireless Sensor Networks 3rd Lecture Christian Schindelhauer.
2008EECS Embedded Network Programming nesC, TinyOS, Networking, Microcontrollers Jonathan Hui University of California, Berkeley.
A Framework for Patient Monitoring A. L. Praveen Aroul, William Walker, Dinesh Bhatia Department of Electrical Engineering University of Texas at Dallas.
Introduction to TinyOS. Networking Open Experimental Platform Small microcontroller 8 kB code 512 B data Simple, low-power radio 10 kbps ASK EEPROM (32.
Intel ® Research mote Ralph Kling Intel Corporation Research Santa Clara, CA.
Microcontroller: Introduction
1 Energy Efficient Communication in Wireless Sensor Networks Yingyue Xu 8/14/2015.
Spring 2000, 4/27/00 Power evaluation of SmartDust remote sensors CS 252 Project Presentation Robert Szewczyk Andras Ferencz.
MICA: A Wireless Platform for Deeply Embedded Networks
Architectures and Applications for Wireless Sensor Networks (204525) Single-Node Architecture Chaiporn Jaikaeo Department of Computer.
A System Architecture for Networked Sensors Jason Hill, Robert Szewczyk, Alec Woo, Seth Hollar, David Culler, Kris Pister
1 Lecture 12: Factors Influencing Sensor Network Design (textbook slides) Ian F. Akyildiz, Mehmet Can Vuran, “Wireless Sensor Networks” WILEY Publisher,
DESIGN & IMPLEMENTATION OF SMALL SCALE WIRELESS SENSOR NETWORK
April 15, 2005TinyOS: A Component Based OSPage 1 of 27 TinyOS A Component-Based Operating System for Networked Embedded Systems Tom Bush Graduate College.
1 An Adaptive Energy-Efficient MAC Protocol for Wireless Sensor Networks The First ACM Conference on Embedded Networked Sensor Systems (SenSys 2003) November.
Operating System Review September 10, 2012Introduction to Computer Security ©2004 Matt Bishop Slide #1-1.
Architectures and Applications for Wireless Sensor Networks ( ) Sensor Node Programming II (UART and Radio) Chaiporn Jaikaeo
(More) Interfacing concepts. Introduction Overview of I/O operations Programmed I/O – Standard I/O – Memory Mapped I/O Device synchronization Readings:
Overview of Sensor Networks David Culler Deborah Estrin Mani Srivastava.
Dhanshree Nimje Smita Khartad
System Architecture Directions for Networked Sensors Jason Hill, Robert Szewczyk, Alec Woo, Seth Hollar, David Culler, Kris Pister Presented by Yang Zhao.
Simulation of Distributed Application and Protocols using TOSSIM Valliappan Annamalai.
System Architecture of Sensor Network Processors Alan Pilecki.
The University of Iowa. Copyright© 2005 A. Kruger 1 Introduction to Wireless Sensor Networks Energy Considerations in WSNs I 3 February 2005.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
System Architecture Directions for Networked Sensors Jason Hill, Robert Szewczyk, Alec Woo, Seth Hollar, David Culler, Kris Pister Presenter: James.
Xiong Junjie Node-level debugging based on finite state machine in wireless sensor networks.
CS 546: Intelligent Embedded Systems Gaurav S. Sukhatme Robotic Embedded Systems Lab Center for Robotics and Embedded Systems Computer Science Department.
Chapter 13 – I/O Systems (Pgs ). Devices  Two conflicting properties A. Growing uniformity in interfaces (both h/w and s/w): e.g., USB, TWAIN.
TinyOS Sandeep Gupta. Operating System (OS) What is an OS? Main functions  Process management  Memory management  Resource management Traditional OSs.
Operating Systems: Summary INF1060: Introduction to Operating Systems and Data Communication.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Why does it need? [USN] ( 주 ) 한백전자 Background Wireless Sensor Network (WSN)  Relationship between Sensor and WSN Individual sensors are very limited.
Software Architecture of Sensors. Hardware - Sensor Nodes Sensing: sensor --a transducer that converts a physical, chemical, or biological parameter into.
- Pritam Kumat - TE(2) 1.  Introduction  Architecture  Routing Techniques  Node Components  Hardware Specification  Application 2.
Introduction to Operating Systems Concepts
INTRODUCTION TO WIRELESS SENSOR NETWORKS
Simulation of Distributed Application and Protocols using TOSSIM
Microcontrollers & GPIO
Wireless Mesh Networks
Ultra-Low-Power Sensor Nodes Featuring a Virtual Runtime Environment
Wireless Sensor Networks 3rd Lecture
Getting the Most Out of Low Power MCUs
Lecture Topics: 11/1 General Operating System Concepts Processes
Node Programming Models
Wireless Sensor Networks and Internet of Things
Wireless Sensor Networks
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Network Kernel Architectures and Implementation ( ) Single-Node Architectures Chaiporn Jaikaeo Department of Computer Engineering Kasetsart University Materials taken from lecture slides by Karl and Willig Contiki materials taken from slides by Adam Dunkels

Outline Main components of a wireless sensor node Main components of a wireless sensor node  Processor, radio, sensors, batteries Energy supply and consumption Energy supply and consumption Operating systems and execution environments Operating systems and execution environments  IWING's MoteLib  TinyOS  Contiki Sample implementations Sample implementations

Main Components Communication Device Controller Sensors/ Actuators Power Supply Memory

Controller Main options: Main options:  Microcontroller – general purpose processor, optimized for embedded applications, low power consumption  DSP – optimized for signal processing tasks, not suitable here  FPGA – may be good for testing  ASIC – only when peak performance is needed, no flexibility

Microcontroller Examples Texas Instruments MSP430 Texas Instruments MSP430  16-bit RISC core, 4 MHz  Up to 120 KB flash  2-10 KB RAM  12 ADCs, RT clock Atmel ATMega Atmel ATMega  8-bit controller, 8 MHz  Up to 128KB Flash  4 KB RAM

Communication Device Medium options Medium options  Electromagnetic, RF  Electromagnetic, optical  Ultrasound Radio Transceiver radio wave bit stream

Transceiver Characteristics Service to upper layer: packet, byte, bit Service to upper layer: packet, byte, bit Power consumption Power consumption Supported frequency, multiple channels Supported frequency, multiple channels Data rate Data rate Modulation Modulation Power control Power control Communication range Communication range etc. etc.

Transceiver States Transceivers can be put into different operational states, typically: Transceivers can be put into different operational states, typically:  Transmit  Receive  Idle – ready to receive, but not doing so  Sleep – significant parts of the transceiver are switched off RxTxIdle Sleep

Wakeup Receivers When to switch on a receiver is not clear When to switch on a receiver is not clear  Contention-based MAC protocols: Receiver is always on  TDMA-based MAC protocols: Synchronization overhead, inflexible Desirable: Receiver that can (only) check for incoming messages Desirable: Receiver that can (only) check for incoming messages  When signal detected, wake up main receiver for actual reception  Ideally: Wakeup receiver can already process simple addresses  Not clear whether they can be actually built, however

Optical Communication Optical communication can consume less energy Optical communication can consume less energy Example: passive readout via corner cube reflector Example: passive readout via corner cube reflector  Laser is reflected back directly to source if mirrors are at right angles  Mirrors can be “tilted” to stop reflecting  Allows data to be sent back to laser source 200 µm

Ultra Wideband Communication Use a large bandwidth, do not modulate, simply emit a “burst” of power Use a large bandwidth, do not modulate, simply emit a “burst” of power Advantages Advantages  Pretty resilient to multi-path propagation  Very good ranging capabilities  Good wall penetration ter/Vol15/Vol15_01/2-UWB-1.jpg

Sensors Main categories Main categories  Passive, omnidirectional  Examples: light, thermometer, microphones, hygrometer, …  Passive, narrow-beam  Example: Camera  Active sensors  Example: Radar Important parameter: Area of coverage Important parameter: Area of coverage  Which region is adequately covered by a given sensor?

Outline Main components of a wireless sensor node Main components of a wireless sensor node  Processor, radio, sensors, batteries Energy supply and consumption Energy supply and consumption Operating systems and execution environments Operating systems and execution environments  IWING's MoteLib  TinyOS  Contiki Example implementations Example implementations

Energy Supply Goal: provide as much energy as possible at smallest cost/volume/weight/recharge time/longevity Goal: provide as much energy as possible at smallest cost/volume/weight/recharge time/longevity  In WSN, recharging may or may not be an option Options Options  Primary batteries – not rechargeable  Secondary batteries – rechargeable, only makes sense in combination with some form of energy harvesting

Energy Supply - Requirements Low self-discharge Low self-discharge Long shelf life Long shelf life Capacity under load Capacity under load Efficient recharging at low current Efficient recharging at low current Good relaxation properties (seeming self- recharging) Good relaxation properties (seeming self- recharging) Voltage stability (to avoid DC-DC conversion) Voltage stability (to avoid DC-DC conversion)

Battery Examples Energy per volume (Joule/cc): Energy per volume (Joule/cc): Primary batteries ChemistryZinc-airLithiumAlkaline Energy (J/cm 3 ) Secondary batteries ChemistryLithiumNiMHNiCd Energy (J/cm 3 )

Energy Harvesting How to recharge a battery? How to recharge a battery?  A laptop: easy, plug into wall socket in the evening  A sensor node? – Try to scavenge energy from environment Ambient energy sources Ambient energy sources  Light ! solar cells – between 10  W/cm 2 and 15 mW/cm 2  Temperature gradients – 80  W/cm 1 V from 5K difference  Vibrations – between 0.1 and  W/cm 3  Pressure variation (piezo-electric) – 330  W/cm 2 from the heel of a shoe  Air/liquid flow (MEMS gas turbines)

Portable Solar Chargers Foldable Solar Chargers Foldable Solar Chargers  Solargorilla Solargorilla  solargorilla/ solargorilla/ solargorilla/

Energy Supply - Comparison

Energy Consumption Rough estimation Rough estimation  Number of instructions  Energy per instruction: 1 nJ  Small battery (“smart dust”): 1 J = 1 Ws  Corresponds: 10 9 instructions!  Lifetime  Or: Require a single day operational lifetime = 24x60x60 = s  1 Ws / 86400s  11.5  W as max sustained power consumption!

Multiple Power Consumption Modes Do not run sensor node at full operation all the time Do not run sensor node at full operation all the time  If nothing to do, switch to power safe mode Typical modes Typical modes  Controller: Active, idle, sleep  Radio mode: Turn on/off transmitter/receiver, both  Strongly depends on hardware Questions: Questions:  When to throttle down?  How to wake up again?

Energy Consumption Figures TI MSP MHz, 3V): TI MSP MHz, 3V):  Fully operation 1.2 mW  One fully operational mode + four sleep modes  Deepest sleep mode 0.3  W – only woken up by external interrupts (not even timer is running any more) Atmel ATMega Atmel ATMega  Operational mode: 15 mW active, 6 mW idle  Six modes of operations  Sleep mode: 75  W

Switching Between Modes Simplest idea: Greedily switch to lower mode whenever possible Simplest idea: Greedily switch to lower mode whenever possible Problem: Time and power consumption required to reach higher modes not negligible Problem: Time and power consumption required to reach higher modes not negligible P active P sleep timet event t1t1 E saved  down  up E overhead

Should We Switch? Switching modes is beneficial if Switching modes is beneficial if which is equivalent to E overhead < E saved

Dynamic Voltage Scaling (DVS) Rationale: Rationale:  Power consumption P depends on  Clock frequency  Square of supply voltage  P  f  V 2  Lower clock allows lower supply voltage  Easy to switch to higher clock But: execution takes longer But: execution takes longer

Memory Power Consumption Crucial part: FLASH memory Crucial part: FLASH memory  Power for RAM almost negligible FLASH writing/erasing is expensive FLASH writing/erasing is expensive  Example: FLASH on Mica motes  Reading:  1.1 nAh per byte  Writing:  83.3 nAh per byte Write energy varies greatly Write energy varies greatly  Difference ratio up to 900:1 between different types

Computation vs. Communication Energy Cost Sending one bit vs. running one instruction Sending one bit vs. running one instruction  Energy ratio up to 2900:1  I.e., send & receive one KB = running three million instruction So, try to compute instead of communicate whenever possible So, try to compute instead of communicate whenever possible Key technique – in-network processing Key technique – in-network processing  Exploit compression schemes, intelligent coding schemes, aggregate data, …

Outline Main components of a wireless sensor node Main components of a wireless sensor node  Processor, radio, sensors, batteries Energy supply and consumption Energy supply and consumption Operating systems and execution environments Operating systems and execution environments  IWING's MoteLib  TinyOS  Contiki Example implementations Example implementations

Mica Motes By Crossbow, USA By Crossbow, USA MCU: MCU:  Atmel ATMega128L Comm: RFM TR1000 Comm: RFM TR1000

EYES Nodes By Infineon, EU By Infineon, EU MCU: TI MSP430 MCU: TI MSP430 Comm: Infineon radio modem TDA5250 Comm: Infineon radio modem TDA5250

Btnote By ETH Zurich By ETH Zurich MCU: MCU:  Atmel ATMega128L Comm: Comm:  Bluetooth  Chipcon CC1000

ScatterWeb By Computer Systems & Telematics group, Freie Universitat Berlin By Computer Systems & Telematics group, Freie Universitat Berlin MCU: MCU:  TI MSP 430 Comm: Comm:  Bluetooth, I 2 C, CAN

Tmote Sky By Sentilla (formerly Moteiv), USA By Sentilla (formerly Moteiv), USA MCU: MCU:  TI MSP430 Comm: Comm:  Chipcon CC2420 (IEEE )

IRIS Motes By Crossbow, USA By Crossbow, USA MCU: ATMega128L MCU: ATMega128L Comm: Atmel's RF230 (IEEE ) Comm: Atmel's RF230 (IEEE ) 3x radio range compared to Tmote 3x radio range compared to Tmote "Postage-stamp" form factor costs as low as $29 per unit (when purchased in large volumes) "Postage-stamp" form factor costs as low as $29 per unit (when purchased in large volumes)

IMote2 By Intel Research By Intel Research MCU: PXA271 XScale MCU: PXA271 XScale Comm: Chipcon CC2420 (IEEE ) Comm: Chipcon CC2420 (IEEE )

Other WSN-Capable Modules Many low-cost, wireless SoC modules already available Many low-cost, wireless SoC modules already available HopeRF 433 MHz module based on Silicon Labs's SoC (~6 USD/module) Synapse Wireless 2.4 GHz module based on Atmel's SoC SNAP OS / embedded Python (~25 USD/module)

IWING-MRF Motes Radio transceiver 8-bit AVR Microcontroller USB Connector (for reprogramming and power) Analog/Digital sensor connectors External battery connector UART Connector Morakot Saravanee, Chaiporn Jaikaeo, Intelligent Wireless Network Group (IWING), KU

IWING-MRF Motes Built from off-the-shelf components Built from off-the-shelf components Built-in USB boot loader Built-in USB boot loader  Reprogrammed via USB Easy to modify and extend hardware Easy to modify and extend hardware

IWING-MRF Mote Processor Processor  8-bit AVR microcontroller ATMega88/168/328, 12 MHz  16KB flash, 2KB RAM RF transceiver RF transceiver  Microchip's MRF24J40A/B/C, 2.4GHz IEEE  SPI interface External connectors External connectors  6 ADC connectors (can also be used as TWI)  1 UART Power options Power options  3 – 3.6 VDC  USB or 2 AA batteries

IWING-JN Motes Built on JN5168 wireless microcontroller Built on JN5168 wireless microcontroller 32-bit RISC architecture 32-bit RISC architecture  Operating at 32 MHz  256 KB flash, 32 KB RAM IEEE RF transceiver IEEE RF transceiver 4 ADC channels (10-bit) 4 ADC channels (10-bit) ~20 general-purpose digital I/O ~20 general-purpose digital I/O 2 UART interfaces 2 UART interfaces Hardware access via C-language API Hardware access via C-language API

Outline Main components of a wireless sensor node Main components of a wireless sensor node  Processor, radio, sensors, batteries Energy supply and consumption Energy supply and consumption Operating systems and execution environments Operating systems and execution environments  IWING's MoteLib  TinyOS  Contiki Example implementations Example implementations

Operating System Challenges Usual operating system goals Usual operating system goals  Make access to device resources abstract (virtualization)  Protect resources from concurrent access Usual means Usual means  Protected operation modes of the CPU  Process with separate address spaces These are not available in microcontrollers These are not available in microcontrollers  No separate protection modes, no MMU  Would make devices more expensive, more power- hungry

Possible OS Options Try to implement “as close to an operating system” on WSN nodes Try to implement “as close to an operating system” on WSN nodes  Support for processes!  Possible, but relatively high overhead Stay away with operating system Stay away with operating system  There is only a single “application” running on a WSN node  No need to protect malicious software parts from each other  Direct hardware control by application might improve efficiency

Possible OS Options Currently popular approach Currently popular approach  No OS, just a simple run-time environment  Enough to abstract away hardware access details  Biggest impact: Unusual programming model

Concurrency Support Simplest option: No concurrency, sequential processing of tasks Simplest option: No concurrency, sequential processing of tasks  Risk of missing data  Should support interrupts/asynchronous operations Poll sensor Process sensor data Poll transceiver Process received packet

Processes/Threads Based on interrupts, context switching Based on interrupts, context switching Difficulties Difficulties  Too many context switches  Most tasks are short anyway  Each process required its own stack Handle sensor process Handle packet process OS-mediated process switching

Event-Based Concurrency Event-based programming model Event-based programming model  Perform regular processing or be idle  React to events when they happen immediately  Basically: interrupt handler Must not remain in interrupt handler too long Must not remain in interrupt handler too long  Danger of loosing events Idle/regular processing Radio event handler Sensor event handler

Components Instead of Processes An abstraction to group functionality An abstraction to group functionality Typically fulfill only a single, well-defined function Typically fulfill only a single, well-defined function  E.g., individual functions of a networking protocol Main difference to processes: Main difference to processes:  Component does not have an execution  Components access same address space, no protection against each other

Event-based Protocol Stack Usual networking API: sockets Usual networking API: sockets  Issue: blocking calls to receive data  Not match to event-based OS API is therefore also event-based API is therefore also event-based  E.g., Tell some component that some other component wants to be informed if and when data has arrived  Component will be posted an event once this condition is met  Details: see IWING's MoteLib and TinyOS

Outline Main components of a wireless sensor node Main components of a wireless sensor node  Processor, radio, sensors, batteries Energy supply and consumption Energy supply and consumption Operating systems and execution environments Operating systems and execution environments  IWING's MoteLib  TinyOS  Contiki Example implementations Example implementations

Case Study: IWING's MoteLib Developed by IWING (CPE, KU) along with IWING motes Developed by IWING (CPE, KU) along with IWING motes Provides hardware abstraction and virtualization in standard C interfaces Provides hardware abstraction and virtualization in standard C interfaces Follows event-based programming model Follows event-based programming model

MoteLib Architecture and API Software Hardware

Example: Count and Send Node#0 runs a counter and broadcasts its value Node#0 runs a counter and broadcasts its value Other nodes display received values on LEDs Other nodes display received values on LEDs

#include Timer timer; uint8_t counter; void timerFired(Timer *t) { counter++; radioRequestTx(BROADCAST_ADDR, 0, (char*)&counter, sizeof(counter), NULL); } void receive(Address source, MessageType type, void *message, uint8_t len) { ledSetValue(((char*)message)[0]); } void boot() { counter = 0; if (getAddress() == 0) { timerCreate(&timer); timerStart(&timer, TIMER_PERIODIC, 500, timerFired); } else radioSetRxHandler(receive); } Example: Count and Send called when node receives a radio packet called when timer expires called when node booted

Outline Main components of a wireless sensor node Main components of a wireless sensor node  Processor, radio, sensors, batteries Energy supply and consumption Energy supply and consumption Operating systems and execution environments Operating systems and execution environments  IWING's MoteLib  TinyOS  Contiki Example implementations Example implementations

Case Study: TinyOS Developed by UC Berkeley as runtime environment for their motes Developed by UC Berkeley as runtime environment for their motes nesC (network embedded system C) as adjunct programming language nesC (network embedded system C) as adjunct programming language Design aspects: Design aspects:  Component-based system  Components interact by exchanging asynchronous events  Components form a program by wiring them together (akin to VHDL – hardware description language) Website Website

TinyOS Components Components Components  Frame – state information  Tasks – normal execution program  Command handlers  Event handlers Hierarchically arranged Hierarchically arranged  Events are passed upward from hardware  Commands are passed downward TimerComponent setRate fire initstart stopfired Event handlers Command handlers Frame Tasks

Interfaces Many commands/events can be grouped Many commands/events can be grouped nesC structures corresponding commands/events into interface types nesC structures corresponding commands/events into interface types Example: Structure timer into three interfaces Example: Structure timer into three interfaces  StdCtrl  Timer  Clock The TimerComponent The TimerComponent  Provides: StdCtrl, Timer  Uses: Clock Clock setRate fire initstart stopfiredTimerStdCtrl TimerComponent

Forming New Components Clock HWClock Clock TimerStdCtrl TimerComponent "Clock" interface provider "Clock" interface user initStdCtrl start stopfiredTimer CompleteTimer

Sample nesC Code configuration CompleteTimer { provides { interface StdCtrl; interface Timer; } implementation { components TimerComponent, HWClock; StdCtrl = TimerComponent.StdCtrl; Timer = TimerComponent.Timer; TimerComponent.Clock -> HWClock.Clock; }

Active Messages Route map routersensor app Sample App Configuration RFM Radio byte Radio Packet UART Serial Packet ADC Tempphoto clocks bit byte packet application HW SW

Command/event handlers must run to completion Command/event handlers must run to completion  Must not wait an indeterminate amount of time  Only a request to perform some action Tasks can perform arbitrary, long computation Tasks can perform arbitrary, long computation  Can be interrupted by handlers  Also have to be run to completion  Preemptive multitasking not implemented Handlers versus Tasks Idle / Running task task queue Sensor event handler Radio event handler

Split-Phase Operations Request Data Blocking SensorController Synchronous Operation Asynchronous Operation SensorController Request Ready Ack Read Data

Outline Main components of a wireless sensor node Main components of a wireless sensor node  Processor, radio, sensors, batteries Energy supply and consumption Energy supply and consumption Operating systems and execution environments Operating systems and execution environments  IWING's MoteLib  TinyOS  Contiki Example implementations Example implementations

Case Study: Contiki Multitasking OS developed by Swedish Institute of Computer Science (SICS) Multitasking OS developed by Swedish Institute of Computer Science (SICS) The kernel is event driven The kernel is event driven Processes are protothreads Processes are protothreads  Very light weight threads  Provide a linear, thread-like programming model Comes with various communication stacks: uIP, uIPv6, Rime Comes with various communication stacks: uIP, uIPv6, Rime Website Website

Problem with Multithreading Four threads, each with its own stack Four threads, each with its own stack Thread 1Thread 2Thread 3Thread 4

Events Require One Stack Four event handlers, one stack Four event handlers, one stack Eventhandler 1Eventhandler 2Eventhandler 3 Stack is reused for every event handler Eventhandler 4

Problem with Event-based Model Threads: sequential code flowEvents: unstructured code flow Very much like programming with GOTOs

Protothreads Protothreads require only one stack Protothreads require only one stack E.g, four protothreads, each with its own stack E.g, four protothreads, each with its own stack Events require one stack Protothread 1 Protothread 2Protothread 3Protothread 4 Just like events

PROCESS_THREAD(hello_world_process, ev, data) { PROCESS_BEGIN(); PROCESS_BEGIN(); printf(“Hello, world!\n”); printf(“Hello, world!\n”); while(1) { while(1) { PROCESS_WAIT_EVENT(); PROCESS_WAIT_EVENT(); } PROCESS_END(); PROCESS_END();} Contiki Processes Contiki processes are protothreads Contiki processes are protothreads

Contiki's Cooja Simulator

Summary The need to build cheap, low-energy, (small) devices has various consequences The need to build cheap, low-energy, (small) devices has various consequences  Much simpler radio frontends and controllers  Energy supply and scavenging are a premium resource  Power management is crucial Unique programming challenges of embedded systems Unique programming challenges of embedded systems  Concurrency without support, protection  De facto standard:  Event-based programming model: TinyOS  Multithreaded programming model: Contiki