Feb 2007WSN Training: First Steps in nesC Programming1 First Steps in TinyOS and nesC Programming Topics  Timer Application: MyApp  Application directory.

Slides:



Advertisements
Similar presentations
TinyOS Tutorial, Part I Phil Levis et al. MobiSys 2003.
Advertisements

1 Tomás Sánchez López July 9, 2004 Real-time & Embedded Systems Laboratory TinyOS … in deep.
Installing DOS and Windows98 under MS Virtual PC.
Developing a WSN application using Crossbow devices and software
CSCI Research Topic Wireless and Sensor Networks TinyOS and Sensor application development using Crossbow sensor products Deepesh Jain.
Reconfigurable Computing S. Reda, Brown University Reconfigurable Computing (EN2911X, Fall07) Lecture 07: Verilog (3/3) Prof. Sherief Reda Division of.
NesC Prepared for the Multimedia Networks Group University of Virginia.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
1 Lab 3 Objectives  Case study: “Hello world” program on motes  Write you first program on mote.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
1 Lab4 Objectives  Learn to read light sensor data from sensor board  Learn to transmit a message containing the sensed data  through Mote serial port.
1 Lab1  Objectives  Get familiar w/ hardware  Mote interface board  Mote  Mote sensor board  Get familiar w/ software  MoteWorks  Programmer’s.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
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.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Programming Motes A TinyOS and TOSSIM Tutorial By: Brent Rood.
Development of a Mica2 Mote Sensor Network Cliff Macklin Bill Ehrbar December 8, 2004 University of Colorado, Colorado Springs.
Using the Visual Basic Editor Visual Basic for Applications 1.
5/5/2003MobiSys 2003 Tutorial TinyOS Tutorial, Part II Robert Szewczyk, Joe Polastre, Phil Levis, David Culler Mobisys 2003.
1 Lab 3 Objectives  Case study: “Hello world” program on motes  Write you first program on mote.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
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.,
Part 1 Using the ARM board And start working with C Tutorial 5 and 6
MoteWorks Installation
Silicon Labs ToolStick Development Platform
Light Sensing Wireless Network with Energy Efficient Routing Algorithm Man-Ting Au Thanh Nguyen Marie Shinotsuka Thomas To Georgia Institute of Technology.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
Visual Basic Chapter 1 Mr. Wangler.
1 Lab 5 Objectives  Use XMesh multi-hop networking service to send sensing data to a base station  Using XServe to display the sensor data message on.
Computing IV Visual C Introduction with OpenCV Example Xinwen Fu.
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.
High Speed Data Converter University
CHAPTER 9 Introducing Microsoft Office Learning Objectives Start Office programs and explore common elements Use the Ribbon Work with files Use.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
Wireless Sensor Networks MOTE-KITS TinyOS Crossbow UC Berkeley.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
OCC Network Drives  H:\  P:\ 
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
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:
Feb 2007WSN Training: Creating a Simple Sensor Application1 A TinyOS Sensor Application called MyApp Objectives  How to create a simple Mote firmware.
Feb 2007WSN Training: XMesh Services1 Lab6 Objectives:  Route Control Interface  Understand XMesh transport services 1.Upstream 2.Upstream with end-to-end.
Asttraining.com Scan Procedures for Ford EEC-V OBD II Systems.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
TinyOS Sandeep Gupta. Operating System (OS) What is an OS? Main functions  Process management  Memory management  Resource management Traditional OSs.
Teaching Digital Logic courses with Altera Technology
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 Lab1: LED Control ZigbeX mote has Red, Yellow, Green LED. This lab using LED control component provided by TinyOS.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
Unit 4: Processes, Threads & Deadlocks June 2012 Kaplan University 1.
Blink Blink.nc configuration Blink { } implementation { components Main, BlinkM, SingleTimer, LedsC; Main.StdControl -> BlinkM.StdControl; Main.StdControl.
Feb 2007WSN Training: XMesh Enabled Sensor App1 Lab 5 Objectives  Use XMesh multi-hop networking service to send sensing data to a base station  Using.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Programming and Debugging with the Dragon and JTAG Many thanks to Dr. James Hawthorne for evaluating the Dragon system and providing the core content for.
TinyOS Sandeep Gupta. TinyOS basics TinyOS is  Single tasking OS  Interrupt driven Written using a Component based language A set of components put.
Tinyos Introduction to Programming Pritee Parwekar.
Making a 24hr Timer.
Simulation of Distributed Application and Protocols using TOSSIM
WSN Training: XMesh Enabled Sensor App
3 Introduction to Classes and Objects.
Explain what touch develop is to your students:
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
An Introduction to nesC
WSN Training: TinyOS/nesC Basic Concepts TinyOS and nesC
Presentation transcript:

Feb 2007WSN Training: First Steps in nesC Programming1 First Steps in TinyOS and nesC Programming Topics  Timer Application: MyApp  Application directory contents  Do and Dissect  Configuration  Wiring  Module  StdControl  Timer  Leds

WSN Training: First Steps in nesC Programming2 Feb 2007 First Steps in TinyOS Programming Objectives  What files needed in an application directory  How to use the Timer and LED components  How to compile and download an application to a Mote  Application: MyApp in /MoteWorks/apps/tutorials/lesson_1/

WSN Training: First Steps in nesC Programming3 Feb 2007 About MyApp This timer application uses one of the timers on the ATmega128L Mote.  The timer will be set to fire continuously every second and the Mote red LED will toggle on and off to show this visually. So why go through the trouble of this program?  This is TinyOS’ version of “Hello World”  To help the learn unfamiliar TinyOS and nesC programming methods

WSN Training: First Steps in nesC Programming4 Feb 2007 /** * This configuration shows how to use the Timer and LED components **/ configuration MyApp { } implementation { components Main, MyAppM, TimerC, LedsC; Main.StdControl -> TimerC.StdControl; Main.StdControl -> MyAppM.StdControl; MyAppM.Timer -> TimerC.Timer[unique("Timer")]; MyAppM.Leds -> LedsC.Leds; } The MoteWorks/apps/tutorials/lesson_1/MyApp MyApp.nc configuration Specifying the INTERFACE Specifying the IMPLEMENTATION TimerCLedsC Main MyApp_Timer MyApp StdControl TimerLeds Timer StdControl

WSN Training: First Steps in nesC Programming5 Feb 2007 Lab Outline 1.Enter/review in all necessary code and auxiliary files 2.Build (compile) and download the application 3.Take a closer look at the code and auxiliary files You should already have these  One MICA Mote: standard editions of MICA2 (MPR4x0) or MICAz (MPR2400) or OEM editions of MICA2 or MICAz  One gateway / programming board: MIB510, MIB520, or MIB600 and the associated hardware (cables, power supply) for each  A Windows PC with MoteWorks installed

WSN Training: First Steps in nesC Programming6 Feb 2007 MyApp Application Review The application folder (directory) is where all your top-level application code and associated files will be stored. 1.Navigate to the directory /MoteWorks/apps/tutorials/ lesson_1

WSN Training: First Steps in nesC Programming7 Feb 2007 Seven Common Files in an Application Directory 1.Makefile (section 5.2.1) 2.Makefile.component (section 5.2.2) 3.Top-level application configuration written in nesC 4.Top-level application module written in nesC 5.sensorboardsApp.h file (not seen here, but typical for applications using sensors and GPIO) 6.appFeatures.h (optional) 7.README (optional, but highly recommended)

WSN Training: First Steps in nesC Programming8 Feb 2007 MyApp Application: Makefile include Makefile.component include $(TOSROOT)/apps/MakeXbowlocal include $(MAKERULES)

WSN Training: First Steps in nesC Programming9 Feb 2007 MyApp – Makefile.component This file describes the top level application component, MyApp, and the name of the sensorboard we are going to use. The sensorboard reference tells the compiler we want to use the nesC components for accessing the sensor devices on that board.  The collection of those components is also known as a “driver” COMPONENT=MyApp SENSORBOARD=mts310

Feb 2007WSN Training: First Steps in nesC Programming10 First Steps in TinyOS and nesC Programming Topics  Application: MyApp  Application directory contents  Do and Dissect  Configuration  Wiring  Module  StdControl interface  Timer interface

WSN Training: First Steps in nesC Programming11 Feb 2007 MyApp – Top Level Configuration What might we have in  The comments?  Application name?  The list of components?  Wiring? /** * **/ configuration { } implementation { components ; Provider.Interface>; }

WSN Training: First Steps in nesC Programming12 Feb 2007 MyApp – Top Level Configuration What is Main? /** * This configuration shows how to use the Timer and LED components **/ configuration MyApp { } implementation { components Main, MyAppM, TimerC, LedsC; Main.StdControl -> TimerC.StdControl; Main.StdControl -> MyAppM.StdControl; MyAppM.Timer -> TimerC.Timer[unique("Timer")]; MyAppM.Leds -> LedsC.Leds; }

WSN Training: First Steps in nesC Programming13 Feb 2007 Main – the scheduler for TinyOS A TinyOS application = configuration (wiring) of new and existing components + the component Main. Main, the scheduler, runs the tasks created by those components. A TinyOS top-level application must have the Main component in its configuration.

WSN Training: First Steps in nesC Programming14 Feb 2007 Main cont’d Main is a component that is executed first in a TinyOS application. The command Main.StdControl.init() is the first command executed in TinyOS followed by Main.StdControl.start(). StdControl is a common interface used to initialize, start, and stop TinyOS components. configuration Main { uses interface StdControl; } implementation { components RealMain, PotC, HPLInit; StdControl = RealMain.StdControl; RealMain.hardwareInit -> HPLInit; RealMain.Pot -> PotC; }

WSN Training: First Steps in nesC Programming15 Feb 2007 MyApp – Top Level Configuration Why does the component TimerC provide a unique Timer? /** * This configuration shows how to use the Timer and LED components **/ configuration MyApp { } implementation { components Main, MyAppM, TimerC, LedsC; Main.StdControl -> TimerC.StdControl; Main.StdControl -> MyAppM.StdControl; MyAppM.Timer -> TimerC.Timer[unique("Timer")]; MyAppM.Leds -> LedsC.Leds; }

WSN Training: First Steps in nesC Programming16 Feb 2007 Parameterized Interfaces (1 of 2)  There may be multiple users of a component  One Timer component but many Users with different event time requirements  When a Timer “fires” which component should be signaled? How does TinyOS handle this ?  Multiple instantiations of a Component’s Interface  Parameter specifies the specific instance

WSN Training: First Steps in nesC Programming17 Feb 2007 Parameterized Interfaces (2 of 2) A parameterized interface allows a component to provide multiple instances of an interface Parameterization (or indexing) is set by a compile-time value provides interface Timer[uint8_t id]; Total number of instances permitted may be limited by implementation

WSN Training: First Steps in nesC Programming18 Feb 2007 nesC Concepts – Unique Instances To make sure your instance parameter is not used by some one else, use unique(“astring”)  Generates an 8-bit identifier from the string given as an argument.  Multiple components using timer[unique(“Timer”)] are each guaranteed to get a signal associated with their specific timer settings. All components must use the same “ astring ”  In our app Timer is used for the astring

Feb 2007WSN Training: First Steps in nesC Programming19 First Steps in TinyOS and nesC Programming Topics  Application Example: Do and Dissect the MyApp_Timer application  Configuration  Wiring  Module  StdControl interface  Timer interface

WSN Training: First Steps in nesC Programming20 Feb 2007 MyApp – Top Level Module The application’s module is located in the MoteWorks/apps/tutorial/lesson_1/MyAppM.nc file.  The function of this code is to start a timer and toggle the red LED on the Mote.

WSN Training: First Steps in nesC Programming21 Feb 2007 MyApp – Top Level Module /** * This module shows how to use the Timer and LED components **/ module MyAppM { provides { interface StdControl; } uses { interface Timer; interface Leds; } The MyAppM module provides the interface StdControl.  To provide an interface means that MyAppM must implement the that interface.  As explained above, this is necessary to get the MyApp component initialized and started. The first part of the code states that this is a module called MyAppM and declares the interfaces which are prefaced by the keywords provides and uses. 1 of 3

WSN Training: First Steps in nesC Programming22 Feb 2007 MyApp – Top Level Module /** * This module shows how to use the Timer and LED components **/ module MyAppM { provides { interface StdControl; } uses { interface Timer; interface Leds; } In many nesC applications, it is common to call a function periodically.  The realization of that function is done by means of a timer. We also want to active one of the LEDs so we use an interface to the LED The name for the interface for a timer is, conveniently enough Timer. The name for the interface for an LED is Leds. 1 of 3

WSN Training: First Steps in nesC Programming23 Feb 2007 nesC Interface – The StdControl Interface (review) The StdControl interface (like the component Main ) must always be implemented at the top-level application.  The StdControl interface provides the basic functionality for the TinyOS application to be initialized, started and stopped. StdControl is like a power switch to turn on and off components  Also does boot time initialization StdControl should not be used for continuous processing  Use a timer instead

WSN Training: First Steps in nesC Programming24 Feb 2007 StdControl Interface Details In /MoteWorks/tos/interfaces/StdControl.nc StdControl defines three commands : init(), start(), and stop().  init() is called when a component is first initialized  start() is called to execute a component  stop() is called when a components is stopped init() can be called multiple times but will never be called after either start() or stop() are called. interface StdControl { command result_t init(); command result_t start(); command result_t stop(); }

WSN Training: First Steps in nesC Programming25 Feb 2007 Mote About the Timer Interface interface Timer { command result_t start(char type, uint32_t interval); command result_t stop(); event result_t fired(); Here we see that Timer interface defines two commands  start() and stop() commands and one event  fired() event What is “ result_t ”?  It is the data type for the status value returned by a command or event.  This status value is either SUCCESS or FAIL.

WSN Training: First Steps in nesC Programming26 Feb 2007 Mote About the Timer Interface (cont’d) interface Timer { command result_t start(char type, uint32_t interval); command result_t stop(); event result_t fired(); The start() command is used to specify the type of the timer and the interval at which the timer will expire.  The unit of the interval argument is millisecond. The valid types of timers  TIMER_ONE_SHOT  Ends after the specified interval  TIMER_REPEAT  Goes on and on until it is stopped by the stop() command.

WSN Training: First Steps in nesC Programming27 Feb 2007 MyApp – Timer interface (cont’d) interface Timer { command result_t start(char type, uint32_t interval); command result_t stop(); event result_t fired(); How does an application know that its timer has expired?  When it receives an event. What is an event?  A signal from the implementation of an interface that something has occurred.  In this case, the fired() event is signaled when the time interval has passed. This is an example of a bi-directional interface  An interface can both provide commands that can be called by users of the interface, and signal events of call handlers implemented by the user.  Remember: A module that uses an interface must implement the events that this interface uses.

WSN Training: First Steps in nesC Programming28 Feb 2007 MyApp – Top Level Module implementation { /** * Initialize the components. * Always returns SUCCESS **/ command result_t StdControl.init() { call Leds.init(); return SUCCESS; } /** * Start things up. This just sets the rate for the clock * component. * Always returns SUCCESS **/ command result_t StdControl.start() { // Start a repeating timer that fires every 1000ms return call Timer.start(TIMER_REPEAT, 1000); } The MyAppM module implements the StdControl.init(), StdControl.start(), and StdControl.stop() commands, since it provides the StdControl interface. 1 of 6

WSN Training: First Steps in nesC Programming29 Feb 2007 MyApp – Top Level Module implementation { /** * Initialize the components. * Always returns SUCCESS **/ command result_t StdControl.init() { call Leds.init(); return SUCCESS; } /** * Start things up. This just sets the rate for the clock * component. * Always returns SUCCESS **/ command result_t StdControl.start() { // Start a repeating timer that fires every 1000ms return call Timer.start(TIMER_REPEAT, 1000); } The init() command in the implemented StdControl interface simply initializes the Leds subcomponent with the call to Leds.init(). 2 of 6

WSN Training: First Steps in nesC Programming30 Feb 2007 MyApp – Top Level Module implementation { /** * Initialize the components. * Always returns SUCCESS **/ command result_t StdControl.init() { call Leds.init(); return SUCCESS; } /** * Start things up. This just sets the rate for the clock * component. * Always returns SUCCESS **/ command result_t StdControl.start() { // Start a repeating timer that fires every 1000ms return call Timer.start(TIMER_REPEAT, 1000); } The start() command invokes Timer.start() to create a repeat timer (“ TIMER_REPEAT ”) that expires every 1000 msec. 3 of 6

WSN Training: First Steps in nesC Programming31 Feb 2007 MyApp – Top Level Module /** * Halt execution of the application. * This just disables the clock component. * Always returns SUCCESS **/ command result_t StdControl.stop() { return call Timer.stop(); } /** * Toggle the red LED in response to the Timer.fired * event. * Always returns SUCCESS **/ event result_t Timer.fired() { call Leds.redToggle(); return SUCCESS; } stop() terminates the timer. 4 of 6

WSN Training: First Steps in nesC Programming32 Feb 2007 MyApp – Top Level Module /** * Halt execution of the application. * This just disables the clock component. * Always returns SUCCESS **/ command result_t StdControl.stop() { return call Timer.stop(); } /** * Toggle the red LED in response to the Timer.fired * event. * Always returns SUCCESS **/ event result_t Timer.fired() { call Leds.redToggle(); return SUCCESS; } The Timer.fired() event is implemented. This is necessary since MyAppM must implement any event from an interface it uses.. 5 of 6

WSN Training: First Steps in nesC Programming33 Feb 2007 MyApp_Timer – Top Level Module /** * Halt execution of the application. * This just disables the clock component. * Always returns SUCCESS **/ command result_t StdControl.stop() { return call Timer.stop(); } /** * Toggle the red LED in response to the Timer.fired * event. * Always returns SUCCESS **/ event result_t Timer.fired() { call Leds.redToggle(); return SUCCESS; } Each time Timer.fired() event is triggered, the Leds.redToggle() toggles the red LED. 6 of 6

WSN Training: First Steps in nesC Programming34 Feb 2007 MyAppM.nc – Key Lessons  The heart of most TinyOS applications is Timer.fired()  Compare to C where main() contains a while loop  A while loop in StdControl.init() would freeze the system and block all tasks  The proper way to centralize processing in TinyOS is to start a repeat timer (with REPEAT_TIMER ) and implement logic in Timer.fired().

Feb 2007WSN Training: First Steps in nesC Programming35 First Steps in TinyOS and nesC Programming Topics  Application: MyApp  Application directory contents  Do and Dissect  Configuration  Wiring  Module  StdControl  Timer  Programming with Programmer’s Notepad

WSN Training: First Steps in nesC Programming36 Feb 2007 MyApp_Timer – Compiling and Flashing the Mote 1.Now that you have reviewed all the application files, we can proceed with the compilation and flashing of the Mote  You need to be in the.nc of the app file you want to compile and program before you can execute shell commands from Programmer’s Notepad. 2.Attach one Mote to a Programmer/Gateway Board  One of MIB510, MIB520, MIB600  One of MICAz, MICA2 3.Compile your application: 1.Select Tools > make mica2 (or make micaz or make mica2dot) 2.The “Output” section of the Programmers Notepad will print the compiling results to the screen:

WSN Training: First Steps in nesC Programming37 Feb 2007

WSN Training: First Steps in nesC Programming38 Feb 2007 MyApp – Compiling and Flashing the Mote 4.Flash your Mote:  Select Tools > shell  In the command line type make install, mica2, or micaz, or mica2dot

WSN Training: First Steps in nesC Programming39 Feb 2007 Lab 1 Change the application so that the yellow or green LED blinks Challenge exercise: Setup two timers so that the yellow or green LED flashes at an some multiple of the red LED  See “Challenge_Apps” directory in WSN training CD for one solution Challenge exercises do not have “answers in the back of the book.”

WSN Training: First Steps in nesC Programming40 Feb 2007 Lab: Change Line 86 of BlinkM.nc Open Programmers Notepad window and navigate to the Blink directory: /MoteWorks/apps/general/Blink Change from call Leds.redToggle(); to call Leds.yellowToggle();

WSN Training: First Steps in nesC Programming41 Feb 2007 Lab: Step 2 -- Compile Compile an application in Programmer’s Notepad A.Method 1: Click on Tools > Shell Type make install and enter into the User Input Parameter dialog box B.Method 2: See next slide Exchange with one of the following mica2 micaz mica2dot Exchange with one of the following mica2 micaz mica2dot

WSN Training: First Steps in nesC Programming42 Feb View compiler output 1. Type in make command then hit “Enter” Lab: Step 2 — Compiling

Feb 2007WSN Training: First Steps in nesC Programming43 Q & A: First Steps in nesC Programming Timer Application: MyApp  Application directory contents  Do and Dissect  Configuration  Wiring  Module  StdControl  Timer  Leds  Programming with Programmer’s Notepad

WSN Training: First Steps in nesC Programming44 Feb 2007 Vocabulary Application Component Module Configuration Interface Makefile Makefile.component nesC TinyOS Provides Uses implementation Command Event Call Return – SUCCESS, FAIL Make StdControl – init(), start(), stop() TimerM Leds interface LedsC Timer interface -- TIMER_REPEAT, TIMER_ONE_SHOT docs