1 Tomás Sánchez López July 9, 2004 Real-time & Embedded Systems Laboratory TinyOS … in deep.

Slides:



Advertisements
Similar presentations
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Advertisements

Computer Networks TCP/IP Protocol Suite.
Zhongxing Telecom Pakistan (Pvt.) Ltd
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Processes and Operating Systems
How to use TinyOS Jason Hill Rob Szewczyk Alec Woo David Culler An event based execution environment for Networked Sensors.
A System Architecture for Tiny Networked Devices
TinyOS Tutorial, Part I Phil Levis et al. MobiSys 2003.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design.
6 Copyright © 2005, Oracle. All rights reserved. Building Applications with Oracle JDeveloper 10g.
1 Processes and Threads Creation and Termination States Usage Implementations.
Chapter 5 Input/Output 5.1 Principles of I/O hardware
1 Data Link Protocols By Erik Reeber. 2 Goals Use SPIN to model-check successively more complex protocols Using the protocols in Tannenbaums 3 rd Edition.
Construction process lasts until coding and testing is completed consists of design and implementation reasons for this phase –analysis model is not sufficiently.
1 Communication in Distributed Systems REKs adaptation of Tanenbaums Distributed Systems Chapter 2.
Real Time Versions of Linux Operating System Present by Tr n Duy Th nh Quách Phát Tài 1.
1 Peripheral Component Interconnect (PCI). 2 PCI based System.
Electric Bus Management System
Configuration management
Mehdi Naghavi Spring 1386 Operating Systems Mehdi Naghavi Spring 1386.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc
Chapter 1: Introduction to Scaling Networks
Campus02.at don't stop thinking about tomorrow DI Anton Scheibelmasser Setubal ICINCO /25 Device integration into automation systems with.
FIFO Queues CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Project 5: Virtual Memory
1 of 27 DA1241 Archive Companies Last updated: March-2004 DA1241 Archive Companies.
Executional Architecture
Systems Analysis and Design in a Changing World, Fifth Edition
Chapter 9 Interactive Multimedia Authoring with Flash Introduction to Programming 1.
Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
TCP/IP Protocol Suite 1 Chapter 18 Upon completion you will be able to: Remote Login: Telnet Understand how TELNET works Understand the role of NVT in.
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.
Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.
How to Code on TinyOS Xufei Mao Advisor: Dr. Xiang-yang Li CS Dept. IIT.
Programming Motes A TinyOS and TOSSIM Tutorial By: Brent Rood.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Development of a Mica2 Mote Sensor Network Cliff Macklin Bill Ehrbar December 8, 2004 University of Colorado, Colorado Springs.
TinyOS Software Engineering Sensor Networks for the Masses.
2008EECS Embedded Network Programming nesC, TinyOS, Networking, Microcontrollers Jonathan Hui University of California, Berkeley.
NesC: 1.1 Bumps and Future Directions David Gay, Intel Research, Berkeley (and the nesC and TinyOS teams)
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.
TinyOS Tutorial Jianping Wang (merge several tutorials found online)
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.
TinyOS 1/2 Onsystech Sangjae Han.
Wireless Sensor Networks MOTE-KITS TinyOS Crossbow UC Berkeley.
Dhanshree Nimje Smita Khartad
CIS 798 Sensor Network Implementation. Goals Learning sensor network programming with Crossbow motes Implement reasonable sized sensor applications Develop.
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:
@ nesC Programming KETI / Ubiquitous Computing Center Jeonghoon Kang
TinyOS and UC Berkeley Motes Hardware and Programming Tools Some slides and information was taken from Boot1.ppt and Boot2.ppt on the Berkeley TinyOS website.
Main Issues Three major issues that we are concerned with in sensor networks are – Clustering Routing and Security To be considered against the backdrop.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Xiong Junjie Node-level debugging based on finite state machine in wireless sensor networks.
TinyOS Sandeep Gupta. Operating System (OS) What is an OS? Main functions  Process management  Memory management  Resource management Traditional OSs.
TinyOS By Valliappan Annamalai. Hardware Mica motes (Mica2 and Mica2Dot) Hardware –Radio –Microcontroller –Flash memory –ADC –Sensor Board (MTA310)
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 Lab1: LED Control ZigbeX mote has Red, Yellow, Green LED. This lab using LED control component provided by TinyOS.
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.
Simulation of Distributed Application and Protocols using TOSSIM
Elaine Cheong Yang Zhao December 8, 2001
An Introduction to nesC
Presentation transcript:

