Introduction to TinyOS 2.x - PowerPoint PPT Presentation

Loading...

PPT – Introduction to TinyOS 2.x PowerPoint presentation | free to view - id: 29ed0-YTZlO



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Introduction to TinyOS 2.x

Description:

Ubuntu. Mac OS. Gentoo. XubunTOS. Compiling. After installing TinyOS, start compiling! 1. Go into the Blink application directory $ cd tinyos-2.x/apps/Blink ... – PowerPoint PPT presentation

Number of Views:544
Avg rating:3.0/5.0
Slides: 64
Provided by: alyc
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Introduction to TinyOS 2.x


1
Introduction to TinyOS 2.x
  • David Moss
  • Rincon Research Corp.

2
Installing TinyOS 2.x
  • Read the installation tutorials on
  • http//docs.tinyos.net
  • Windows (using cygwin)
  • Linux
  • Ubuntu
  • Mac OS
  • Gentoo
  • XubunTOS

3
Compiling
  • After installing TinyOS, start compiling!
  • 1. Go into the Blink application directory
  • cd tinyos-2.x/apps/Blink
  • 2. Compile the application
  • make mica2dot
  • Make this application for the Mica2Dot platform

4
Compiling
5
Compiling
  • Output from compiling
  • build/mica2dot/main.exe
  • build/mica2dot/main.ihex
  • build/mica2dot/main.srec
  • Next step get it on the microcontroller.

6
Installing to a Mica2Dot
  • 1. Connect your node to the programmer.
  • 2. Plug the programmer into the computer.
  • Assuming your programmer is connected to COM1
    (ttyS0)
  • Compile and install
  • make mica2dot install mib510,/dev/ttyS0
  • Install an application youve previously
    compiled
  • make mica2dot reinstall mib510,/dev/ttyS0

7
TinyOS Basics
8
TinyOS Features
  • Developed for resource constrained wireless
    sensor networks
  • Ultimately not limited by WSNs.
  • Features a task scheduler
  • Automatically puts the microcontroller to sleep
    when there is no code to execute.
  • Allows for concurrency
  • Lets execution be split-phase
  • Event-driven operating system
  • No shell.

9
TinyOS Applications
  • A program is a set of components
  • Components can be reused
  • Components can be replaced
  • Components can be hardware or software

10
TinyOS Architecture
Main (scheduler)
Application
Sensing
Comms
Other Libraries
Hardware Abstractions (ADC, CLOCK, I2C, LEDS,
PHOTO, UART, SPI)
11
Compiling
TinyOS
nesC
GCC
12
Component-Oriented Programming
13
Component-Oriented Programming
  • Programming in nesC / TinyOS is like programming
    in a hardware description language.

14
Component-Oriented Programming
  • Object-Oriented Programming
  • Focuses on the relationships between classes that
    are combined into one large binary executable
  • Component-Oriented Programming
  • Focuses on interchangeable code modules that work
    independently and don't require you to be
    familiar with their inner workings to use them.

15
Component-Oriented Programming
  • 3 file types in TinyOS
  • Module (suffixed with P.nc)
  • Configuration (suffixed with C.nc)
  • Interface (suffixed with .nc)
  • Collectively, a Configuration and a Module are
    combined to create a Component.

16
Component-Oriented Programming
  • Modules
  • Define functionality that make your application
    run.
  • Provide interfaces to other modules.
  • Use interfaces from other modules.
  • Dont care whats behind the interface.
  • Modules are like the ICs on a circuit board that
    actually do something.

17
Component-Oriented Programming
  • Configurations
  • Wire interfaces from several modules together.
  • May forward interfaces from external modules to
    internal modules.
  • May contain sub-configurations.
  • Configurations are like a Printed Circuit Board,
    laying out wiring that connects modules together.
  • I recommend each Module be wrapped in its own
    Configuration to take care of dependencies.

18
Component-Oriented Programming
  • Interfaces
  • Define the interactions between modules
  • Commands
  • Implemented by the module providing the interface
  • Called by the module using the interface
  • Events
  • Signaled by the module providing the interface
  • Captured by the module using the interface

