
TinyOS Tutorial Mo Sha Fall 2012 Outline Installing TinyOS and Building Your First App Hardware Primer Basic nesC Syntax Advanced nesC Syntax Network Communicaon Sensor Data AcquisiAon Debugging Tricks and Techniques 2 TinyOS Installation TinyOS Community hHp://www.Anyos.net/ Various installaon opAons listed under “Geng started” secAon 3 TinyOS Installation (cont.) 4 TinyOS Installation (cont.) 5 TinyOS Installation (cont.) Pre-compiled .rpm and .deb packages for Fedora and Ubuntu Linux users Ubuntu users: be sure to remove brltty package Automa?c installa?on for debian systems using the TinyOS debian repository (Manual install TI MSP430 Tools) All necessary drivers already included with Linux kernel OS X unofficially supported but works well Windows installaon uses Cygwin to emulate Linux so\ware layer Works well under XP, refuses to work on some Vista/7 machines (updang Cygwin aer the installaon may help) Step 5b (oponal): Post-install fixes in Windows/Cygwin environment “Running a XubunTOS Virtual Machine Image in VMware Player” 6 Post-install +ixes in Windows/Cygwin TinyOS Installation (cont.) OS X unofficially supported but works well Precompiled packages available at hHp://students.cec.wustl.edu/~ms31/Anyos-2.1.1.dmg Need to install pySerial (hHp://pyserial.sourceforge.net) and FTDI FT232R serial drivers (hHp://www.\dichip.com/Drivers/VCP.htm) separately Can also compile using MacPorts: see TinyOS Wiki 8 TinyOS Installation Problems If you run tos-check-env and it says: -> WARNING: CLASSPATH environment variable doesn't exist. then add: export CLASSPATH=/opt/tinyos-2.1.1/support/sdk/java/ tinyos.jar:. to your .bash_profile or .bash_aliases file 9 TinyOS Installation Problems If you try to run make micaz sim and it gives you a long error message starAng with: ...: error: inttypes.h: No such file or directory then you need to install the C library/header files for your own architecture On Ubuntu/Debian, run apt-get install build-essential 10 TinyOS Directory Structure /opt/Anyos-2.1.1 ($TOSROOT) apps support • make • sdk tools tos 11 make System $TOSROOT/support/make includes lots of Makefiles to support the build process Create a simple stub Makefile in your app directory that points to main component COMPONENT=[MainComponentC] SENSORBOARD=[boardtype] # if needed include $(MAKERULES) make [platform] in app directory Builds but does not install program platform: one of the plaorms defined in $TOSROOT/tos/ platforms (mica2, micaz, telosb) 12 make System make [re]install.[node ID] [platform] [programming options] node ID: 0 - 255 programming opAons: • mica2/micaz: mib510,/dev/ttyXYZ • telosb: bsl,/dev/ttyXYZ make clean make docs [platform] Generates HTML documentaon in $TOSROOT/doc/nesdoc/ [platform] 13 Useful commands motelist See the list of motes connecting with pc make telosb Compile your code make telosb reinstall,1 Program the mote make telosb install,1 Compile your code Program the mote make docs telosb Generate docs 14 Build Stages Preprocess .nc to .c, then compile .c to binary Set AM address and node ID in binary Program mote 15 Example under Windows C:\cygwin\bin http://students.cec.wustl.edu/~ms31/520S/ 16 “Homework” Install TinyOS 2.1.1 and build Blink (Not graded, but a good idea to make sure you have everything up and running) 17 How to Get Help TinyOS Documentaon Wiki: hp://docs.nyos.net TinyOS Programming Manual: 139-page PDF intro to nesC and TinyOS 2.x: hHp://www.Anyos.net/Anyos-2.x/doc/pdf/Anyos- programming.pdf TinyOS Tutorials: short HTML lessons on using parts of TinyOS (sensors, radio, TOSSIM, etc.): hHp://docs.Anyos.net/Anywiki/index.php/TinyOS_Tutorials 18 How to Get Help nesdoc: annotated API for all interfaces and components in TinyOS: hHp://docs.Anyos.net/Anywiki/index.php/ Source_Code_Documentaon TinyOS Enhancement Protocols (TEP): formal documentaon for TinyOS features: hHp://docs.Anyos.net/Anywiki/index.php/TEPs 20 Outline Installing TinyOS and Building Your First App Hardware Primer Basic nesC Syntax Advanced nesC Syntax Network Communicaon Sensor Data AcquisiAon Debugging Tricks and Techniques 21 Available Hardware Motes, sensor boards, and gateways Most up to date list here: hHp://wsn.cse.wustl.edu/index.php/ Equipment_for_course_projects Hardware is in Mobile CompuAng Laboratory (Jolley 519) 22 Tmote Sky (aka TelosB) IEEE 802.15.4 Radio 250kbps TI MSP430 microcontroller 16MHz, 16 MIPS, 10kB RAM Integrated antenna & USB interface Low power uAlizaon 1.8mA/5.1µA vs. Mica 2’s 8mA/15µA QuanAty w/o on-board sensors: 6 QuanAty w/temperature, light, and humidity sensors: 20 QuanAty w/SBT80 sensor board: 4 23 MICA2 Mote (MPR400CB) 128KB InstrucAon EEPROM 2 AA 4KB Data EEPROM 512KB Chipcon Atmel External ATmega128L μP CC1000 radio, Flash 38K or 19K baud, 7.3827MHz (8 MIPS) UART 2 Manchester, Memory 315, 433, or SPI bus 900MHz ADC 0-7 UART 1 I2C Bus 3 LEDs To Sensors, JTAG, and/or Quantity: 56 51 pin I/O Connector Programming Board 24 MPR2400 MICAz Same as Mica2 except with IEEE 802.15.4 radio 2.4GHz 250kbps QuanAty: 7 25 Programming Board (MIB510) Mote JTAG MICA2Dot interface Serial interface to laptop MICA2 interface ISPJTAG Block data to laptop 5V Power Quantity: 3 Reset 26 MTS310CA Sensor Board 51 pin MICA2 4.6KHz Interface Speaker Tone Detector Light and 2 Axis Temperature Accelerometer Microphone Magnetometer Quantity: 3 27 NSLU2 Network Storage Link (“Slug”) 266MHz Xscale CPU, 32MB SDRAM, 8MB flash, 1x Ethernet port Wired power No built-in radio, but 2x USB 2.0 ports for add-on 802.11/Bluetooth/mote interface Can be easily converted to an embedded Linux box with third-party firmware Our testbed uses the OpenWrt distribuAon (hHp://openwrt.org) QuanAty: 15 28 MCS410 Cricket Mote A Mica2 mote with ultrasound Rx/Tx Indoor localizaon 10.5m range Distance accuracy: 1 cm (< 3.5m dist) 2cm (>3.5m dist) Mote finds distance, PC finds locaon hHp://cricket.csail.mit.edu/ QuanAty: 9 29 Outline Installing TinyOS and Building Your First App Hardware Primer Basic nesC Syntax Advanced nesC Syntax Network Communicaon Sensor Data AcquisiAon Debugging Tricks and Techniques 30 TinyOS Execution Model To save energy, node stays asleep most of the Ame Computaon is kicked off by hardware interrupts Interrupts may schedule tasks to be executed at some Ame in the future TinyOS scheduler conAnues running unAl all tasks are cleared, then sends mote back to sleep z z z HandlePacket ReadSensor TimerFired 31 TinyOS Component Model Upper Layer Provides Provides Provides Split Control Send Receive ActiveMessageC 32 TinyOS Component Model Upper Layer command Provides Provides Provides Split Control Send Receive Start() ActiveMessageC 33 TinyOS Component Model Upper Layer Event Provides Provides Provides Split Control Send Receive Startdone( ) ActiveMessageC 34 Components != Objects AppLogicP NetworkHandlerP AnotherHandlerP ✓ ✗ AcAveMessageC AcAveMessageC AcAveMessageC 35 Interfaces List of exposed events and commands Like ordinary C funcAon declaraons, except with event or command in front interface Receive { event message_t * Receive(message_t * msg, void * payload, uint8_t len); command void * getPayload(message_t * msg, uint8_t * len); command uint8_t payloadLength(message_t * msg); } 36 Modules Modules provide the implementaon of one or more interfaces They may consume (use) other interfaces to do so module ExampleModuleP { provides interface SplitControl; uses interface Receive; uses interface Receive as OtherReceive; } implementation { ... } “Rename” interfaces with the as keyword -- required if you are using/providing more than one of the same interface! 37 Modules implementation block may contain: Variable declaraons Helper funcAons Tasks Event handlers Command implementaons 38 Modules: Variables and Functions Placed inside implementation block exactly like standard C declaraons: ... implementation { uint8_t localVariable; void increment(uint8_t amount); ... void increment(uint8_t amount) { localVariable += amount; } } 39 Modules: Tasks Look a lot like funcAons, except: Prefixed with task Can’t return anything or accept any parameters implementation { ... task void legalTask() { // OK } task bool illegalTask() { // Error: can’t have a return value! } task void anotherIllegalTask(bool param1) { // Error: can’t have parameters! } } 40 Modules: Task Scheduling Tasks are scheduled using the post keyword post handlePacket(); TinyOS guarantees that task will eventually run Default scheduling policy: FIFO task1 task1 task2 task1 task3 ... ✓ ✗ 41 Modules: Commands and Events Commands and events also look like C funcAons, except: they start with the keyword command or event the “funcAon” name is in the form InterfaceName.CommandOrEventName e.g. implementation { command error_t SplitControl.start() { // Implements SplitControl’s start() command } event message_t * Receive.receive(message_t * msg, void * payload, uint8_t len) { // Handles Receive’s receive() event } } 42 Modules: Commands and Events Commands are invoked using the call keyword: call Leds.led0Toggle(); // Invoke the led0Toggle command on the Leds interface Event handlers are invoked using the signal keyword: signal SplitControl.startDone(); // Invoke the startDone event handler on the SplitControl interface 43 Modules: Commands and Events A command, event handler, or funcAon can call or signal any other command or event from any interface wired into the module: module ExampleModuleP { uses interface Receive; uses interface Leds; } implementation
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages133 Page
-
File Size-