ppt

therapistarmyΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 3 χρόνια και 9 μήνες)

87 εμφανίσεις

MANJUNATH D,

CS 4222 SEMESTER I I, 2011/2012

TinyOS and NesC

Hardware: Motes and Sensors

TelosB

SBT30 sensor

Smart dust

Microcontroller (TIMSP430)

10 KB RAM

16
-
bit 8 MHz processor

48 KB internal flash

Radio transceiver of 250 Kbps

Configuration of a typical mote

12
-
bit ADC

2 AA batteries

Sensors

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





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



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



L
earning 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


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/


TinyOS: Design


Process management


Application plus OS is a single program and a single process

Main() { }

func1(){ }

func2(){ }

func3(){ }

func4(){ }

funcN(){ }

Application+OS

Image of a TinyOS Program

TinyOS: Design


Process management


Multiprocessing is expensive in terms of memory

Process 1

stack

Process 2

stack

Process 3

stack

Process N

stack

Each process has to be allocated with a separate stack memory


Only interrupts are allowed to preempt the execution

Global variables (BSS)

Stack

RAM

0X00000

TinyOS’s single stack

TinyOS: Design



Memory management


Virtual memory is not supported


Memory is not protected



File systems


Proposed file systems are not popular

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

Network

Sensors

Leds

USB

Flash

Routing

MAC

Temperature

Light

Microphone

Radio

TinyOS

TinyOS: Components (Contd..)


Building an application over TinyOS

AppC

Sensors

Leds

USB

Flash

Temperature

Light

Microphone

Network

Routing

MAC

Radio

TinyOS

TinyOS: Components (Contd..)


Component interfaces


Component services are accessed via interfaces

Network

Send

Receive

TinyOS: Components (Contd..)


Interface commands


Instruct components to perform its specific tasks


Sensors

SampleSensors

getTemperature

getLight

getMagnetometer

getAccelerometer

TinyOS: Components (Contd..)


Interface events


Applications are responsible for specifying an action on an
occurrence of an event



Events are also essential as system calls in TinyOS
are non
-
blocking



Network

Receive

Application

PacketReceive

Application

Send

sendDone

TinyOS: Components (Contd..)


A few commonly used TinyOS components


LedsC


TimerC


ActiveMessageC


Some components to sample sensors


TinyOS: Components (Contd..)


LedsC


Allows to control the 3 LEDS on the motes


Provided

interfaces


Leds


Commands


led0Toggle()


led1Toggle()


led2Toggle()


ledoOn


led0Off


………


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()

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)




NesC: Design


NesC is designed to implement TinyOS components


NesC is a pre
-
processor to the C compiler

NesC preprocessor

C program

NesC program

C compiler (gcc)

Binary for the mote platform

NesC Compilation Process

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 t
oggles (blinks) the red LED on a
mote once in every 2 seconds


Configuration component

Module component

components

TimerC,

LedsC,

MainC;

uses {

interface Leds;

interface Timer;

interface Boot;

}

implementation {

event Boot.booted()

{



}

event Timer.fired()

{


}

}

components
BlinkC;

implementation {

BlinkC.Leds
-
>

LedsC;

BlinkC.Timer
-
>

TimerC;

BlinkC.Boot
-
>

MainC;

}

LedsC


interfaces: Leds


commands:


led0Toggle()


led1Toggle()…..

TimerC


interfaces: Timer


commands:


startPeriodic()


events:


fired()


call

Timer.startPeriodic(2000) ;

(BlinkC)


call

Leds.led0Toggle() ;

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





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

Configuration component

Module component

components

LedsC,

ActiveMessageC,

MainC;

uses {

interface AMSend;

interface Receive;

interface SplitControl;

}

implementation {

event Boot.booted()

{


}

interface Boot;

message_t packet;

event SplitControl.startDone()

{


}

LedsC


interfaces: Leds


commands:


led0Toggle()


led1Toggle()…..

ActiveMessageC


interface: AMSend


commands: send()


events: sendDone()



interface: Receive



events: receive ()



interface: SplitControl



commands: start()



events: startDone()

call

SplitControl.start()


call

AMSend.send(2, &packet, 10);

event AMSend.sendDone(packet, error)

{


if(error == SUCCESS) {


call

Leds.led0On();


}


else {


// Retransmit if you need


}

}

event Receive.recevie(packet, payload,
size)

{


call

Leds.led1On();

}

}

components

LedsC,

ActiveMessageC,

MainC;

LedsC


interfaces: Leds


commands:


led0Toggle()


led1Toggle()…..

ActiveMessageC


interface: AMSend


commands: send()


events: sendDone()



interface: Receive



events: receive ()



interface: SplitControl



commands: start()



events: startDone()

Configuration component

Module component

components

LedsC,

ActiveMessageC,

MainC;

components
NetC;

implementation {

NetC.AMSend
-
>

ActiveMessageC.AMSend;

NetC.SplitControl
-
>

ActiveMessageC;

}

NetC.Boot
-
>

MainC;

NetC.Receive
-
>

ActiveMessageC.Receive;

Module component

uses {

interface AMSend;

interface Receive;

interface SplitControl;

}

implementation {

event Boot.booted()

{


}

interface Boot;

message_t packet;

event SplitControl.startDone()

{


}

call

SplitControl.start()


call

AMSend.send(2, &packet, 10);

(
NetC
)

Configuration component

components

LedsC,

ActiveMessageC,

MainC;

components
NetC;

implementation {

NetC.AMSend
-
>

ActiveMessageC.AMSend;

NetC.SplitControl
-
>

ActiveMessageC;

}

NetC.Boot
-
>

MainC;

NetC.Receive
-
>

ActiveMessageC.Receive;

uses {

interface AMSend;

interface Receive;

interface SplitControl;

}

interface Boot;

Configuration component

event Receive.recevie(packet, payload,
size)

{


call

Leds.led1On();

}

Module component

(
NetC
)

uses {

interface AMSend;

interface Receive;

interface SplitControl;

}

interface Boot;

Configuration component

components

LedsC,

MainC;

components
NetC;

implementation {

NetC.AMSend
-
>

ActiveMessageC.AMSend [240];

}

NetC.Boot
-
>

MainC;

NetC.Receive
-
>

ActiveMessageC.Receive[240];

NetC.SplitControl
-
>

ActiveMessageC;

ActiveMessageC,

event Receive.recevie(packet, payload,
size)

{


call

Leds.led1On();

}

Module component

(
NetC
)

NesC Programs over TinyOS (Contd
..)


An example of
s
erial 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)

PC

mote

SF

SF
-
client

SF
-
client

SF protocol

Required set
-
up for serial communication

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 !!!!



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


event AMSend.sendDone(packet, error)

{


if(error == SUCCESS) {


call Leds.led0On();


}


else {


// Retransmit if you need


}

}

Configuration component

Module component (SerialC)

components

LedsC,

SerialActiveMessageC
,

MainC;

uses {

interface AMSend;

interface Receive;

interface SplitControl;

}

implementation {

event Boot.booted()

{


call SplitControl.start();

}

}

components
SerialC,

implementation {

SerialC.AMSend

-
>

SerailActiveMessageC
.AMSend[240];

SerialC.Receive

-
>

SerialActiveMessageC
.Receive[240];

SerialC.SplitControl

-
>

SerialActiveMessageC
;

}

interface Boot;

message_t packet;

event SplitControl.startDone()

{

}

event Receive.recevie(packet, payload, size)

{


call Leds.led1On();


call
AMSend.send
(
addr
, &packet, 10);

}

SerialC.Boot

-
>

MainC;

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



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

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%