ece693_mobile_programming_ece_lecture13.pdf

30
TinyOS Overview Lecture 13 EE 693 Programming for Mobile Devices

Upload: domnulmike

Post on 25-Oct-2015

13 views

Category:

Documents


0 download

DESCRIPTION

tinyos

TRANSCRIPT

Page 1: ECE693_Mobile_Programming_ECE_Lecture13.pdf

TinyOS Overview

Lecture 13

EE 693

Programming for Mobile Devices

Page 2: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Outline

TinyOS Overview

Why TinyOS 2.x

Difference between TinyOS 1.x and 2.x

Installing TinyOS 2.x

Page 3: ECE693_Mobile_Programming_ECE_Lecture13.pdf

IRIS-XM2110

Atmel Atmega1281

2.4GHz

8KB RAM

128KB Program

Flash

51 pin I/O Connector

ADC 0-7 UART 1 I2C Bus

2 AA

Page 4: ECE693_Mobile_Programming_ECE_Lecture13.pdf

MIB520CB Mote Interface Board

Mib520

IRIS interface

Page 5: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Sensor Board

Our testing sensor board with IRIS

Page 6: ECE693_Mobile_Programming_ECE_Lecture13.pdf

TinyOS Overview

TinyOS Architecture

Component-oriented Programming

Concurrency Model

Page 7: ECE693_Mobile_Programming_ECE_Lecture13.pdf

TinyOS Architecture

Sensing Comms Other Libraries

Application

Main (scheduler)

Hardware Abstractions (ADC, CLOCK, I2C, LEDS, PHOTO, UART, SPI)

Page 8: ECE693_Mobile_Programming_ECE_Lecture13.pdf

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.

Page 9: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Three File Types

Module (suffixed with C.nc, P.nc)

Configuration (suffixed with C.nc, P.nc)

Interface (suffixed with .nc)

Public Module (suffixed with C.nc)

Private Module (suffixed with P.nc)

Component-oriented Programming

Page 10: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Configuration

Assemble other used components together

Wire interfaces used by components to interfaces provided by others

Can provide and use interfaces

Top-configuration and sub-configuration

Component-oriented Programming

Page 11: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Configuration

Assemble other used components together

Wire interfaces used by components to interfaces provided by others

Can provide and use interfaces

Top-configuration and sub-configuration

Top-configuration does not provide or use interface

Component-oriented Programming

Page 12: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Component-oriented Programming

Module

Declare provided and used interfaces

Implement the functions to make your application run

Does not care what is behind the interfaces and components

A configuration and a module combined to form a component

Page 13: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Component-oriented Programming

Interface

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

Page 14: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Command, Event, Task are all functions

Command is used for requesting actions

Event is used for notifying occurrence

Task is used for long time operations

Component-oriented Programming

Page 15: ECE693_Mobile_Programming_ECE_Lecture13.pdf

15

Component Example BlinkAppC wires BlinkC.Timer to TimerC.Timer

module BlinkC {

uses interface Timer<TMilli>

as Timer0

provide interface xxxx}

implementation {

int c;

void increment() {c++;}

event void Timer0.fired()

{

call Leds.led0Toggle();

}

}

configuration BlinkAppC

{

}

implementation

{

components MainC, BlinkC, LedsC;

components new TimerMilliC()

as Timer0;

BlinkC.Timer0 -> Timer0;

BlinkC -> MainC.Boot;

BlinkC.Leds -> LedsC;

}

TimerC BlinkC Timer

Page 16: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Singletons and Generics

Singleton components are unique: they exist in a global namespace

Generics are instantiated: each instantiation is a new, independent copy

configuration BlinkC { … }

implementation {

components new TimerC();

components BlinkC;

BlinkC.Timer -> TimerC;

}

Page 17: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Interfaces

Collections of related functions

Define how components connect

Interfaces are bi-directional: for A->B

Commands are from A to B

Events are from B to A

Can have parameters (types)

interface Timer<tag> { command void startOneShot(uint32_t period); command void startPeriodic(uint32_t period); event void fired(); }

Page 18: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Interface (provide and use)

User

Provider

Interface

Commands

Events

Module BlinkC { use interface xxxx; provide interface xxxxxxx; ......... }

Page 19: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Concurrency Model

Task “background” processing, run later, rather than now.

Hardware Event Handler handle hardware interrupt

Split-phase Operation split invocation and completion into two separate

phases

Page 20: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Blocking operation

if (send() == SUCCESS) {

sendCount++;

}

Concurrency Model

Split-phase operation

// start phase

send();

// completion phase

void sendDone (error_t error) {

if (error == SUCCESS) {

sendCount++;

}

}

Page 21: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Tasks

TinyOS has a single stack: long-running computation can reduce responsiveness

Tasks: mechanism to defer computation

Tells TinyOS “do this later”

Tasks run to completion

TinyOS scheduler runs them one by one in the order they post

Keep them short!

Interrupts run on stack, can post tasks

Page 22: ECE693_Mobile_Programming_ECE_Lecture13.pdf

TinyOS Execution Model

Xxxxxx;

event void Timer0.fired()

{

xxxxxx;

xxxxxx;

xxxxxx;

xxxxxx;

call Leds.led0Toggle();

xxxxxx;

xxxxxx;

post remainingwork();

}

xxxxx;

remainingwork(){xxxx;};

xxxxx;

......

Stack Task Queue

Timer0.fired

......

Timer0.fired

Led0Toggle

......

remainingwork

main

main

remainingwork

main

......

Page 23: ECE693_Mobile_Programming_ECE_Lecture13.pdf

TinyOS/nesC Summary

Components and Interfaces Programs built by writing and wiring components

modules are components implemented in C

configurations are components written by assembling other components

Execution model Execution happens in a series of tasks (atomic with respect to

each other) and interrupt handlers

No threads

System services: startup, timing, sensing (so far) (Mostly) represented by instantiatable generic components

This instantiation happens at compile-time! (think C++ templates)

All slow system requests are split-phase

Page 24: ECE693_Mobile_Programming_ECE_Lecture13.pdf

24

“Make”: The Tool Chain

ncc

gcc

int main() { scheduler_init(); ... }

Native binary:

03 2F 77 9A F2 FF ...

Page 25: ECE693_Mobile_Programming_ECE_Lecture13.pdf

The “Make” System

Native binary:

03 2F 77 9A F2 FF ...

make micaz install mib520, /dev/ttyS0

automates nesC, C compilation, mote installation

TinyOS

App

PC Applications

Page 26: ECE693_Mobile_Programming_ECE_Lecture13.pdf

Build PC Applications

Native binary:

03 2F 77 9A F2 FF ...

TinyOS Java, C, Python apps

Talk with motes

java classname -comm serial@/dev/ttyS0:micaz

Page 27: ECE693_Mobile_Programming_ECE_Lecture13.pdf

PC Applications: Extracting Information from TinyOS

mig

ncg

Java, C or Python app

packet formats

constants

TinyOS

Page 28: ECE693_Mobile_Programming_ECE_Lecture13.pdf

“Make”: Install Applications

Native binary:

03 2F 77 9A F2 FF ...

pybsl, uisp, etc

deluge

Page 29: ECE693_Mobile_Programming_ECE_Lecture13.pdf

PC Applications: Talking to Motes

Java, C or Python app

sf

packet libs

packet libs

Page 30: ECE693_Mobile_Programming_ECE_Lecture13.pdf

TinyOS Installation

VMware Player

Ubuntu & Dropbox

TinyOS

g++/python