June 2008 WEI Short Course TinyOS Timers 1 Wireless Embedded Intrer-Networking Foundations of Ubiquitous Sensor Networks Timers and System Resources David.

Slides:



Advertisements
Similar presentations
Computer Architecture and Organization
Advertisements

1 (Review of Prerequisite Material). Processes are an abstraction of the operation of computers. So, to understand operating systems, one must have a.
NesC Prepared for the Multimedia Networks Group University of Virginia.
Feb 2007WSN Training: First Steps in nesC Programming1 First Steps in TinyOS and nesC Programming Topics  Timer Application: MyApp  Application directory.
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.
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,
7/13/2007AIIT Summer Course - D#1 Wireless Embedded Systems and Networking Lab Day 5: Part 1: TinyOS Programming on Open Source Distribution Jaein Jeong.
2008EECS Embedded Network Programming nesC, TinyOS, Networking, Microcontrollers Jonathan Hui University of California, Berkeley.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
NesC: 1.1 Bumps and Future Directions David Gay, Intel Research, Berkeley (and the nesC and TinyOS teams)
Chapter 13 Embedded Operating Systems Eighth Edition By William Stallings Operating Systems: Internals and Design Principles.
1 Lab 3 Objectives  Case study: “Hello world” program on motes  Write you first program on mote.
CS-334: Computer Architecture
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 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
1 Software Development Infrastructure for Sensor Networks  Operating systems ( TinyOS )  Resource (device) management  Basic primitives  Protocols.
Ch. 9 Interrupt Programming and Real-Time Sysstems From Valvano’s Introduction to Embedded Systems.
ARM Timers.
By: R Jayampathi Sampath
April 15, 2005TinyOS: A Component Based OSPage 1 of 27 TinyOS A Component-Based Operating System for Networked Embedded Systems Tom Bush Graduate College.
System Clocks.
Data Acquisition Data acquisition (DAQ) basics Connecting Signals Simple DAQ application Computer DAQ Device Terminal Block Cable Sensors.
Chapter 4 TIMER OPERATION
Unit 10.2 Timer Examples. Example – Music Generation Channel 6 – Set up as a timer Output to Generate Square Waves Channel 4 – Set up as a timer Output.
THE COMPUTER SYSTEM. Lecture Objectives Computer functions – Instruction fetch & execute – Interrupt Handling – I/O functions Interconnections Computer.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
KFUPM, COE 499. Ayman Al Bassam COE 499 Wireless Sensor Networks LAB 1.
Microcontroller based system design Asst. Prof. Dr. Alper ŞİŞMAN.
Top Level View of Computer Function and Interconnection.
Other Chapters From the text by Valvano: Introduction to Embedded Systems: Interfacing to the Freescale 9S12.
CIS 798 Sensor Network Implementation. Goals Learning sensor network programming with Crossbow motes Implement reasonable sized sensor applications Develop.
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 TinyOS & NesC.
COMPUTER ORGANIZATIONS CSNB123. COMPUTER ORGANIZATIONS CSNB123 Expected Course Outcome #Course OutcomeCoverage 1Explain the concepts that underlie modern.
EEE440 Computer Architecture
Time Management.  Time management is concerned with OS facilities and services which measure real time, and is essential to the operation of timesharing.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
Xiong Junjie Node-level debugging based on finite state machine in wireless sensor networks.
By Fernan Naderzad.  Today we’ll go over: Von Neumann Architecture, Hardware and Software Approaches, Computer Functions, Interrupts, and Buses.
LoCal Embedded IPv6 Bootcamp Stephen Dawson-Haggerty September 9, 2010.
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Chapter 5 - Interrupts.
TinyOS Sandeep Gupta. Operating System (OS) What is an OS? Main functions  Process management  Memory management  Resource management Traditional OSs.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
Chapter 3 System Buses.  Hardwired systems are inflexible  General purpose hardware can do different tasks, given correct control signals  Instead.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
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.
Application Case Study Security Camera Controller
Simulation of Distributed Application and Protocols using TOSSIM
Peek into TinyOS Programs
Networked Embedded Systems Sachin Katti
David Gay Intel Research Berkeley
ECE 3430 – Intro to Microcomputer Systems
An Introduction to nesC
Embedded Operating Systems
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
Wireless Embedded Systems
ECE 3430 – Intro to Microcomputer Systems
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
Presentation transcript:

