Lecture 2: Software Platforms

Slides:



Advertisements
Similar presentations
How to use TinyOS Jason Hill Rob Szewczyk Alec Woo David Culler An event based execution environment for Networked Sensors.
Advertisements

A System Architecture for Tiny Networked Devices
Programming TinyOS David Culler,
TinyOS Tutorial, Part I Phil Levis et al. MobiSys 2003.
MicroKernel Pattern Presented by Sahibzada Sami ud din Kashif Khurshid.
Threads, SMP, and Microkernels
Sensor Network Platforms and Tools
Overview: Chapter 7  Sensor node platforms must contend with many issues  Energy consumption  Sensing environment  Networking  Real-time constraints.
Mote Programming. 如何 compile 程式  make [re]install. : desired device address : target platform  install vs. reinstall install : compile the application.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Chapter 13 Embedded Systems
Towards System Architecture for Tiny Networked Devices David Culler U.C. Berkeley Wireless hoo-hah 5/30/2000.
Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.
Jason Hill, Robert Szewczyk, Alec Woo Spring 2000 TinyOS Operating System for Networked Sensors Networked SensorsSystem Structure Composing Components.
A System Architecture for Tiny Networked Devices Jason Hill U.C. Berkeley 9/22/2000.
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.
2008EECS Embedded Network Programming nesC, TinyOS, Networking, Microcontrollers Jonathan Hui University of California, Berkeley.
Figure 1.1 Interaction between applications and the operating system.
Sensor Node Architecture Issues Stefan Dulman
1 Software Development Infrastructure for Sensor Networks  Operating systems ( TinyOS )  Resource (device) management  Basic primitives  Protocols.
TinyOS Tutorial Jianping Wang (merge several tutorials found online)
A System Architecture for Networked Sensors Jason Hill, Robert Szewczyk, Alec Woo, Seth Hollar, David Culler, Kris Pister
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 TinyOS Computer Network Programming Wenyuan Xu Fall 2007.
WSN Platforms: Hardware & Software Murat Demirbas Lecture uses some slides from tutorials prepared by authors of these platforms.
Vishal Jain, TinyOS Design Viewpoint “TinyOS” Design Viewpoint.
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.
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 TinyOS & NesC.
Part 2 TinyOS and nesC Programming Selected slides from:
WSN Software Platforms - concepts Vinod Kulathumani Lecture uses some slides from tutorials prepared by authors of these platforms.
Lab 3, Part 2 Selected slides from: Wireless Sensor Networks Hardware/Software Tiny OS & NesC Programming borrowed from Turgay Korkmaz.
TinyOS Sandeep Gupta. Operating System (OS) What is an OS? Main functions  Process management  Memory management  Resource management Traditional OSs.
System Architecture Directions for Networked Sensors.
TinyOS By Valliappan Annamalai. Hardware Mica motes (Mica2 and Mica2Dot) Hardware –Radio –Microcontroller –Flash memory –ADC –Sensor Board (MTA310)
Based on slides from Andreas Larsson Table from CY Chong, SP Kumar, BA Hamilton - Proceedings of the IEEE, 2003.
Introduction Contain two or more CPU share common memory and peripherals. Provide greater system throughput. Multiple processor executing simultaneous.
EmStar: A Software Environment for Developing and Deploying Wireless Sensor Networks CENS Research Review October 28, 2005 UCLA CENS EmStar Team.
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.
TinyOS Sandeep Gupta. TinyOS basics TinyOS is  Single tasking OS  Interrupt driven Written using a Component based language A set of components put.
TinyOS and nesC. Outline ● Wireless sensor networks and TinyOS ● Networked embedded system C (nesC) – Components – Interfaces – Concurrency model – Tool.
Implementing Context Aware Applications Class 5. Agenda Review of TinyOS execution model Tutorial on TinyOS Code walk through Code quiz Assignment 2.
Introduction to Operating Systems Concepts
Computer System Structures
Software and Communication Driver, for Multimedia analyzing tools on the CEVA-X Platform. June 2007 Arik Caspi Eyal Gabay.
Real-time Software Design
Module 12: I/O Systems I/O hardware Application I/O Interface
Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3.
Simulation of Distributed Application and Protocols using TOSSIM
Topics Covered What is Real Time Operating System (RTOS)
Elaine Cheong Yang Zhao December 8, 2001
Understanding the OSI Reference Model
Real-time Software Design
CSCI 315 Operating Systems Design
GEOMATIKA UNIVERSITY COLLEGE CHAPTER 2 OPERATING SYSTEM PRINCIPLES
Operating System Concepts
An Introduction to nesC
CS 501: Software Engineering Fall 1999
Software models - Software Architecture Design Patterns
Lecture Topics: 11/1 General Operating System Concepts Processes
Lecture 4- Threads, SMP, and Microkernels
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
SenseToRfm SenseToInt.Timer -> TimerC; configuration SenseToRfm {
Chapter 13: I/O Systems.
Modeling Event-Based Systems in Ptolemy II EE249 Project Status Report
Module 12: I/O Systems I/O hardwared Application I/O Interface
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:

Lecture 2: Software Platforms Anish Arora CIS788.11J Introduction to Wireless Sensor Networks Lecture uses slides from tutorials prepared by authors of these platforms

Outline Discussion includes not only operating systems but also programming methodology Some environments focus more on one than the other Focus here is on node centric platforms (versus distributed system centric platforms) Platforms TinyOS (applies to XSMs) slides from Culler et al EmStar (applies to XSSs) slides from UCLA SOS Contiki Virtual machines (Maté) TinyCLR

References NesC The Emergence of Networking Abstractions and Techniques in TinyOS EmStar: An Environment for Developing Wireless Embedded Systems Software TinyOS webpage EmStar webpage

Traditional Systems Well established layers of abstractions Strict boundaries Ample resources Independent applications at endpoints communicate pt-pt through routers Well attended Application Application User System Network Stack Threads Transport Network Address Space Data Link Files Physical Layer Drivers Routers

Sensor Network Systems Highly constrained resources processing, storage, bandwidth, power, limited hardware parallelism, relatively simple interconnect Applications spread over many small nodes self-organizing collectives highly integrated with changing environment and network diversity in design and usage Concurrency intensive in bursts streams of sensor data & network traffic Robust inaccessible, critical operation Unclear where the boundaries belong  Need a framework for: Resource-constrained concurrency Defining boundaries Appl’n-specific processing allow abstractions to emerge

Choice of Programming Primitives Traditional approaches command processing loop (wait request, act, respond) monolithic event processing full thread/socket posix regime Alternative provide framework for concurrency and modularity never poll, never block interleaving flows, events

TinyOS Microthreaded OS (lightweight thread support) and efficient network interfaces Two level scheduling structure Long running tasks that can be interrupted by hardware events Small, tightly integrated design that allows crossover of software components into hardware

Tiny OS Concepts Scheduler + Graph of Components Component: constrained two-level scheduling model: threads + events Component: Commands Event Handlers Frame (storage) Tasks (concurrency) Constrained Storage Model frame per component, shared stack, no heap Very lean multithreading Efficient Layering Commands Events msg_rec(type, data) msg_send_done) send_msg(addr, type, data) power(mode) init Messaging Component internal thread Internal State Power(mode) TX_packet(buf) init RX_packet_done (buffer) TX_packet_done (success)

