1 / 23

Lab 3

Lab 3. Introduction to TinyOS and nesC How to debug programs at PC Examples Blink Timer Blink Hellow World Reference: www.tinyos.net/tinyos-1.x/doc/tutorial/lesson1.html. TinyOS and nesC. The TinyOS system, libraries, and applications are written in necC.

lefty
Download Presentation

Lab 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab 3 • Introduction to TinyOS and nesC • How to debug programs at PC • Examples • Blink Timer • Blink • Hellow World • Reference: www.tinyos.net/tinyos-1.x/doc/tutorial/lesson1.html

  2. TinyOS and nesC • The TinyOS system, libraries, and applications are written in necC. • The nesC language is a new language for programming structured component-base application, and is intended for embedded systems. • necC is a C-like syntax, but supports the TinyOS concurrency model, as well as mechanisms for structuring, naming, and linking together software components into robust network embedded systems.

  3. nesC application • Components • modules • configuration • Interfaces • “provide” interfaces • “use” interfaces • commands • events

  4. Components • A nesC application consists of one or more components linked together. • A component provides and usesinterfaces. • There are two types of components; • module • configuration

  5. module and configuration • A module provides application code, implementing one or more interface. • A configuration is used to assemble other components together, connecting interfaces used by components to interfaces provided by others, which is called wiring. • Every nesC application is described by a top-level configuration that wires the components inside together.

  6. Example application: Blink • The application simply causes the red LED on the mote to turn and off at 1 Hz. • …/apps/Blink • It consists of two components: • a module: “BlinkM.nc” • a configuration: “Blink.nc” : top-level configuration

  7. Blink.nc configuration • All application require a top-level configuration, which is typically named after the application itself. Blink.nc configuration Blink {}implementation { components Main, BlinkM, SingleTimer, LedsC; Main.StdControl -> BlinkM.StdControl; Main.StdControl -> SingleTimer.StdControl; BlinkM.Timer -> SingleTimer.Timer; BlinkM.Leds -> LedsC;}

  8. Components and Interfaces of Blink Timer LedsC Leds BlinkM StdControl Timer Main SingleTimer StdControl

  9. Main component • Main is a component that is executed first in an application. The Main.StdControl.init() command is the first command executed. • StdControl is a common interface used to initialize and start components. • tos/interfaces/StdControl.nc StdControl.nc interface StdControl {  command result_t init();  command result_t start();  command result_t stop();}

  10. Calling init() must make it call init() on all of its subcomponents. • The subcomponent initialization functions must be explicitly called by the using components. For example, the BlinkM module uses the interface Leds, so Leds.init() is called explicitly in BlinkM.init(). Main.StdControl -> BlinkM.StdControl; Main.StdControl -> SingleTimer.StdControl;

  11. “provide” and “use” interface Main.StdControl -> BlinkM.StdControl; BlinkM.Timer -> SingleTimer.Timer; BlinkM.Leds -> LedsC; LedsC Leds BlinkM StdControl Timer (tos/interfaces/Timer.nc) Main SingleTimer StdControl (tos/lib/SingleTimer.nc)

  12. BlinkM interfaces StdControl “BlinkM provides the Interface.” BlinkM Leds Timer “BlinkM uses the Interface.”

  13. Blink module: BlinkM • BlinkM provides the interface StdControl. • BlinkM implements the StdControl interface. • BlinkM uses the interfaces: Leds and Times. • BlinkM may call any command declared in the interfaces it uses and must also implement any events declared in the interfaces. BlinkM.nc module BlinkM {provides { interface StdControl; }uses { interface Timer; interface Leds; }}

  14. 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; }}

  15. Leds interfaces • The Leds interface defines several commands: • Leds.init() • Leds.redOn() • Leds.redOff() • Leds.redToggle() • Leds.greenOn() • Leds.greenOff() • Leds.greenToggle() • Leds.yellowOn() • Leds.yellowOff() • Leds.yellowToggle() • Because BlinkM uses this inteface, it can invoke any of these commands.

  16. Timer interface(1) /tos/interfaces/Timer.nc Timer.nc interface Timer { command result_t start(char type, uint32_t interval);command result_t stop();event result_t fired();} • Start() is used to specify the type of timer and the interval at which the timer is expired. • Type of timer: (TIMER_REPEAT, TIMER_ONE_ONE_SHOT)

  17. Timer interface(2) • An event is a function that the implementation of an interface will signal when a certain event takes place. • The fired() event is signaled when the specific interval has passed. • A module that uses an interface must implement the events that this interface uses. • An interface not only provides commands that can be called by users of the interface, but also signals events that call handlers in the user.

  18. Program debugging: TOSSIM • cd /opt/tinyos-1.x/tools/java/org/python • make • cd ../apache • make

  19. Program debugging • Add the following line in the source code. • dbg(DBG_USR1, “data_event\n”); • Compile the source code for PC. • make pc • Execute on cygwin • export DBG=usr1 • ./build/pc/main.exe 1

  20. TOSSIM other options • ./build/pc/main.exe –h

  21. Tinyviz • Simulate the execution of the application program on a graphic display. • Type the following on cygwin • cd /opt/tinyos-1.x/apps/Oscilloscope • make clean • make pc • export DBG=led • $tinyviz –run $main 5

  22. Example applications • Blink • /opt/tinyos-1.x/contrib/zigbex/Blink.nc • Helloworld • /opt/tinyos-1.x/contrib/zigbex/helloworld.nc

  23. Exercise • Understand the code of the application Helloworld. • Modify helloworldM.nc to display “hello world” only once.

More Related