June 2008 WEI Short Course TinyOS Timers 1 Wireless Embedded Intrer-Networking Foundations of Ubiquitous Sensor Networks Timers and System Resources David E. Culler University of California, Berkeley

June 2008WEI Short Course TinyOS Timers2 Timers See TEP102 for complete details

June 2008WEI Short Course TinyOS Timers3 Timer Interface (Hardware Independent) Precision: typedef struct { } TMilli; // 1024 ticks per second typedef struct { } T32khz; // ticks per second typedef struct { } TMicro; // ticks per second interface Timer { command void startPeriodic(uint32_t dt); event void fired(); command void startOneShot(uint32_t dt); command void stop(); command bool isRunning(); command bool isOneShot(); command void startPeriodicAt(uint32_t t0, uint32_t dt); command void startOneShotAt(uint32_t t0, uint32_t dt); command uint32_t getNow(); command uint32_t gett0(); command uint32_t getdt(); }

June 2008WEI Short Course TinyOS Timers4 Microcontroller Timer Capabilities Most microcontrollers offer a rich timer system, with features like: –several counters, possibly of different widths, with multiple clocking options –one or more compare registers for each counter, which can trigger interrupts, changes to output pins and changes to the counter value –capture of the time of input pin changes

June 2008WEI Short Course TinyOS Timers5 Hardware Timer Support Atmega128 –Two 8-bit timers, each allowing »7 prescaler values (division by different powers of 2) »Timer 0 can use an external 32768Hz crystal »One compare register, with many compare actions (change output pin, clear counter, generate interrupt, etc) –Two 16-bit timers, each with »5 prescaler values »External and software clocking options »Three compare registers (again with many actions) »Input capture MSP430 –Two 16-bit timers with »One with three compare registers »One with eight compare registers »Each from distinct clock source »Each with limited prescalers

June 2008WEI Short Course TinyOS Timers6 Hardware Timer Support (cont) Intel PXA27x –One fixed rate (3.25MHz) 32-bit timer with »4 compare registers »Watchdog functionality –8 variable rate 32-bit timers with »1 associated compare register each »Individually selectable rates: 1/32768s, 1ms, 1s, 1us »Individually selectable sources: ( external osc, 13 Mhz internal clock) –Periodic & one-shot capability –Two external sync events

June 2008WEI Short Course TinyOS Timers7 TinyOS Timer Subsystem Architecture Hardware Timer Support Counters Alarms Timers HPL Counters of system defined width and precision, handle overflows signal an event when specified time occurs Physical registers, Ops, comparators 32-bit counter without overflow Local Time HAL HIL Virtual timers Periodic, one-shot, phase Synchronous Asynchronous

June 2008WEI Short Course TinyOS Timers8 Local Time get() –return the current time in specified precision. –32-bit result, no overflows interface LocalTime { async command uint32_t get(); }

June 2008WEI Short Course TinyOS Timers9 Basic Timers command void startPeriodic(uint32_t dt); –Set a periodic timer to repeat every dt time units, starting from now –Fired event will be signaled every dt units (first event in dt units) command void startOneShot(uint32_t dt); –Set a single-short timer to some time units in the future from now. event void fired(); –Signal occurance of a running timer Each Timer is a distinct virtual resource (generic). Starting a timer replaces previous pending setting. Collectively they are implemented by a set of parameterized components.