1 Tomás Sánchez López July 9, 2004 Real-time & Embedded Systems Laboratory TinyOS … in deep

2 Outline Overview Design Implementation Overview Example Tasks Main Scheduler Conclusions Network Stack Sources Compilation

3 Overview TinyOs has been being developed by the university of Berkeley for more than 3 years As other projects, they develop its own hardware platform Use an event model and state machine Use their own C language extension called Nesc Need to learn, not only the design but also how to implement it Its module based Components that interact and create a graph with its relations Layered based where the hardware details are hidden through several levels of components Two level of scheduling Tasks that are scheduled through a FIFO queue Events that are caused by hardware interrupts

4 Design Architecture of TinyOS consist of interacting components and a task scheduler 3 entities exist that allow components to execute code and communicate among them: Commands and Command Handlers Events and Event Handlers Tasks Also a fixed-size and statically allocated frame exist per each component, representing its internal state and being operated by the 3 previous entities Components declare commands used and events signalled, creating a layers of components, where upper layers issue commands to lower layers and handle events coming from them

5 Design In TinyOS is talked then about bidirectional interface, referring communication between components through events and commands

6 Design Perform the primary computation work Atomic with respect to other tasks, and run to completion, but can be preempted by events Allow the OS to allocate a single stack assigned to the currently executing task Call lower level commands Signal higher level events Schedule other tasks within a component Simulate concurrency using events Are queued in FIFO task scheduler TASKS

7 Design COMMANDS Non-blocking requests to lower level components Deposit request parameters into a components frame, and post a task for later execution Can also invoke lower level commands, but cannot block Return status to the caller

8 Design EVENTS Event handlers deal with hardware events (interrupts) directly or by lower layer components Deposit information into a frame and post tasks to the scheduler (similar to commands) Signal higher level events Call lower level commands

9 Implementation - Overview Proprietary language based on C language called NesC Provides macros which will be translated by the NesC compiler into native C code and compiled later by the gcc compiler Two types of components in NesC: Modules: Application code, implementing one or more interfaces Configurations: Wires components and, on a top level, assembles applications to produce and executable All files have *.nc extension with a naming convention File layout distinguish modules and configurations Old versions were not like this

10 Implementation - Example In Practice: Blink Application Simple application that causes the red LED on the mote to turn on and off at 1Hz Two components. A module called BlinkM.nc and a configuration called Blink.nc, plus: Timer components Led access components Main is the first component executed in any TinyOS application and must be indicated in its configuration file Hardware

11 Implementation - Example In Practice: Blink Application configuration Blink { } implementation { components Main, BlinkM, SingleTimer, LedsC; Main.StdControl -> BlinkM.StdControl; Main.StdControl -> SingleTimer.StdControl; BlinkM.Timer -> SingleTimer.Timer; BlinkM.Leds -> LedsC; } Configuration: Blink.nc uses provides

12 Implementation - Example In Practice: Blink Application Module: BlinkM.nc module BlinkM { provides { interface StdControl; } uses { interface Timer; interface Leds; }} implementation { command result_t StdControl.init() { call Leds.init(); return SUCCESS; } command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 1000); } command result_t StdControl.stop() { return call Timer.stop(); } event result_t Timer.fired() { call Leds.redToggle(); return SUCCESS; } } Main.StdControl -> BlinkM.StdControl;BlinkM.Timer -> SingleTimer.Timer; BlinkM.Leds -> LedsC; configuration Main { uses interface StdControl; } …. interface StdControl { command result_t init(); command result_t start(); command result_t stop(); }

