how to code on tinyos
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 PresentationTRANSCRIPT
How to Code on TinyOS
Xufei Mao Xufei Mao Advisor: Dr. Xiang-yang LiAdvisor: Dr. Xiang-yang Li
CS Dept. IITCS Dept. IIT
Outlines
What is TinyOS?What is TinyOS? Hardware & SoftwareHardware & Software NesCNesC A simple exampleA simple example ConclusionConclusion
So why do we need a new OS?
Traditional OS
Huge !Multi-threaded architecture =>large memoryI/O modelKernel and user space separationTypically no energy constraintsAmple available resources
Sensor Hardware Constraints Lower Power Limited memory Slow CPU Size (Small) Limited hardware parallelisms Communication using radio
Low-bandwidth Short range
Desired OS Properties Small memory footprint Efficient in power and computation Communication is fundamental Real-time Support diverse application design
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
The Hardware
Software
TinyOS (Platform) TinyOS (Platform) Coding languageCoding language
NesC (Network Embedded System C)NesC (Network Embedded System C)
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
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
Components
Two type of componentsTwo type of components ModuleModule
component written with codecomponent written with code ConfigurationConfiguration
components wired togethercomponents wired together
Components
TinyOS Application (Sample)
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
nesC Naming conventions
nesC files extension: .nc Clock.nc : either an interface (or a configuration) ClockC.nc : a configuration ClockM.nc : a module
nesC Keywords
nesC Keywords -implementation
Interfaces
Modules Implement one or more interfaces Can use one or more other interfaces
Modules (Sample)
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)
Configurations (Sample)
nesC Wiring Syntax
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.)
Simple Example 1
Blink ApplicationBlink Application Blink.nc configuration Blink.nc configuration
Simple Example 1
Blink ApplicationBlink Application BlinkM.nc moduleBlinkM.nc module
Simple Example 2
Communication between two sensorsCommunication between two sensors Environment : Xubuntu + TinyOS 2.0Environment : Xubuntu + TinyOS 2.0 Hardware: TelosB sensorsHardware: TelosB sensors
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/
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
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
Conclusion