how to code on tinyos

32
How to Code on TinyOS Xufei Mao Xufei Mao Advisor: Dr. Xiang-yang L Advisor: Dr. Xiang-yang L i i CS Dept. IIT CS Dept. IIT

Upload: novia

Post on 18-Feb-2016

38 views

Category:

Documents


2 download

DESCRIPTION

How to Code on TinyOS. Xufei Mao Advisor: Dr. Xiang-yang Li CS Dept. IIT. Outlines. What is TinyOS? Hardware & Software NesC A simple example Conclusion. So why do we need a new OS?. Traditional OS. Huge ! Multi-threaded architecture =>large memory I/O model - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: How to Code on TinyOS

How to Code on TinyOS

Xufei Mao Xufei Mao Advisor: Dr. Xiang-yang LiAdvisor: Dr. Xiang-yang Li

CS Dept. IITCS Dept. IIT

Page 2: How to Code on TinyOS

Outlines

What is TinyOS?What is TinyOS? Hardware & SoftwareHardware & Software NesCNesC A simple exampleA simple example ConclusionConclusion

Page 3: How to Code on TinyOS

So why do we need a new OS?

Page 4: How to Code on TinyOS

Traditional OS

Huge !Multi-threaded architecture =>large memoryI/O modelKernel and user space separationTypically no energy constraintsAmple available resources

Page 5: How to Code on TinyOS

Sensor Hardware Constraints Lower Power Limited memory Slow CPU Size (Small) Limited hardware parallelisms Communication using radio

Low-bandwidth Short range

Page 6: How to Code on TinyOS

Desired OS Properties Small memory footprint Efficient in power and computation Communication is fundamental Real-time Support diverse application design

Page 7: How to Code on TinyOS

TinyOS Solution Concurrency: uses event-driven architecture Modularity

Application composed of components OS + Application compiles into single

executable Communication

Uses event/command model FIFO and non pre-emptive scheduling

No kernel/application boundary

Page 8: How to Code on TinyOS

The Hardware

Page 9: How to Code on TinyOS

Software

TinyOS (Platform) TinyOS (Platform) Coding languageCoding language

NesC (Network Embedded System C)NesC (Network Embedded System C)

Page 10: How to Code on TinyOS

TinyOS Memory Model STATIC memory allocation!

No heap (malloc) No function pointers No dynamic, run-time allocation

Global variables Available on a per-frame basis Conserve memory Use pointers

Local variables Saved on the stack Declared within a method

Page 11: How to Code on TinyOS

TinyOS & nesC Concepts New Language: nesC. Basic unit of code = Component Component

Process Commands Throws Events Has a Frame for storing local state Uses Tasks for concurrency

Components provide interfaces Used by other components to communicate with this component

Page 12: How to Code on TinyOS

Components

Two type of componentsTwo type of components ModuleModule

component written with codecomponent written with code ConfigurationConfiguration

components wired togethercomponents wired together

Page 13: How to Code on TinyOS

Components

Page 14: How to Code on TinyOS

TinyOS Application (Sample)

Page 15: How to Code on TinyOS

Commands/Events/Tasks Commands

Should be non-blocking i.e. take parameters start the processing and return to app; postpone time-consuming work by posting a task Can call commands on other components

Events Can call commands, signal other events, post tasks but cannot be signal-ed by commands Pre-empt tasks, not vice-versa

Tasks FIFO scheduling Non pre-emptable by other task, pre-emtable by events Used to perform computationally intensive work Can be posted by commands and/or events

Page 16: How to Code on TinyOS

nesC Naming conventions

nesC files extension: .nc Clock.nc : either an interface (or a configuration) ClockC.nc : a configuration ClockM.nc : a module

Page 17: How to Code on TinyOS

nesC Keywords

Page 18: How to Code on TinyOS

nesC Keywords -implementation

Page 19: How to Code on TinyOS

Interfaces

Page 20: How to Code on TinyOS

Modules Implement one or more interfaces Can use one or more other interfaces

Page 21: How to Code on TinyOS

Modules (Sample)

Page 22: How to Code on TinyOS

Configurations Two components are linked together in nesC by wiring them Interfaces on user component are wired to the same interface on the provider component 3 wiring statements in nesC:

endpoint1 = endpoint2 endpoint1 -> endpoint2 endpoint1 <- endpoint2 (equivalent: endpoint2 -> endpoint1)

Page 23: How to Code on TinyOS

Configurations (Sample)

Page 24: How to Code on TinyOS

nesC Wiring Syntax

Page 25: How to Code on TinyOS

Compile & Run Compiler processes nesC files converting them into a gigantic C file

Has both your application & the relevant OS components you are using Then platform specific compiler compiles this C file

Becomes a single executable Loader installs the code onto the Mote (Mica2, Telos, etc.)

Page 26: How to Code on TinyOS

Simple Example 1

Blink ApplicationBlink Application Blink.nc configuration Blink.nc configuration

Page 27: How to Code on TinyOS

Simple Example 1

Blink ApplicationBlink Application BlinkM.nc moduleBlinkM.nc module

Page 28: How to Code on TinyOS

Simple Example 2

Communication between two sensorsCommunication between two sensors Environment : Xubuntu + TinyOS 2.0Environment : Xubuntu + TinyOS 2.0 Hardware: TelosB sensorsHardware: TelosB sensors

Page 29: How to Code on TinyOS

Resources Gaurav’s TinyOS-1.x installation howto:

http://www.cs.umass.edu/~gmathur/misc/tinyos_setup.htm Tinyos-2.x installation howto (straightforward):

http://www.tinyos.net/tinyos-2.x/doc/html/install-tinyos.html The official TinyOS tutorial (pretty good):

http://www.tinyos.net/tinyos-1.x/doc/tutorial/ The offical TinyOS-2.x tutorial (very good):

http://www.tinyos.net/tinyos-2.x/doc/html/tutorial/index.html nesC: http://nescc.sourceforge.net/

Page 30: How to Code on TinyOS

Resources Other Docs:

nesC paper: http://none.cs.umass.edu/~gmathur/tinyos/nesc-pldi-2003.pdf nesC manual: http://none.cs.umass.edu/~gmathur/tinyos/nesc-ref.pdf TinyOS abstractions: http://none.cs.umass.edu/~gmathur/tinyos/tinyosnsdi04.pdf

Page 31: How to Code on TinyOS

Reference TinyOS TutorialTinyOS Tutorial by by Jeremy Gummeson, Sensors Lab,

UMass-Amherst TinyOS Programming by Philip Levis nesC paper: http://none.cs.umass.edu/~gmat

hur/tinyos/nesc-pldi-2003.pdf

Page 32: How to Code on TinyOS

Conclusion