By: R Jayampathi Sampath

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

NesC Prepared for the Multimedia Networks Group University of Virginia.
1 Lab 3 Objectives  Case study: “Hello world” program on motes  Write you first program on mote.
KFUPM, COE 499. Ayman Al Bassam COE 499 Wireless Sensor Networks LAB 1.
Sensor Network Platforms and Tools
Peek into TinyOS Programs Vinod Kulathumani. 2 Basics Application consists of one or more components assembled, or wired A component provides and uses.
TinyOS Introduction Advanced Computer Networks. TinyOS Outline  Introduction to the Architecture of TinyOS and nesC  Component Model –Components, interfaces,
Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.
Systems Wireless EmBedded nesC Update Eric Brewer with help from David Culler, David Gay, Phil Levis, Rob von Behren, and Matt Welsh.
How to Code on TinyOS Xufei Mao Advisor: Dr. Xiang-yang Li CS Dept. IIT.
Sample Project Ideas KD Kang. Project Idea 1: Real-time task scheduling in TinyOS EDF in TinyOS 2.x –Description is available at
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
2008EECS Embedded Network Programming nesC, TinyOS, Networking, Microcontrollers Jonathan Hui University of California, Berkeley.
June 2008 WEI Short Course TinyOS Timers 1 Wireless Embedded Intrer-Networking Foundations of Ubiquitous Sensor Networks Timers and System Resources David.
CPS110: Implementing threads/locks on a uni-processor Landon Cox.
1 Lab 3 Objectives  Case study: “Hello world” program on motes  Write you first program on mote.
TinyOS 2.1 Jun Yi Partially based on the tutorial at IPSN 2009 By Stephen Dawson-Haggerty, Omprakash Gnawali, David Gay, Philip Levis, Răzvan Musăloiu-E.,
1 Software Development Infrastructure for Sensor Networks  Operating systems ( TinyOS )  Resource (device) management  Basic primitives  Protocols.
Programming in nesC (and TOSSIM)
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 Lab2 Objectives  Basics of TinyOS  Basics of nesC programming language.
1 Lab2 Objectives  Basics of TinyOS  Basics of nesC programming language.
Architecture Support for OS CSCI 444/544 Operating Systems Fall 2008.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
KFUPM, COE 499. Ayman Al Bassam COE 499 Wireless Sensor Networks LAB 1.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Dhanshree Nimje Smita Khartad
Lab 3 Introduction to TinyOS and nesC How to debug programs at PC Examples –Blink Timer –Blink –Hellow World Reference: 1.x/doc/tutorial/lesson1.html.
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:
Himali Saxena. Topics Configurations and Wiring Configuration implementation Basic Rules for declaration/definition Auto Wiring initialization ‘C’ and.
Scheduling Lecture 6. What is Scheduling? An O/S often has many pending tasks. –Threads, async callbacks, device input. The order may matter. –Policy,
@ nesC Programming KETI / Ubiquitous Computing Center Jeonghoon Kang
Overview A wireless sensor network (WSN) is a wireless network consisting of spatially distributed autonomous devices using sensors to cooperatively monitor.
Main Issues Three major issues that we are concerned with in sensor networks are – Clustering Routing and Security To be considered against the backdrop.
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Xiong Junjie Node-level debugging based on finite state machine in wireless sensor networks.
WSN Software Platforms - concepts Vinod Kulathumani Lecture uses some slides from tutorials prepared by authors of these platforms.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
1 Lab2 Objectives  Basics of TinyOS  Basics of nesC programming language.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
LoCal Embedded IPv6 Bootcamp Stephen Dawson-Haggerty September 9, 2010.
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.
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Why does it need? [USN] ( 주 ) 한백전자 Background Wireless Sensor Network (WSN)  Relationship between Sensor and WSN Individual sensors are very limited.
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.
Tinyos Introduction to Programming Pritee Parwekar.
Event Sources and Realtime Actions
Simulation of Distributed Application and Protocols using TOSSIM
Peek into TinyOS Programs
Lecture 21 Concurrency Introduction
Computer System Overview
An Introduction to nesC
Embedded Operating Systems
WSN Training: TinyOS/nesC Basic Concepts TinyOS and nesC
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
CSE 451: Operating Systems Winter 2007 Module 2 Architectural Support for Operating Systems Brian Bershad 562 Allen Center 1.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
CS333 Intro to Operating Systems
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Presentation transcript:

