320 likes | 445 Vues
Dive into the world of TinyOS, an operating system designed for sensor networks and embedded systems. This guide covers its unique features, including low power consumption, limited memory usage, and real-time capabilities. Learn about the NesC programming language, which simplifies component-based application development. The text outlines TinyOS's architecture, the advantages it offers over traditional OS, and practical examples for implementation. Ideal for developers looking to create efficient and responsive applications in resource-constrained environments.
E N D
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
Traditional OS Huge ! Multi-threaded architecture =>large memory I/O model Kernel and user space separation Typically no energy constraints Ample 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
Software • TinyOS (Platform) • Coding language • 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 components • Module • component written with code • Configuration • components wired together
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
Modules • Implement one or more interfaces • Can use one or more other interfaces
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)
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 Application • Blink.nc configuration
Simple Example 1 • Blink Application • BlinkM.nc module
Simple Example 2 • Communication between two sensors • Environment : Xubuntu + TinyOS 2.0 • Hardware: 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 Tutorial by Jeremy Gummeson, Sensors Lab, UMass-Amherst • TinyOS Programming by Philip Levis • nesC paper: http://none.cs.umass.edu/~gmathur/tinyos/nesc-pldi-2003.pdf