13 Implementation - Example In Practice: Blink Application Module: BlinkM.nc module BlinkM { provides { interface StdControl; } uses { interface Timer; interface Leds; }} implementation { command result_t StdControl.init() { call Leds.init(); return SUCCESS; } command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 1000); } command result_t StdControl.stop() { return call Timer.stop(); } event result_t Timer.fired() { call Leds.redToggle(); return SUCCESS; } } Main.StdControl -> BlinkM.StdControl;BlinkM.Timer -> SingleTimer.Timer; BlinkM.Leds -> LedsC; async command result_t Leds.init() { atomic { ledsOn = 0; TOSH_SET_RED_LED_PIN(); TOSH_SET_YELLOW_LED_PIN(); TOSH_SET_GREEN_LED_PIN(); } return SUCCESS; } async command result_t Leds.redToggle() { result_t rval; atomic { if (ledsOn & RED_BIT) rval = call Leds.redOff(); else rval = call Leds.redOn(); } return rval; }

14 Implementation - Example In Practice: Blink Application Module: BlinkM.nc module BlinkM { provides { interface StdControl; } uses { interface Timer; interface Leds; }} implementation { command result_t StdControl.init() { call Leds.init(); return SUCCESS; } command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 1000); } command result_t StdControl.stop() { return call Timer.stop(); } event result_t Timer.fired() { call Leds.redToggle(); return SUCCESS; } } Main.StdControl -> BlinkM.StdControl; BlinkM.Timer -> SingleTimer.Timer; BlinkM.Leds -> LedsC; async command result_t Leds.init() { atomic { ledsOn = 0; TOSH_SET_RED_LED_PIN(); TOSH_SET_YELLOW_LED_PIN(); TOSH_SET_GREEN_LED_PIN(); } return SUCCESS; } async command result_t Leds.redToggle() { result_t rval; atomic { if (ledsOn & RED_BIT) rval = call Leds.redOff(); else rval = call Leds.redOn(); } return rval; }

15 Implementation - Example In Practice: Blink Application Module: BlinkM.nc For a component to call the commands of an interface, it must implement the events signaled by it An event can call commands The async reserved word is used by commands and event that are executed as part of a hardware event handler. The code section within the atomic curly braces will execute without preemption

16 Implementation - Example In Practice: Blink Application

17 Implementation - Tasks What about the tasks? They are declared and implemented using the syntax: task void taskname() {... } Can be posted for execution within a command, event or another task: post taskname(); Tasks posted go to the FIFO queue Example: SenseTask application Gather a serial of sensor reading and full a cyclic buffer Post a task to process the sensor readings Show the readings in the leds

18 Implementation - Tasks Example: SenseTask application The Main module call StdControl, which goes down in the hierarchy and inits (among other things) the Timer module The timer module fires a signal each 500ms (as requested by our application calling a Timer module command), which event handler is implemented by the application. The handler calls a command of the ADC to get the sensor reading, which in turn signals an event when the data is ready Te application handles this event and fills the buffer and posts the task The task analyses the buffer and calls commands that will light the desired leds Note that the buffer, used by the task and the putting data function, is always protected from data races with the atomic keyword

19 Implementation - Main How does everything really start? module RealMain { uses { command result_t hardwareInit(); interface StdControl; interface Pot; } } implementation { int main() __attribute__ ((C, spontaneous)) { call hardwareInit(); call Pot.init(10); TOSH_sched_init(); call StdControl.init(); call StdControl.start(); __nesc_enable_interrupt(); while(1) { TOSH_run_task(); } } } The component RealMain.nc, which starts the hardware, the StdControl chain, the Scheduler and enables the interrupts, is converted into the main(void) function by the NesC compiler. configuration Main { uses interface StdControl; } implementation { components RealMain, PotC, HPLInit; StdControl = RealMain.StdControl; RealMain.hardwareInit -> HPLInit; RealMain.Pot -> PotC; } The Main.nc is just a configuration for quick changes in interface wiring