By: R Jayampathi Sampath TinyOS Programming By: R Jayampathi Sampath

nesC (network embedded system C) necC is a component-based C dialect. nesC application consists of one or more components wired. Use a purely local namespace. There are two types of components: modules provide the implementation of one or more interfaces. configurations used to wire other components together.

Contd. Components define two scopes. Specification (signature) names of interfaces it provides (implements) and names of interfaces it uses (calls). Implementation implementation of commands and events. module configuration { …..//provide and uses interfaces … } implementation{ …..//executable code …..//wire components

Modules and State Modules: are executable codes. must implement every command of interfaces it provides and every event of interfaces it uses. can declare state variables. Any state of a components is private. Ex: uint8_t counter = 0; 8 bits 16 bits 32 bits 64 bits signed int8_t int16_t int32_t int64_t unsigned uint8_t uint16_t uint32_t uint64_t

BilinkC.nc BlinkAppC.nc module BilnkC { uses interface Timer<TMilli> as Timer0; uses interface Timer<TMilli> as Timer1; uses interface Timer<TMilli> as Timer2; uses interface Leds; uses interface Boot; } Implementation event void Boot.booted() call Timer0.startPeriodic(250); call Timer1.startPeriodic(500); call Timer1.startPeriodic(1000); event void Timer0.fired(){ call Leds.led0Toggle(); event void Timer1.fired(){ call Leds.led1Toggle(); event void Timer2.fired() call Leds.led2Toggle(); BlinkAppC.nc configuration BlinkC components MainC, BlinkC, LedsC; components new TimerMillic() as Timer0; BlinkC ->MainC.Boot; BlinkC.Timer0 -> Timer0; BlinkC.Timer1 -> Timer1; BlinkC.Timer2 -> Timer2; BlinkC.Leds -> LedsC; nesC uses arrows to bind interfaces to one another. The right arrow (A->B) as "A wires to B"

Interfaces, Commands and Events if a component uses an interface, it can call the interface's commands and must implement handlers for its events. Invoking an interface command requires the call keyword, and invoking an interface event requires the signal keyword. Ex Timer.nc: interface Timer { // basic interface command void startPeriodic( uint32_t dt ); command void startOneShot( uint32_t dt ); command void stop(); event void fired(); // extended interface omitted (all commands) }

Internal Functions Ex: module BlinkC { uses interface Timer<TMilli> as Timer0; uses interface Timer<TMilli> as Timer1; uses interface Timer<TMilli> as Timer2; uses interface Leds; uses interface Boot; } implementation { void startTimers() { call Timer0.startPeriodic( 250 ); call Timer1.startPeriodic( 500 ); call Timer2.startPeriodic( 1000 ); event void Boot.booted() { startTimers(); . Component's private function for its own internal use. Similar to C function. Can’t invoke directly. Can freely call commands or signal events.

Split-Phase Operations Hardware is almost always split-phase (non blocking/asynchronous). In split-phase completion of a request is a callback. ADC synchronous operation: Magnetometer. samples periodically. when queried gives a cached value. (it can return the result immediately) make everything synchronous through threads is not possible. Solution : Operations that are split-phase in hardware are split-phase in software. Introduce interfaces that are bidirectional S/W Interrupts when complete Read the value Start Sample ADC

Split-Phase Operations (Contd.) ADC Down call Start the operation Up call signals the operation is complete Down call - command Up call - event

Split-Phase Operations (Contd.) Split-phase interfaces enable a TinyOS component to easily start several operations at once and have them execute in parallel. split-phase operations can save memory. Ex: The command Timer.startOneShot is an example of a split-phase call. The user of the Timer inteface calls the command, which returns immediately. Some time later (specified by the argument), the component providing Timer signals Timer.fired. In a system with blocking calls, a program might use sleep():

Interfaces with Arguments Interfaces can take types as arguments. wiring providers and users of interfaces that have type arguments, they types must match. used to enforce type checking.

Module Implementation

Tasks Consider magnetometer/ADC example: depending on split-phase operations means that the magnetometer driver has to issue a callback. it could just signal the event from within the call. signaling an event from within a command is generally a bad idea. might cause a very long call loop. corrupt memory and crash the program. needs a way to schedule a function to be called later (like an interrupt). can do this is with a task.

Tasks (Contd.) Task A module can post a task to the TinyOS scheduler. doesn’t take any parameters. A component posts a task to the TinyOS scheduler with the post keyword: post only one task runs at any time. and TinyOS doesn’t interrupt one task to run another. Implies that tasks should usually be reasonably short.

Tasks (Contd.) Ex: event void Timer.fired() { call Read.read(); } event void RawRead.readDone(error_t err, uint16_t val) { if (err == SUCCESS) { lastVal = val; filterVal *= 9; filterVal /= 10; filterVal += lastVal / 10; command error_t Read.read() { post readDoneTask(); return SUCCESS; task void readDoneTask() { signal Read.readDone(SUCCESS, filterVal); When Read.read is called, posts readDoneTask and returns immediately. At some point later, TinyOS runs the task, which signals Read.readDone.

Tasks (Contd.) Why? Synchronous code runs in a single execution context and does not have any kind of pre-emption. sync code runs for a long time. A component needs to be able to split a large computation into smaller parts, which can be executed one at a time. Task A task is function which a component tells TinyOS to run later, rather than now.

Concurrency Tasks allow software components to emulate the split-phase behavior of hardware. They also provide a mechanism to manage pre-emption in the system. In nesC and TinyOS, functions that can run preemptively labeled with the async keyword. async function can’t call a command or event that isn’t async. By default, commands and events are sync. A task post is an async operation, while a task running is sync.

Concurrency (Contd.) Can’t make everything async because of race condition. Ex: consider the command, toggle, which flips the state bit and returns the new one: Solutions: Keep code synchronous when you can. functionality through atomic statements.

Concurrency (Contd.) The atomic block promises that these variables can be read and written atomically this does not promise that the atomic block won’t be preempted with atomic blocks, two code segments that do not share any of the same variables can preempt one another

Concurrency (Contd.) An atomic block involves some kind of execution (e.g.. disabling an interrupt), so unnecessary atomics are a waste of CPU cycles. an atomic block does have a CPU cost, so you want to minimize how many you have. shorter atomic blocks delay interrupts less and so improve system concurrency.

Allocation the only way that components can share state is through function calls. two basic ways that components can pass parameters: by value and by reference (pointer). every pointer should have a clear owner, and only the owner can modify the corresponding memory. abstract data types (ADTs) in TinyOS are usually represented one of two ways: Generic modules Through an interface with by-reference commands.

Allocation (An Example) Generic module, Ex many TinyOS components needs to maintain bit vectors, and so in tos/system there’s a generic module BitVectorC that takes the number of bits as a parameter: This component allocates the bit vector internally and provides the BitVector interface to access it:

Allocation (Contd.) passing a parameter by reference, in BitVector, it’s possible that, after a bit has been fetched for get() but before it returns, an interrupt fires whose handler calls set() on that same bit. you should call get() from within an atomic section. passing a parameter by reference, this is easy, as all of its commands are synchronous: no code that can preempt the call (async).

References TinyOS Documentation Wiki (URL: http://docs.tinyos.net/index.php/Main_Page). TinyOS Programing (URL: http://www.tinyos.net/tinyos 2.x/doc/pdf/tinyos programming.pdf)