Application = Graph of Components Route map Router Sensor Appln application Active Messages Example: ad hoc, multi-hop routing of photo sensor readings packet Radio Packet Serial Packet Temp Photo SW 3450 B code 226 B data Radio byte UART HW byte ADC bit RFM clock Graph of cooperating state machines on shared stack

TOS Execution Model commands request action events notify occurrence ack/nack at every boundary call command or post task events notify occurrence HW interrupt at lowest level may signal events call commands post tasks tasks provide logical concurrency preempted by events application comp data processing message-event driven active message RFM Radio byte Radio Packet bit byte packet event-driven packet-pump crc event-driven byte-pump encode/decode event-driven bit-pump

Event-Driven Sensor Access Pattern command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 200); } event result_t Timer.fired() { return call sensor.getData(); event result_t sensor.dataReady(uint16_t data) { display(data) return SUCCESS; SENSE Timer Photo LED clock event handler initiates data collection sensor signals data ready event data event handler calls output command device sleeps or handles other activity while waiting conservative send/ack at component boundary

TinyOS Commands and Events { ... status = call CmdName(args) } command CmdName(args) { ... return status; } event EvtName(args) { ... return status; } { ... status = signal EvtName(args) }

TinyOS Execution Contexts Hardware Interrupts events commands Tasks Events generated by interrupts preempt tasks Tasks do not preempt tasks Both essential process state transitions

Tasks provide concurrency internal to a component longer running operations are preempted by events able to perform operations beyond event context may call commands may signal events not preempted by tasks { ... post TskName(); } task void TskName { ... }

Typical Application Use of Tasks event driven data acquisition schedule task to do computational portion event result_t sensor.dataReady(uint16_t data) { putdata(data); post processData(); return SUCCESS; } task void processData() { int16_t i, sum=0; for (i=0; i ‹ maxdata; i++) sum += (rdata[i] ›› 7); display(sum ›› shiftdata); 128 Hz sampling rate simple FIR filter dynamic software tuning for centering the magnetometer signal (1208 bytes) digital control of analog, not DSP ADC (196 bytes)

Task Scheduling Currently simple fifo scheduler Bounded number of pending tasks When idle, shuts down node except clock Uses non-blocking task queue data structure Simple event-driven structure + control over complete application/system graph instead of complex task priorities and IPC

Maintaining Scheduling Agility Need logical concurrency at many levels of the graph While meeting hard timing constraints sample the radio in every bit window Retain event-driven structure throughout application Tasks extend processing outside event window All operations are non-blocking

The Complete Application SenseToRfm generic comm IntToRfm AMStandard RadioCRCPacket UARTnoCRCPacket packet CRCfilter noCRCPacket Timer photo MicaHighSpeedRadioM ChannelMon phototemp RadioTiming SecDedEncode byte SW SPIByteFIFO RandomLFSR ADC HW UART ClockC bit SlavePin

Programming Syntax TinyOS 2.0 is written in an extension of C, called nesC Applications are too just additional components composed with OS components Provides syntax for TinyOS concurrency and storage model commands, events, tasks local frame variable Compositional support separation of definition and linkage robustness through narrow interfaces and reuse interpositioning Whole system analysis and optimization

Components A component specifies a set of interfaces by which it is connected to other components provides a set of interfaces to others uses a set of interfaces provided by others Interfaces are bidirectional include commands and events Interface methods are the external namespace of the component provides StdControl Timer provides interface StdControl; interface Timer: uses interface Clock Timer Component uses Clock

Component Interface logically related set of commands and events StdControl.nc interface StdControl { command result_t init(); command result_t start(); command result_t stop(); } Clock.nc interface Clock { command result_t setRate(char interval, char scale); event result_t fire(); }

Component Types Configurations Modules link together components to compose new component configurations can be nested complete “main” application is always a configuration Modules provides code that implements one or more interfaces and internal behavior

Example of Top Level Configuration configuration SenseToRfm { // this module does not provide any interface } implementation { components Main, SenseToInt, IntToRfm, ClockC, Photo as Sensor; Main.StdControl -> SenseToInt; Main.StdControl -> IntToRfm; SenseToInt.Clock -> ClockC; SenseToInt.ADC -> Sensor; SenseToInt.ADCControl -> Sensor; SenseToInt.IntOutput -> IntToRfm; Main StdControl SenseToInt Clock ADC ADCControl IntOutput ClockC Photo IntToRfm

Nested Configuration includes IntMsg; configuration IntToRfm { provides { interface IntOutput; interface StdControl; } implementation components IntToRfmM, GenericComm as Comm; IntOutput = IntToRfmM; StdControl = IntToRfmM; IntToRfmM.Send -> Comm.SendMsg[AM_INTMSG]; IntToRfmM.SubControl -> Comm; StdControl IntOutput IntToRfmM SubControl SendMsg[AM_INTMSG]; GenericComm

IntToRfm Module command result_t StdControl.start() includes IntMsg; { return call SubControl.start(); } command result_t StdControl.stop() { return call SubControl.stop(); } command result_t IntOutput.output(uint16_t value) { ... if (call Send.send(TOS_BCAST_ADDR, sizeof(IntMsg), &data) return SUCCESS; } event result_t Send.sendDone(TOS_MsgPtr msg, result_t success) includes IntMsg; module IntToRfmM { uses { interface StdControl as SubControl; interface SendMsg as Send; } provides { interface IntOutput; interface StdControl; implementation bool pending; struct TOS_Msg data; command result_t StdControl.init() { pending = FALSE; return call SubControl.init();

Atomicity Support in nesC Split phase operations require care to deal with pending operations Race conditions may occur when shared state is accessed by premptible executions, e.g. when an event accesses a shared state, or when a task updates state (premptible by an event which then uses that state) nesC supports atomic block implemented by turning of interrupts for efficiency, no calls are allowed in block access to shared variable outside atomic block is not allowed

Supporting HW Evolution Distribution broken into apps: top-level applications tos: lib: shared application components system: hardware independent system components platform: hardware dependent system components includes HPLs and hardware.h interfaces tools: development support tools contrib beta Component design so HW and SW look the same example: temp component may abstract particular channel of ADC on the microcontroller may be a SW I2C protocol to a sensor board with digital sensor or ADC HW/SW boundary can move up and down with minimal changes

Example: Radio Byte Operation Pipelines transmission: transmits byte while encoding next byte Trades 1 byte of buffering for easy deadline Encoding task must complete before byte transmission completes Separates high level latencies from low level real-time rqmts Decode must complete before next byte arrives … Encode Task Byte 1 Byte 2 Byte 3 Byte 4 Bit transmission start Byte 1 Byte 2 Byte 3 RFM Bits

Dynamics of Events and Threads bit event => end of byte => end of packet => end of msg send thread posted to start send next message bit event filtered at byte layer radio takes clock events to detect recv

Sending a Message User component provide structured msg storage bool pending; struct TOS_Msg data; command result_t IntOutput.output(uint16_t value) { IntMsg *message = (IntMsg *)data.data; if (!pending) { pending = TRUE; message->val = value; message->src = TOS_LOCAL_ADDRESS; if (call Send.send(TOS_BCAST_ADDR, sizeof(IntMsg), &data)) return SUCCESS; pending = FALSE; } return FAIL; destination length Refuses to accept command if buffer is still full or network refuses to accept send command User component provide structured msg storage

Send done Event Send done event fans out to all potential senders event result_t IntOutput.sendDone(TOS_MsgPtr msg, result_t success) { if (pending && msg == &data) { pending = FALSE; signal IntOutput.outputComplete(success); } return SUCCESS; Send done event fans out to all potential senders Originator determined by match free buffer on success, retry or fail on failure Others use the event to schedule pending communication

Receive Event event TOS_MsgPtr ReceiveIntMsg.receive(TOS_MsgPtr m) { IntMsg *message = (IntMsg *)m->data; call IntOutput.output(message->val); return m; } Active message automatically dispatched to associated handler knows format, no run-time parsing performs action on message event Must return free buffer to the system typically the incoming buffer if processing complete

Tiny Active Messages Sending Receiving Buffer management declare buffer storage in a frame request transmission name a handler handle completion signal Receiving declare a handler firing a handler: automatic Buffer management strict ownership exchange tx: send done event  reuse rx: must return a buffer

Tasks in Low-level Operation transmit packet send command schedules task to calculate CRC task initiates byte-level data pump events keep the pump flowing receive packet receive event schedules task to check CRC task signals packet ready if OK byte-level tx/rx task scheduled to encode/decode each complete byte must take less time that byte data transfer

TinyOS tools TOSSIM: a simulator for tinyos programs ListenRaw, SerialForwarder: java tools to receive raw packets on PC from base node Oscilloscope: java tool to visualize (sensor) data in real time Memory usage: breaks down memory usage per component (in contrib) Peacekeeper: detect RAM corruption due to stack overflows (in lib) Stopwatch: tool to measure execution time of code block by timestamping at entry and exit (in osu CVS server) Makedoc and graphviz: generate and visualize component hierarchy Surge, Deluge, SNMS, TinyDB

Scalable Simulation Environment target platform: TOSSIM whole application compiled for host native instruction set event-driven execution mapped into event-driven simulator machinery storage model mapped to thousands of virtual nodes radio model and environmental model plugged in bit-level fidelity Sockets = basestation Complete application including GUI

Simulation Scaling

TinyOS Limitations Static allocation allows for compile-time analysis, but can make programming harder No support for heterogeneity Support for other platforms (e.g. stargate) Support for high data rate apps (e.g. acoustic beamforming) Interoperability with other software frameworks and languages Limited visibility Debugging Intra-node fault tolerance Robustness solved in the details of implementation nesC offers only some types of checking

Em* Software environment for sensor networks built from Linux-class devices Claimed features: Simulation and emulation tools Modular, but not strictly layered architecture Robust, autonomous, remote operation Fault tolerance within node and between nodes Reactivity to dynamics in environment and task High visibility into system: interactive access to all services

Contrasting Emstar and TinyOS Similar design choices programming framework Component-based design “Wiring together” modules into an application event-driven reactive to “sudden” sensor events or triggers robustness Nodes/system components can fail Differences hardware platform-dependent constraints Emstar: Develop without optimization TinyOS: Develop under severe resource-constraints operating system and language choices Emstar: easy to use C language, tightly coupled to linux (devfs) TinyOS: an extended C-compiler (nesC), not wedded to any OS

Em* Transparently Trades-off Scale vs. Reality Em* code runs transparently at many degrees of “reality”: high visibility debugging before low-visibility deployment

Processing Application Em* Modularity Dependency DAG Each module (service) Manages a resource & resolves contention Has a well defined interface Has a well scoped task Encapsulates mechanism Exposes control of policy Minimizes work done by client library Application has same structure as “services” Hardware Radio Topology Discovery Collaborative Sensor Processing Application Neighbor Discovery Reliable Unicast Sensors Leader Election 3d Multi- Lateration Audio Time Sync Acoustic Ranging State

Em* Robustness Fault isolation via multiple processes Active process management (EmRun) Auto-reconnect built into libraries “Crashproofing” prevents cascading failure Soft state design style Services periodically refresh clients Avoid “diff protocols” scheduling depth map path_plan EmRun camera motor_x motor_y

Em* Reactivity Event-driven software structure React to asynchronous notification e.g. reaction to change in neighbor list Notification through the layers Events percolate up Domain-specific filtering at every level e.g. neighbor list membership hysteresis time synchronization linear fit and outlier rejection scheduling path_plan notify filter motor_y

EmStar Components Tools Standard IPC Common Services EmRun EmProxy/EmView Standard IPC FUSD Device patterns Common Services NeighborDiscovery TimeSync Routing

EmView/EmProxy: Visualization Emulator nodeN Mote … motenic linkstat neighbor emproxy emview

EmSim/EmCee Em* supports a variety of types of simulation and emulation, from simulated radio channel and sensors to emulated radio and sensor channels (ceiling array) In all cases, the code is identical Multiple emulated nodes run in their own spaces, on the same physical machine

EmRun: Manages Services Designed to start, stop, and monitor services EmRun config file specifies service dependencies Starting and stopping the system Starts up services in correct order Can detect and restart unresponsive services Respawns services that die Notifies services before shutdown, enabling graceful shutdown and persistent state Error/Debug Logging Per-process logging to in-memory ring buffers Configurable log levels, at run time

IPC : FUSD Inter-module IPC: FUSD Creates device file interfaces Text/Binary on same file Standard interface Language independent No client library required Client Server kfusd.o /dev/fusd /dev/servicename User Kernel

Device Patterns FUSD can support virtually any semantics What happens when client calls read()? But many interfaces fall into certain patterns Device Patterns encapsulate specific semantics take the form of a library: objects, with method calls and callback functions priority: ease of use

Status Device Designed to report current state no queuing: clients not guaranteed to see every intermediate state Supports multiple clients Interactive and programmatic interface ASCII output via “cat” binary output to programs Supports client notification notification via select() Client configurable client can write command string server parses it to enable per-client behavior Status Device Server O I Client1 Client2 Client3 Config Handler State Request

Packet Device Designed for message streams Supports multiple clients Supports queuing Round-robin service of output queues Delivery of messages to all/ specific clients Client-configurable: Input and output queue lengths Input filters Optional loopback of outputs to other clients (for snooping) Packet Device Server Client1 I O F Client2 Client3

Device Files vs Regular Files Require locking semantics to prevent race conditions between readers and writers Support “status” semantics but not queuing No support for notification, polling only Device files: Leverage kernel for serialization: no locking needed Arbitrary control of semantics: queuing, text/binary, per client configuration Immediate action, like an function call: system call on device triggers immediate response from service, rather than setting a request and waiting for service to poll

Interacting With em* Text/Binary on same device file Text mode enables interaction from shell and scripts Binary mode enables easy programmatic access to data as C structures, etc. EmStar device patterns support multiple concurrent clients IPC channels used internally can be viewed concurrently for debugging “Live” state can be viewed in the shell (“echocat –w”) or using emview