19
Hello World
20
Component Diagram
HelloC
CONFIGURATION
21
HelloC Configuration
  • configuration HelloC
  • implementation

22
Component Diagram
HelloP
HelloC
MODULE
23
HelloC Configuration
  • configuration HelloC
  • implementation
  • components HelloP

24
HelloP Module
  • module HelloP
  • implementation

25
Component Diagram
void myFunctions()
HelloP
HelloC
FUNCTIONALITY
26
HelloP Module
  • module HelloP
  • uses
  • interface Boot
  • interface Leds
  • implementation

27
HelloP Module
  • module HelloP
  • uses
  • interface Boot
  • interface Leds
  • implementation

28
Boot Interface
  • interface Boot
  • event void booted()

29
HelloP Module
  • module HelloP
  • uses
  • interface Boot
  • interface Leds
  • implementation
  • event void Boot.booted()

USE an interface, CAPTURE all of its events!
30
HelloP Module
  • module HelloP
  • uses
  • interface Boot
  • interface Leds
  • implementation
  • event void Boot.booted()

31
Leds Interface
  • interface Leds
  • command void led0On()
  • command void led0Off()
  • command void led0Toggle()
  • command void set(uint8_t val)

32
HelloP Module
  • module HelloP
  • uses
  • interface Boot
  • interface Leds as MyLeds
  • interface Leds as MySecondLeds
  • implementation
  • event void Boot.booted()
  • call Leds.led0On()

33
Component Diagram
Leds
void myFunctions()
HelloP
HelloC
INTERFACES
34
Component Diagram
Leds
void myFunctions()
LedsC
HelloP
MainC
HelloC
35
HelloC Configuration
  • configuration HelloC
  • implementation
  • components HelloP,
  • MainC,
  • LedsC,
  • SecondLedsC
  • // USES -gt PROVIDES
  • HelloP.Boot -gt MainC.Boot
  • HelloP.MyLeds -gt LedsC
  • HelloP.MySecondLeds -gt SecondLedsC

36
Component Diagram
PROVIDES
Leds
void myFunctions()
LedsC
HelloP
Boot
USES
MainC
HelloC
37
Hello Application
  • The Result

38
Hello Application
  • The Result

39
TinyOS Task Scheduler
40
Task Scheduler
  • Tasks are functions
  • that are queued up to run at a later time.

41
Task Scheduler
  • Task Rules
  • Tasks do not take or return arguments.
  • Tasks cannot preempt other tasks.
  • Tasks run to completion.
  • Tasks are synchronous
  • Interrupts are asynchronous
  • All tasks have the same priority.
  • Cannot post/queue the same task twice, but a task
    can post itself.

42
Task Scheduler
  • Tasks result in Split-Phase execution

ComponentA
ComponentB
call Interface.doSomething()
return SUCCESS
signal Interface.done()
43
Task Scheduler
  • command void Scheduler.taskLoop()
  • for ()
  • uint8_t nextTask
  • atomic
  • while ((nextTask popTask())
    NO_TASK)
  • call McuSleep.sleep()
  • signal TaskBasic.runTasknextTask()

44
When should you post a task?
  • When you have a lot of processing to do that will
    take a long time to execute.
  • When your code can possibly form a recursive loop
    in execution.
  • When you want to use something thats currently
    busy (i.e. the radio or flash file system).
  • When you received an interrupt and need to get
    out of async context (hardware implementation
    layers)

45
Tasks in Algorithms / Recursion
  • uint8_t myData // global memory
  • task void fft() // prototype
  • command error_t FFT.transform(uint8_t data)
  • myData data
  • post fft()
  • return SUCCESS // This split-phase command
    will finish later.
  • task void fft()
  • // do work.
  • if(notDoneYet)
  • post fft()
  • else
  • signal FFT.transformed(transformedData) //
    finished the command

46
Sub-system Polling
  • message_t myMsg // Message to send
  • task void sendResponse() // prototype
  • event message_t Receive.receive(message_t msg,
    void payload, uint8_t length)
  • post sendResponse()
  • return msg
  • task void sendResponse()
  • if(call AMSend.send(AM_BROADCAST_ADDR,
  • myMsg, sizeof(my_payload_t)) ! SUCCESS)
  • post sendMsg()