20 Implementation - Scheduler Tasks are posted to a FIFO queue (which actually a cyclic array buffer) The entries in the queue are pointers to the task function, and a maximum of 8 positions (7 tasks) is defined Scheduling next task just checks there is a task to pick, removes it from the head and executes it Post a task puts the task pointer into the next free slot The scheduler runs as long as there are tasks to pick or, otherwise, sends the system to sleep The scheduler can be found in sched.c

21 Implementation - Network Same procedure as the rest of the modules is used for the network stack. AMStandard.nc implements the AM (radio and serial) functionality: Initializations of radio, UART and timers Management of received packets: Defines event handlers for lower layer events reporting a received message Accepts messages and forwards them to lower layer components Handles the signals of message sent to upper layer.

22 Implementation - Network Radio stack example to the lowest layer Control power of the radio Set radio modes (Rx and Tx) Control the gathering of bytes Set up back off random times if channel busy

23 Implementation - Network AM.h contains the data structure regarding to the network packets typedef struct TOS_Msg { uint16_t addr; uint8_t type; uint8_t group; uint8_t length; int8_t data[TOSH_DATA_LENGTH]; uint16_t crc; uint16_t strength; uint8_t ack; uint16_t time; uint8_t sendSecurityMode; uint8_t receiveSecurityMode; } TOS_Msg; 2 bytes 1 byte 1 byte 1 byte 29 bytes 2 bytes 36 bytes Not acually sent. Required for internal accounting and by the AM interface Other packet structures for security are included (TinySec)

24 Implementation - Stack Due to that tasks are run to completion, it is possible to allocate a single stack that is assigned to the currently executing task The stack in not allocated of fixed size at compile time, but it grows over the physical memory Should it grow too much, we could have problems of overriding frame variables Normally is not a problem, but is unpredictable So what happens when a task is preempted by an event? It stores its return information in the stack

25 Implementation - Stack And what happens if the event handler is preempted by another event? As non two entities can run at the same time, we can still use the same stack for nested interrupts However, nested callings to commands or events are often reorganized by the nesC compiler so they will disappear in actual assembler.

26 Implementation - Sources Ncc (extension of gcc) + gdb + java This Unix tool support is ported to Windows by using the Cygwin Linux emulation layer and applications TinyOS root appscontribdoc tos tools … nesdoc … mica mica2 … Blink … mica mica2 build interfaces libs platforms sensorboards system types mica mica2 …

27 Implementation - Sources Apps One directory for each application with the source One build directory with subdirectories for different platform compilations Doc All applications can be doc-compiled for an specific supported platform The documentation system includes a complete source of components, interfaces and application component graphs Contrib Other parties contributions such as routing or MAC layer protocols Tools Different tools such as matlab or java utilities

28 Implementation - Sources Tos Contains the sources of TinyOS Interfaces: Defines interfaces that might be used when building and wiring applications Libs: Contains components that can be used to offer certain additional functionalities, such as security (TinySec) or SQL-like queries (TinyDB) Platform: Contains platform specific components, which will be used depending on compiling options Sensorboards: The same but with sensor boards and not motes System: TinyOS core with the main components and configurations Types: Contain data structures and related and related functions, such as the AM message frame.

29 Implementation - Compilation Compilation is automated though Makefiles which will include flags and platform specific paths for compiling the given application A Makerules file is included in the root apps directory A local Makefile should be included in applications root directory which will include the Makerules file and override its parameters if necessary An *.exe is provided for the specified platform. Another make command will transform the binary and upload it to the mote if connected to the PC.

30 Implementation - Compilation NesC language, first, transforms the code of all the components into ANSI C and merges it into a single app.c file on the build directory of each application Events and commands are transformed into regular C functions Due to that the same command or event call may exist with the same name on several components, nesC overloads the naming to specify the component. component Example: event result_t Event.handler() { int foo = 2; call Command.go(foo); return SUCCESS; } result_t Example$Event$handler() { int foo = 2; Example$Command$go(foo); return SUCCESS; }

31 Conclusions TinyOS follows an event model that forces an specific structure of its source code The choice is intended for low memory usage while allowing acceptable concurrency Obliges a language extension Obscures the programming and understanding, mainly of the operating system Its advantageous in modularity Achieves its performance goals, but makes the development difficult