TinyOS - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

TinyOS

Description:

Similar to a thread that wakes up every so often in relation to how you are used ... of the basic concepts on how to structure the code, setup parts of the code, etc ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 18
Provided by: grandmas
Category:
Tags: tinyos | how | set | to | up | wifi

less

Transcript and Presenter's Notes

Title: TinyOS


1
TinyOS
  • Session 2, September 16th
  • Events, Tasks, and Basic Programming

2
Components
  • There are two types of components in nesC
    modules and configurations.
  • Modules provide application code, implementing
    one or more interfaces.
  • Configurations are used to wire other components
    together, connecting interfaces used by
    components to interfaces provided by others.
  • Every nesC application is described by a
    top-level configuration that wires together the
    components used

3
Interfaces
  • An Interface is like a function definition,
    similar to an abstract class in C
  • Modules can use interfaces to make calls to
    implementations
  • Example random number generator component
  • (in the module definition note, it still has to
    be wired to implementation)
  • uses
  • interface Random
  • Later on we can call
  • call Random.rand()

4
Wiring
  • Wiring is the method we use to connect an
    interface we use to an implementation of that
    functionality Example
  • Here, our module ExampleMessageM uses the Time
    interface
  • It is wired to the implementation of the Time
    interface on the LogicalTime Componen
  • ExampleMessageM.Time -gt LogicalTime.Time

5
Modules
  • Wiring file is MyCode.nc (sorta like a header
    file in c, but not exactly)
  • Module file is MyCodeM.nc (sorta like the .c file
    in c)
  • Contains the implementation code for your program

6
Our Module
  • module ExampleMessageM
  • provides
  • interface StdControl
  • interface BluSH_AppI as HelloWorld
  • interface BluSH_AppI as SendMessage
  • uses
  • // allows us access to the random number
    generator component in tinyOS
  • interface Random
  • interface StdControl as TimerControl
  • interface Timer
  • interface Time // allows us to see elapsed
    time
  • interface TimeUtil

7
Tasks
  • A task is similar to a function in c programming
  • It takes no parameters
  • Continues execution until completion, other tasks
    do not execute until it is complete
  • Can only be pre-empted by an event

8
Task Example
  • task void ExampleTask()
  • trace(DBG_USR1," --- ExampleTask Start ---
    \r\n", TOS_LOCAL_ADDRESS)
  • .. And then
  • post ExampleTask()

9
Events
  • Events are method calls made to a component
  • Similar to a callback in c programming
  • Common event in code is the Timer fired() event
  • event result_t Timer.fired()

10
Timers
  • In our example code, a basic Timer is wired up
  • Allows us to periodically do a function, or post
    a task
  • Similar to a thread that wakes up every so often
    in relation to how you are used to thinking about
    programming.

11
Timer Example
  • event result_t Timer.fired()
  • trace(DBG_USR1, "Timergt Fired!\r\n")
  • return SUCCESS

12
The Radio
  • The Imote2 employs the CC2420 chipset which is
    fairly standard, similar to your laptop wifi
  • Integrated 802.15.4 Radio
  • Integrated 2.4GHz Antenna

13
Issues with Physical Mediums
  • The wireless physical medium is crazy. Just know
    this.
  • Everything in the immediate area can and mostly
    will interfere with your data, and it will drive
    you crazy.
  • Radio waves bounce around off everything,
    sometimes distance isnt your only obstacle.
  • For a technical reference on how power and
    interference effects this, take a look at
    http//en.wikipedia.org/wiki/Friis_transmission_eq
    uation

14
So How Do We Send a Message?
  • Basically, we have a data structure which has a
    data field which is an array of bytes
  • We have a packet format, and we write our values
    into the slots designated by the format
  • We then pass this data structure on to the
    underlying messaging communication subsystem via
    the Send interface
  • call RadioSend.send( radio_msg )

15
Packets at the Bit Level
  • // read a field from the packet
  • uint16_t Read_ArbitraryField_FromPacket(
    TOS_MsgPtr pMsg )
  • uint8_t d0, d1
  • d0 (uint8_t) pMsg-gtdata PKT_ARBITRARY_16_FIELD
    _0
  • d1 (uint8_t) pMsg-gtdata PKT_ARBITRARY_16_FIELD
    _1
  • return d0 d1 ltlt 8
  • // write a field to the packet
  • void Write_ArbitraryField_ToPacket( TOS_MsgPtr
    pMsg, uint16_t iArbitrary_16bit_Value )
  • pMsg-gtdata PKT_ARBITRARY_16_FIELD_0
    iArbitrary_16bit_Value 0xff
  • pMsg-gtdata PKT_ARBITRARY_16_FIELD_1
    (iArbitrary_16bit_Value gtgt 8) 0xff

16
The BLuSH Shell
  • Basically an easy way to talk to the mote from
    the pc while the mote is running
  • You write shell commands that execute on the mote
  • Anything that the mote writes to trace will show
    up in your console window
  • Imoteconsole.exe brings up the BLuSH shell

17
Our Messaging Codebase
  • So now weve taken a look at most of the basic
    concepts on how to structure the code, setup
    parts of the code, etc
  • We now want to get our hands dirty and try out a
    few of these new concepts
  • Download the ExampleMessage codebase at
    http//jpatterson.floe.tv/tinyOS/ExampleMessage.zi
    p
  • Compile the code, flash the mote, and run
    imoteconsole.exe
Write a Comment
User Comments (0)
About PowerShow.com