47
TinyOS Communications
48
CC1000 Radio
49
CC1000 Radio
  • Byte-based radio
  • 300-1000 MHz
  • Your matching network is around 915 MHz
  • FSK Modulation
  • 7.4 mA Rx Current
  • 10.4 mA Tx Current
  • 38.4 kbps (manchester encoding)

50
Radio Stacks
Your Application
SplitControl
Receive
AMSend
Message Queue
ActiveMessage
CSMA / Acknowledgements
Transmit / Receive / Init
Radio Hardware
51
Main Radio Interfaces
  • SplitControl
  • Provided by ActiveMessageC
  • AMSend
  • Provided by AMSenderC
  • Receive
  • Provided by AMReceiverC

52
Main Serial Interfaces
  • SplitControl
  • Provided by SerialActiveMessageC
  • AMSend
  • Provided by SerialAMSenderC
  • Receive
  • Provided by SerialAMReceiverC

53
Setting up the Radio Configuration
  • configuration MyAppC
  • implementation
  • components MyAppP,
  • MainC,
  • ActiveMessageC,
  • new AMSenderC(0), // send an AM type 0
    message
  • new AMReceiverC(0) // receive an AM type 0
    message
  • MyAppP.Boot -gt MainC
  • MyAppP.SplitControl -gt ActiveMessageC
  • MyAppP.AMSend -gt AMSenderC
  • MyAppP.Receiver -gt AMReceiverC

54
Setting up the Radio Module
  • module MyAppP
  • uses
  • interface Boot
  • interface SplitControl
  • interface AMSend
  • interface Receive
  • implementation

55
Turn on the Radio
  • event void Boot.booted()
  • call SplitControl.start()
  • event void SplitControl.startDone(error_t
    error)
  • post sendMsg()
  • event void SplitControl.stopDone(error_t error)

56
Send Messages
  • message_t myMsg
  • task void sendMsg()
  • if(call AMSend.send(AM_BROADCAST_ADDR,
  • myMsg, 0) ! SUCCESS)
  • post sendMsg()
  • event void AMSend.sendDone(message_t msg,
  • error_t error)
  • post sendMsg()

57
Receive a Message
  • event message_t Receive.receive(message_t msg,
    void
  • payload, uint8_t length)
  • call Leds.led0Toggle()
  • return msg

58
Payloads
  • A message consists of
  • Header
  • Payload
  • Optional Footer

59
message_t
  • typedef nx_struct message_t
  • nx_uint8_t headersizeof(message_header_t)
  • nx_uint8_t dataTOSH_DATA_LENGTH
  • nx_uint8_t footersizeof(message_footer_t)
  • nx_uint8_t metadatasizeof(message_metadata_t)
  • message_t

60
Payloads Use Network Types
  • (MyPayload.h)
  • ifndef MYPAYLOAD_H
  • define MYPAYLOAD_H
  • typedef nx_struct MyPayload
  • nx_uint8_t count
  • MyPayload
  • enum
  • AM_MYPAYLOAD 0x50,
  • endif

61
Example Filling out a Payload
  • void createMsg()
  • MyPayload payload (MyPayload ) call
    AMSend.getPayload(myMsg)
  • payload-gtcount (myCount)
  • post sendMsg()

62
Example Receiving a Payload
  • event void Receive.receive(message_t msg, void
    payload, uint8_t len)
  • MyPayload payload (MyPayload ) payload
  • call Leds.set(payload-gtcount)
  • signal RemoteCount.receivedCount(payload-gtcount)
  • return msg

63
Learn More
  • http//docs.tinyos.net
  • Stuff we havent covered yet
  • -gt vs.
  • Timers
  • Parameterized Interfaces
  • Generic configurations
  • Generic modules
  • unique() and uniqueCount()
  • Interfacing with a computer
  • Channels / Groups
  • Tinyos-2.x-contrib
  • Unit Testing
About PowerShow.com