Programming MotesThe monsters:TinyOS OverviewTinyOS featuresWhat TinyOS does not provide…TinyOS program architectureTinyOS Components can provide...Tasks in TinyOS and SchedulingTinyOS developmentTinyOS installation notesComponent DevelopmentBlink: A component exampleCode walkthroughCode walkthrough continued…StdControl InterfaceCode walkthrough continued pt2…BlinkM.nc – module implementationBlinkM.nc continued…BlinkM.nc continued pt2…Running TinyOS code - TOSSIMDebuggingTinyViz – A visualization programTinyVizMica2 module uploading…And they all lived happily ever afterProgramming MotesA TinyOS and TOSSIM TutorialBy: Brent RoodThe monsters:Programming BoardMICA2 MOTETinyOS OverviewOperating system developed at UC Berkeley for use with sensor motesSupport sensor motes and ease development of sensor applicationsEvent-driven architectureUtilizes new programming language called nesCCurrently the standard in sensor OSTinyOS featuresExtensibility–Allows components to be “wired” together thereby allowing for flexibility and ease of development through use of a wide array of components able to be wired in many configurationsSpecifically designed for use in sensors–Low power overhead–Requires little processing power–Small memory footprintWhat TinyOS does not provide…In order to accommodate the unique resource requirements of sensors, TinyOS has sacrificed:–Kernel – programmer deals with hardware directly–Process Management – only one process–Multiple stacks – only a single shared stack–Virtual Memory – physical memory used–Dynamic Memory Allocation – assigned at compile timeTinyOS program architectureA program consists of a set of components “wired” together–Each component can provide “interfaces” which can be wired to and allow use of that component’s functions (it exports these functions)–The component can also export events to which a component wired to it can respond toNote: These components are statically wired together at compile timeTinyOS Components can provide...Events–An event is a “happening” that is produced by a component and that can be responded to by any components wired to this component–Events are generated in response to a given happening and can call other commands, generate other events or post a taskCommands–Provided by a component, these provide functionality into that component–A command of a component may be invoked by a component wired to it and is akin to a member function of a class–Can also call other commands, trigger events or post tasksTasks in TinyOS and SchedulingTasks–A function that once called is put in a FIFO queue awaiting execution–Usually used for longer processing errands because these can be preempted (by an incoming event for example)Scheduling–Commands and Tasks (FIFO queued) are non-blocking and non-preemptive (tasks cannot preempt each other)–Events are preemptive and blocking–Hence, responses to events must be kept as short as possible (e.g. post a task and return)TinyOS developmentDownload and Install TinyOS http://www.tinyos.net/tinyos-1.x/doc/install.html–Windows:Uses Cygwin environment to simulate Linux environmentMore complex than Linux installation (this took some time)WARNING: TinyOS has problems with newer versions of Cygwin and prefers older versions for proper functioning–Linux:Preferred as it’s native and faster; Easier setupSimply involves installing several RPMs (for Red Hat)Note that nesc-1.1-1.i386.rpm should be used (the recommended nesc-1.1.2b-1.i386.rpm gives many compiler errors)TinyOS installation notesInstalls –nesC compiler and AVR package (processor dependant)–Java JDK and Communications package–TinyOS software/modulesTinyOS installation (Red Hat) can be found in /opt/tinyos-1.x/–/opt/tinyos-1.x/apps contains example components (such as Blink)–/opt/tinyos-1.x/tools/java contains many java applications that will be useful later–/opt/tinyos-1.x/tools/scripts contains toscheck which can be used to check installation for correctnessAlso ensure that you change your PATH variable to includeComponent DevelopmentComponents consist of two files–Configuration file (e.g. mycomponent.nc)Specifies how and to which other components this particular component is wired toAlso allows the component to “provide” various interfaces to other components (that can wire to it)–Module file (e.g. mycomponentM.nc)This is the actual implementation of the component itselfDeals with event handling, command implementation, task posting, etc.Blink: A component exampleBlink.nc consists of:configuration Blink {}implementation { components Main, BlinkM, SingleTimer, LedsC; Main.StdControl -> BlinkM.StdControl; Main.StdControl -> SingleTimer.StdControl; BlinkM.Timer -> SingleTimer.Timer; BlinkM.Leds -> LedsC;}Code walkthrough configuration Blink { }–Specifies this is a configuration file whose name is Blinkimplementation { –Indicates that this is where we specify the actual configuration of the componentcomponents Main, BlinkM, SingleTimer, LedsC; – A listing of the set of components that this configuration file references (makes use of)Code walkthrough continued… Main.StdControl -> SingleTimer.StdControl; Main.StdControl -> BlinkM.StdControl; –Main is a component and StdControl is an interface it uses–-> symbol indicates that the component on the left “is wired to” (OR the component on the left “uses”) the component on the right and carries with it two conditions:The component on the right must implement all the functions provided by the component’s interface on the leftThe component on the left must implement event handlers for all the events that the component on the right exportsHence, Main’s StdControl interface uses (is wired to) the StdControl interfaces provided by (implemented by) both BlinkM and SingleTimerStdControl InterfaceAnyone who provides the StdControl Interface must implement the following 3 functions:–StdControl.init(), StdControl.start() and StdControl.stop()When a mote is started, the first two functions called are Main.StdControl.init() and Main.StdControl.start()–Any modules who implement this interface and are wired to Main in such a way also have their init and start functions called–The last function called is Main.StdControl.stop() and it will call all the stop
View Full Document