1 / 35

TinyOS and NesC

TinyOS and NesC. Manjunath D, Cs 4222 Semester II, 2011/2012. Hardware: Motes and Sensors. Configuration of a typical mote. Sensors. TelosB. 16-bit 8 MHz processor. 10 KB RAM. Microcontroller (TIMSP430). 12-bit ADC. 48 KB internal flash. Smart dust. Radio transceiver of 250 Kbps.

ona
Download Presentation

TinyOS and NesC

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. TinyOS and NesC Manjunath D, Cs 4222 Semester II, 2011/2012

  2. Hardware: Motes and Sensors Configuration of a typical mote Sensors TelosB 16-bit 8 MHz processor 10 KB RAM Microcontroller (TIMSP430) 12-bit ADC 48 KB internal flash Smart dust Radio transceiver of 250 Kbps 2 AA batteries SBT30 sensor

  3. TinyOS and NesC: Installation • An overview of the steps involved in using TinyOS and NesC • PC-side • Install TinyOS and NesC • Write and compile your programs • Test your executables in a simulation environment • Finally, executables are loaded on to the mote devices • Mote-side • Loaded executables are executed on the mote devices

  4. TinyOS and NesC: PC-Side Installation • On the PC-side, we encourage you to use Ubuntu Linux: http://www.ubuntu.com/ • A three-step process for installation • Edit the file “/etc/apt/sources.list” to include the following line • “deb http://tinyos.stanford.edu/tinyos/dists/ubuntu <version_name> main” • Command “lsb_release –a” will tell you the <version_name> • Execute commands • “apt-get update” and “apt-get install tinyos-2.1.1” • Set environment variables • Add the line “source /opt/tinyos-2.1.1/tinyos.sh” to “/home/xxx/.bashrc”

  5. TinyOS and NesC: PC-Side Installation (Contd..) • Installation is somewhat painful on other OSs • Every package has to be installed manually • Details for Windows, Redhat Linux, and MAC can be found here http://docs.tinyos.net/index.php/Getting_started • Learning Unix commands is inevitable as Cygwin is mandatory on Windows so why not Ubuntu Linux ? • You can use Ubuntu Linux’s virtual image containing TinyOS and NesC on Windows http://docs.tinyos.net/index.php/Getting_started

  6. TinyOS and NesC: PC-Side Installation (Contd..) • Directory structure • Parent directory /opt/tinyos-2.1.1/ • Applications /opt/tinyos-2.1.1/apps/ • System libraries /opt/tinyos-2.1.1/tos/ • Supporting tools /opt/tinyos-2.1.1/support/

  7. TinyOS: Design • Process management • Application plus OS is a single program and a single process Application+OS Main() { } func1(){ } func2(){ } func3(){ } func4(){ } funcN(){ } Image of a TinyOS Program

  8. TinyOS: Design • Process management • Multiprocessing is expensive in terms of memory RAM 0X00000 Global variables (BSS) Process 2 Process N stack stack Process 3 Process 1 Each process has to be allocated with a separate stack memory Stack stack stack TinyOS’s single stack • Only interrupts are allowed to preempt the execution

  9. TinyOS: Design • Memory management • Virtual memory is not supported • Memory is not protected • File systems • Proposed file systems are not popular

  10. TinyOS: Components • TinyOS is a library of components • A specific component implements a specific set of services • A component in turn can be a collection of sub-components Routing Temperature Network Sensors MAC Light Microphone Radio Leds USB Flash TinyOS

  11. TinyOS: Components (Contd..) Building an application over TinyOS AppC TinyOS Routing Temperature Network Sensors MAC Light Microphone Radio Leds USB Flash

  12. TinyOS: Components (Contd..) • Component interfaces • Component services are accessed via interfaces Send Receive Network

  13. TinyOS: Components (Contd..) • Interface commands • Instruct components to perform its specific tasks getTemperature SampleSensors getLight Sensors getMagnetometer getAccelerometer

  14. TinyOS: Components (Contd..) • Interface events • Applications are responsible for specifying an action on an occurrence of an event PacketReceive sendDone Network Receive Send Application Application • Events are also essential as system calls in TinyOS are non-blocking

  15. TinyOS: Components (Contd..) • A few commonly used TinyOS components • LedsC • TimerC • ActiveMessageC • Some components to sample sensors

  16. TinyOS: Components (Contd..) • LedsC • Allows to control the 3 LEDS on the motes • Provided interfaces • Leds • Commands • led0Toggle() • led1Toggle() • led2Toggle() • ledoOn • led0Off • ………

  17. TinyOS: Components (Contd..) • TimerC • Lets to carryout a task after a specified interval or periodically • Provided interfaces • Timer • Commands • startPeriodic(int period_millisec) • startOneShot(int period_millisec) • stop() • …… • Events • fired()

  18. TinyOS: Components (Contd..) • ActiveMessageC (TinyOS’s Network component) • Allows to communicate over the radio • Provided interfaces • AMSend • Commands • send(destination, packet, size) • Events • sendDone(packet, error) • Receive • Events • receive(packet, payload, size)

  19. NesC: Design NesC is designed to implement TinyOS components NesC is a pre-processor to the C compiler NesC program NesC preprocessor C program C compiler (gcc) Binary for the mote platform NesC Compilation Process

  20. NesC Programs over TinyOS • The best way to learn NesC is to dig into a few examples of NesC programs over TinyOS • Hello-world program • A simple application that toggles (blinks) the red LED on a mote once in every 2 seconds

  21. Configuration component Module component (BlinkC) uses { components LedsC, TimerC, interface Leds; MainC; interface Timer; components BlinkC; interface Boot; } implementation { BlinkC.Leds -> LedsC; implementation { BlinkC.Timer -> TimerC; event Boot.booted() { } BlinkC.Boot -> MainC; } call Timer.startPeriodic(2000) ; event Timer.fired() { } TimerC interfaces: Timer commands: startPeriodic() events: fired() LedsC interfaces: Leds commands: led0Toggle() led1Toggle()….. call Leds.led0Toggle() ; }

  22. NesC Programs over TinyOS (Contd..) • Compile and upload the Blink application • Include a Makefile containing the following two lines COMPONENT=BlinkAppC include $(MAKERULES) • Compilation • Type make telosb in the same directory where the Makefile and your application components are located • Uploading an exe image on to a mote • Type make telosb reinstall.NODEID bsl,addr_usb_port in the same directory • Command “motelist” will give you the addr_usb_port e.g., make telosb reinstall.1 bsl,/dev/ttyUSB0

  23. NesC Programs over TinyOS (Contd..) • A simple networking example • A packet is communicated from a sender to a receiver with the sender turning ON the red LED after transmission and the receiver switches ON the green LED on receiving the packet

  24. Configuration component Module component components ActiveMessageC, uses { interface AMSend; LedsC, MainC; interface Receive; interface SplitControl; ActiveMessageC interface: AMSend commands: send() events: sendDone() interface: Receive events: receive () interface: SplitControl commands: start() events: startDone() interface Boot; } implementation { message_t packet; event Boot.booted() { } call SplitControl.start() LedsC interfaces: Leds commands: led0Toggle() led1Toggle()….. event SplitControl.startDone() { } call AMSend.send(2, &packet, 10);

  25. Configuration component Module component components ActiveMessageC, event AMSend.sendDone(packet, error) { if(error == SUCCESS) { call Leds.led0On(); } else { // Retransmit if you need } } LedsC, MainC; ActiveMessageC interface: AMSend commands: send() events: sendDone() interface: Receive events: receive () interface: SplitControl commands: start() events: startDone() event Receive.recevie(packet, payload, size) { call Leds.led1On(); } LedsC interfaces: Leds commands: led0Toggle() led1Toggle()….. }

  26. Module component (NetC) Configuration component uses { interface AMSend; components ActiveMessageC, interface Receive; LedsC, MainC; interface SplitControl; components NetC; interface Boot; implementation { } NetC.AMSend -> ActiveMessageC.AMSend; implementation { message_t packet; event Boot.booted() { } NetC.Receive -> ActiveMessageC.Receive; call SplitControl.start() NetC.SplitControl -> ActiveMessageC; event SplitControl.startDone() { } NetC.Boot -> MainC; } call AMSend.send(2, &packet, 10);

  27. Module component (NetC) Configuration component uses { interface AMSend; components ActiveMessageC, interface Receive; LedsC, MainC; interface SplitControl; components NetC; interface Boot; implementation { } NetC.AMSend -> ActiveMessageC.AMSend; NetC.Receive -> ActiveMessageC.Receive; event Receive.recevie(packet, payload, size) { call Leds.led1On(); } NetC.SplitControl -> ActiveMessageC; NetC.Boot -> MainC; }

  28. Module component (NetC) Configuration component uses { interface AMSend; components ActiveMessageC, interface Receive; LedsC, MainC; interface SplitControl; components NetC; interface Boot; implementation { } NetC.AMSend -> ActiveMessageC.AMSend [240]; NetC.Receive -> ActiveMessageC.Receive[240]; event Receive.recevie(packet, payload, size) { call Leds.led1On(); } NetC.SplitControl -> ActiveMessageC; NetC.Boot -> MainC; }

  29. NesC Programs over TinyOS (Contd..) • An example of serial communication over USB • Send a command from a PC to a mote that triggers the mote to send a packet back to the PC (PC mote communication) SF-client TCP SF protocol SF TCP mote SF-client Required set-up for serial communication PC

  30. NesC Programs over TinyOS (Contd..) • Executing serial communication programs on the PC-side • SF is a gateway program that lets multiple clients to communicate with a mote ./sf tcp_port_num usb_dev_addr telosb • Two programs constituting the SF-client ./send host_addr sf_port_num input_values ./receive host_addr sf_port_num • These programs are available in C, Python, and Java • You do not have to learn any of these languages – knowing to execute their programs is sufficient !!!!

  31. NesC Programs over TinyOS (Contd..) • TinyOS component to be used on the mote-side • SerialActiveMessageC (Very similar to the ActiveMessageC) • Provided interfaces • AMSend • Receive • SplitControl

  32. Configuration component Module component (SerialC) SerialActiveMessageC, components uses { components SerialC, MainC; LedsC, interface AMSend; interface Receive; implementation { SerialC.AMSend->SerailActiveMessageC.AMSend[240]; interface SplitControl; SerialC.Receive->SerialActiveMessageC.Receive[240]; interface Boot; } SerialC.SplitControl->SerialActiveMessageC; implementation { SerialC.Boot-> MainC; message_t packet; } event Boot.booted() { call SplitControl.start(); } event AMSend.sendDone(packet, error) { if(error == SUCCESS) { call Leds.led0On(); } else { // Retransmit if you need } } event SplitControl.startDone() { } event Receive.recevie(packet, payload, size) { call Leds.led1On(); call AMSend.send(addr, &packet, 10); } }

  33. Programming Assignment 1 • A simple application aimed to warm you up for more programming on TinyOS/NesC • Students mainly learn • Basic architecture of TinyOS/NesC • Compilation and downloading of TinyOS code on to motes • PC<->Mote communication • Application is to turn a desired LED(s) ON/OFF for a desired duration of time • Application involves programming on both PC- and mote-side

  34. Programming Assignment 1 (Contd..) • PC-side • Design a client that communicates a few parameters to the mote and displays messages received from the mote • A command line interface is sufficient, no need for GUI • Mote-side • Program should receive the parameters that the client transmits and send an ACK back to the client • LEDS must be controlled as instructed by the input parameters

  35. Programming Assignment 1 (Contd..) • Submission • Submit your code zipped/tarred to IVLE workbin • The code should be compilable and include a README file explaining how to compile and how the program works • Grading • 25 points – Correct choice of components and compilation • 25 points – PC to mote communication • 25 points – Mote to PC communication • 25 Points – Desired control of LEDS • Weightage towards final assessment is 5%

More Related