June 2008WEI Short Course TinyOS Timers10 Time command uint32_t getNow(); –Return the current time command uint32_t gett0(); –Return the base time for the previously started timer or the time of the previous event for periodic timers. command uint32_t getdt(); –Return the interval for the previously started timer. –The next fired event will occur at gett0() + getdt().

June 2008WEI Short Course TinyOS Timers11 Absolute Timers command void startPeriodicAt(uint32_t t0, uint32_t dt) –Fired event will be signaled every dt units –first event at t0+dt units. »Periodic timers set in the past will get a bunch of events in succession, until the timer "catches up". command void startOneShotAt(uint32_t t0, uint32_t dt); – Set a single-short timer to time t0+dt. »Timers set in the past will fire "soon".

June 2008WEI Short Course TinyOS Timers12 Timer Status and Control command void stop(); command bool isRunning(); command bool isOneShot();

June 2008WEI Short Course TinyOS Timers13 Alarms Alarm components are extensions of Counters that signal an event when their compare register detects the alarm time has been hit. All commands and events of the Alarm interface are asynchronous (or in "interrupt context"). The Alarm interface provides a set of "basic" commands for common usage and provides a set of "extended" commands for advanced use.

June 2008WEI Short Course TinyOS Timers14 Alarm Interface interface Alarm { // basic interface async command void start( size_type dt ); async command void stop(); async event void fired(); // extended interface async command bool isRunning(); async command void startAt( size_type t0, size_type dt ); async command size_type getNow(); async command size_type getAlarm(); }

June 2008WEI Short Course TinyOS Timers15 Alarms start(dt) –cancel any previously running alarm and set to fire in dt time units from the time of invocation. The alarm will only fire once then stop. stop() –cancel any previously running alarm. fired() –signals that the alarm has occurred. isRunning() –return TRUE if the alarm has been started and has not been cancelled or has not yet fired. FALSE is returned otherwise. startAt(t0,dt) –cancel any previously running alarm and set to fire at time t1 = t0+dt. This form allows a delay to be anchored to some time t0 taken before the invocation of startAt. The timer subsystem uses this form internally, to be able to use of the full width of an alarm while also detecting when a short alarm elapses prematurely. getNow() –return the current time in the precision and width of the alarm. getAlarm() –return the time the currently running alarm will fire or the time that the previously running alarm was set to fire. getAlarm can be used with startAt to set an alarm from the previous alarm time, as in startAt(getAlarm(),dt). This pattern is used within the fired() event to construct periodic alarms.

June 2008WEI Short Course TinyOS Timers16 Counters A Counter component will increase the width of a low-level hardware timer by wrapping the overflow event and incrementing its higher order bits. These higher order bits are considered extra state over the HPL register layer, and therefore qualify all Counters as HAL components. The Counter interface returns the current time and provides commands and an event for managing overflow conditions. These overflow commands and events are necessary for properly deriving larger width Counters from smaller widths.

June 2008WEI Short Course TinyOS Timers17 Counter Interface get() –return the current time. isOverflowPending() –return TRUE if the overflow flag is set for this counter, i.e., if and only if an overflow interrupt will occur after the outermost atomic block exits. Return FALSE otherwise. –This command only returns the state of the overflow flag and causes no side effect. It is expected that the underlying hardware platform sets the overflow flag when appropriate. clearOverflow() –cancel the pending overflow interrupt clearing the overflow flag. overflow() –signals that an overflow in the current time. That is, the current time has wrapped around from its maximum value to zero. interface Counter { async command size_type get(); async command bool isOverflowPending(); async command void clearOverflow(); async event void overflow(); }

June 2008WEI Short Course TinyOS Timers18 Abstraction Architecture HPL – present capabilities of the hardware –Convenient software access to what the hardware can do –Mechanism, not policy HAL – provide useful services in a manner that is most effective for the underlying hardware platform –Allow applications the ability to optimize if they value that higher than portability –Not limited to the least common denominator HIL – provide common hardware independent services using the HAL –Expressing a powerful common subset –Range of hardware / software in implementation

June 2008WEI Short Course TinyOS Timers19 Philosophy Applied to Timers Small number of direct hardware supported counters and alarms –Essentially generalized interrupts –Low-latency, low jitter –Pre-empts higher level activity Create virtualized timer resources using a portion of the available hardware resources –Delivered to the application component in task (synchronous) context. –Atomic relative to other synch context handlers. –Number of virtual timers determined automatically at compile time.

June 2008WEI Short Course TinyOS Timers20 System Implementation Challenges Want to provide multiple dedicated virtual resources to higher levels to simplify usage –Start / stop each virtual timer independent of the others Want to implement the multiple virtual timers on a shared resource. –Multiple pending “fires”, limited physical timer registers –Set the physical timer to the next event.

June 2008WEI Short Course TinyOS Timers21 Virtualizing physical resources Generic Modules –Create multiple virtual resources services by a common shared resource

June 2008WEI Short Course TinyOS Timers22 Example – multiple virtual timers #include "Timer.h" module Blink3M { uses interface Timer as Timer0; uses interface Timer as Timer1; uses interface Timer as Timer2; uses interface Leds; uses interface Boot; } implementation { event void Boot.booted() { call Timer0.startPeriodic( 250 ); call Timer1.startPeriodic( 550 ); call Timer2.startPeriodic( 1200 ); } event void Timer0.fired() { call Leds.led0Toggle(); } event void Timer1.fired() { call Leds.led1Toggle(); } event void Timer2.fired() { call Leds.led2Toggle(); } Note, not simple multiples

June 2008WEI Short Course TinyOS Timers23 3 Virtual Timer Instances TimerMilliC is a generic component Instantiated multiple times configuration Blink3MAppC { } implementation { components MainC, BlinkC, LedsC; components new TimerMilliC() as Timer0; components new TimerMilliC() as Timer1; components new TimerMilliC() as Timer2; BlinkC -> MainC.Boot; BlinkC.Timer0 -> Timer0; BlinkC.Timer1 -> Timer1; BlinkC.Timer2 -> Timer2; BlinkC.Leds -> LedsC; }

June 2008WEI Short Course TinyOS Timers24 Instantiating Multiple Virtual Timers Blink3M BootLeds MainC Boot LedsC Leds Timer0 TimerMilliC Timer Blink3MAppC Timer0 TimerMilliC Timer Timer0 TimerMilliC Timer

June 2008WEI Short Course TinyOS Timers25 Providing Virtual Timers The generic configuration, TimerMilliC, obtains a unique id (at compile time) for the instance. Wires it to the indexed interface array of the resource provider Blink3M BootLeds MainC Boot LedsC Leds Timer0 TimerMilliC Timer Blink3MAppC Timer0 Timer Timer0 TimerMilliC Timer TimerMilliP TimerMilli unique(UQ_TIMER_MILLI) TimerMilli

June 2008WEI Short Course TinyOS Timers26 Generic Configuration Generates a unique index (key) over the UQ_TIMER_MILLI keyset. Wires the instance to that index #include "Timer.h“ generic configuration TimerMilliC() { provides interface Timer ; } implementation { components TimerMilliP; Timer = TimerMilliP.TimerMilli[unique(UQ_TIMER_MILLI)]; } tos/system/timer/TimerMilliC.nc component interface index

June 2008WEI Short Course TinyOS Timers27 Indexed Interface Extent parameter behaves as a compile-time constant –Size internal data structures Determined by the number of distinct wirings #include "Timer.h" configuration TimerMilliP { provides interface Timer as TimerMilli[uint8_t id]; } implementation { … }

June 2008WEI Short Course TinyOS Timers28 Connecting to the Platform Indexed interface, paramterized by precision Connected to Hardware Independent interface provided by the component that implements the HIL for the particular platform. #include "Timer.h" configuration TimerMilliP { provides interface Timer as TimerMilli[uint8_t id]; } implementation { components HilTimerMilliC, MainC; MainC.SoftwareInit -> HilTimerMilliC; TimerMilli = HilTimerMilliC; } tos/system/timer/TimerMilliP.nc

June 2008WEI Short Course TinyOS Timers29 Mica class Millisecond timer for the mica family is built on hardware timer 0, running at 1024Hz. #include "Timer.h" configuration HilTimerMilliC { provides interface Init; provides interface Timer as TimerMilli[uint8_t num]; provides interface LocalTime ; } implementation { enum { TIMER_COUNT = uniqueCount(UQ_TIMER_MILLI) }; components AlarmCounterMilliP, new AlarmToTimerC(TMilli), new VirtualizeTimerC(TMilli, TIMER_COUNT), new CounterToLocalTimeC(TMilli); Init = AlarmCounterMilliP; TimerMilli = VirtualizeTimerC; VirtualizeTimerC.TimerFrom -> AlarmToTimerC; AlarmToTimerC.Alarm -> AlarmCounterMilliP; LocalTime = CounterToLocalTimeC; CounterToLocalTimeC.Counter -> AlarmCounterMilliP; } Tos/platforms/mica/HilTimerMilliC.nc

June 2008WEI Short Course TinyOS Timers30 Mica: Timer out of Alarms and Counters HilTimerMilliC TimerMilli AlarmCounterMilliP AlarmToTimerC VirtualizeTimerC CounterToLocalTimeC init TIMER_COUNT TimerFrom Alarm LocalTime Counter AlarmCounter init LocalTime

June 2008WEI Short Course TinyOS Timers31 MSP430 HIL configuration HilTimerMilliC { provides interface Init; provides interface Timer as TimerMilli[ uint8_t num ]; } implementation { components new AlarmMilli32C(); components new AlarmToTimerC(TMilli); components new VirtualizeTimerC(TMilli, uniqueCount(UQ_TIMER_MILLI)); Init = AlarmMilli32C; TimerMilli = VirtualizeTimerC; VirtualizeTimerC.TimerFrom -> AlarmToTimerC; AlarmToTimerC.Alarm -> AlarmMilli32C; }

June 2008WEI Short Course TinyOS Timers32 MSP430 – doing the work generic module VirtualizeTimerC(typedef precision_tag, int max_timers) { provides interface Timer as Timer[uint8_t num]; uses interface Timer as TimerFrom; } implementation { enum { NUM_TIMERS = max_timers, END_OF_LIST = 255, }; typedef struct { uint32_t t0; uint32_t dt; bool isoneshot : 1; bool isrunning : 1; bool _reserved : 6; } Timer_t; Timer_t m_timers[NUM_TIMERS]; bool m_timers_changed; …….

June 2008WEI Short Course TinyOS Timers33 Additional areas of importants Resource Arbitrators Radio Stacks Sharing of Busses and Pins Platform Definition

June 2008WEI Short Course TinyOS Timers34 3 Classes of Resources – TEP 108 Dedicated –subsystem needs exclusive access to at all times –no sharing policy is needed –Ex: interrupts and counters –MAY be annotated with the nesC to provide compile-time checks that their usage assumptions are not violated Virtualized –Multiple clients interact with resource as if it were dedicated –virtualized instances multiplexed on single underlying resource Shared –Multiplexing of resource is exposed to multiple clients –Ex: bus. »TelosB Flash and Radio share SPI, SPI and I2C share pins –resource arbiter is responsible for multiplexing between the different clients »Clients request access to shared resource through arbiter resource interface

June 2008WEI Short Course TinyOS Timers35 Resource Interface – TEP 108 interface Resource { async command error_t request(); async command error_t immediateRequest(); event void granted(); async command error_t release(); async command bool isOwner(); }