[Firebug-cvs] firebug/project/src/Blinker .cvsignore,NONE,1.1 Blink.nc,NONE,1.1 BlinkHandler.nc,NONE
Brought to you by:
doolin
From: <do...@us...> - 2003-12-13 00:50:20
|
Update of /cvsroot/firebug/firebug/project/src/Blinker In directory sc8-pr-cvs1:/tmp/cvs-serv20536 Added Files: .cvsignore Blink.nc BlinkHandler.nc BlinkM.nc Blinker.nc BlinkerM.nc Makefile README interfaces.html main.css tutorial.css Log Message: Added a tutorial for handling events using interfaces. Hopefully this can be rolled into the tinyos main tree and out of here. --- NEW FILE: .cvsignore --- build *~ --- NEW FILE: Blink.nc --- /* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */ /* tab:4 * "Copyright (c) 2000-2003 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Copyright (c) 2002-2003 Intel Corporation * All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE * file. If you do not find these files, copies can be found by writing to * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, * 94704. Attention: Intel License Inquiry. */ /** * Blink is a basic application that toggles the leds on the mote * on every clock interrupt. The clock interrupt is scheduled to * occur every second. The initialization of the clock can be seen * in the Blink initialization function, StdControl.start().<p> * * Parts of this code were written or modified for FireBug project * funded by the NSF Information Technology Research * initiative. Copyright Regents of the University of * of California, 2003. * * @author tin...@mi... * @author David. M. Doolin */ // $Id: Blink.nc,v 1.1 2003/12/13 00:50:17 doolin Exp $ configuration Blink { provides { interface StdControl; interface BlinkHandler; } } implementation { components BlinkM, TimerC, LedsC; BlinkM.StdControl = StdControl; StdControl = TimerC; BlinkM.Timer -> TimerC.Timer[unique("Timer")]; BlinkM.Leds -> LedsC; BlinkM.BlinkHandler = BlinkHandler; } --- NEW FILE: BlinkHandler.nc --- /* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */ /* tab:4 * "Copyright (c) 2000-2003 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * */ /** * Parts of this code were written or modified for FireBug project * funded by the NSF Information Technology Research * initiative. Copyright Regents of the University of * of California, 2003. * * @author David. M. Doolin */ interface BlinkHandler { event result_t Blink (); } --- NEW FILE: BlinkM.nc --- /* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */ /** tab:4 * "Copyright (c) 2000-2003 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Copyright (c) 2002-2003 Intel Corporation * All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE * file. If you do not find these files, copies can be found by writing to * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, * 94704. Attention: Intel License Inquiry. */ /** * Implementation for Blink component. Signal an * event when the timer fires. * * Parts of this code were written or modified for FireBug project * funded by the NSF Information Technology Research * initiative. Copyright Regents of the University of * of California, 2003. * * @author David. M. Doolin */ module BlinkM { provides { interface StdControl; interface BlinkHandler; } uses { interface Timer; interface Leds; } } implementation { command result_t StdControl.init() { call Leds.init(); return SUCCESS; } command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 1000); } command result_t StdControl.stop() { return call Timer.stop(); } event result_t Timer.fired() { signal BlinkHandler.Blink(); call Leds.redToggle(); return SUCCESS; } default event result_t BlinkHandler.Blink() { return SUCCESS; } } --- NEW FILE: Blinker.nc --- /* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */ /** * "Copyright (c) 2000-2002 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * */ /** * Parts of this code were written or modified for FireBug project * funded by the NSF Information Technology Research * initiative. Copyright Regents of the University of * of California, 2003. * * @author David. M. Doolin */ configuration Blinker { } implementation { components Main, Blink, LedsC, BlinkerM; Main.StdControl -> BlinkerM.StdControl; Main.StdControl -> Blink.StdControl; BlinkerM.Leds -> LedsC; BlinkerM.BlinkHandler -> Blink.BlinkHandler; } --- NEW FILE: BlinkerM.nc --- /* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */ /** * "Copyright (c) 2000-2003 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * */ /** * Parts of this code were written or modified for FireBug project * funded by the NSF Information Technology Research * initiative. Copyright Regents of the University of * of California, 2003. * * @author David. M. Doolin */ module BlinkerM { provides { interface StdControl; } uses { interface BlinkHandler; interface StdControl as Blink; interface Leds; } } implementation { command result_t StdControl.init() { call Leds.init(); return SUCCESS; } command result_t StdControl.start() { call Leds.greenOn(); return SUCCESS; } command result_t StdControl.stop() { return SUCCESS; } event result_t BlinkHandler.Blink() { call Leds.greenToggle(); return SUCCESS; } } --- NEW FILE: Makefile --- COMPONENT=Blinker include $(TOSROOT)/apps/Makerules --- NEW FILE: README --- README for Blinker Author/Contact: do...@ce... Description: Blinker is an application that demonstrates the use of interfaces for handling events. In this case, the interface defines a Blink event, which is signaled from the BlinkM module, and caught by the implementation in BlinkerM. The application is built on the Blink program described in the TinyOS tutorial. Tools: None Known bugs/limitations: None See Also: --- NEW FILE: interfaces.html --- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <link type="text/css" rel="stylesheet" href="main.css" /> <link type="text/css" rel="stylesheet" href="tutorial.css" /> <script language="JavaScript1.2" src="/main.js" type="text/javascript"></script> <link rel="SHORTCUT ICON" href="./images/favicon.ico" /> <title>TinyOS Tutorial: Handling events with interfaces</title> </head> <body> <h1>nesC Interfaces: abstracting definition from implementation</h1> <p> This lesson discusses the basic concept of interfaces in the nesC programming language. It includes an easy to understand example using the Blink application introduced in the TinyOS Lesson 1 Tutorial. </p> <h1>Introduction</h1> <p>Bug-free, maintainable software is rarely written first try. As code evolves, pieces are rewritten, refactored and improved. One large component may turn into several smaller components. Given enough common functionality between components, the behavior of a set of components may be defined independently of any particular implementation. <code>nesC</code> encourages such abstraction by the use of <em>interfaces</em>. In this tutorial, we will define an interface (<code>BlinkHandler.nc</code>) for handling blinks, and wrap the Blink application with a program that implements the BlinkHandler interface. </p> <h1>Componentizing Blink</h1> <p> To provide independence between the component that wants to blink an LED and the program that provides the actual blinking behavior, the Blink configuration needs to be slightly modified to remove Main: </p> <center> <table class="code"> <tbody> <tr> <td width="100%"> <b>Blink.nc</b> <pre> configuration Blink { provides { interface StdControl; interface BlinkHandler; } } implementation { components BlinkM, TimerC, LedsC; BlinkM.StdControl = StdControl; StdControl = TimerC; BlinkM.Timer -> TimerC.Timer[unique("Timer")]; BlinkM.Leds -> LedsC; BlinkM.BlinkHandler = BlinkHandler; } </pre> </td> </tr> </tbody> </table> </center> <p> In addition to removing the Main, we also specify that the BlinkHandler interface is implemented. Since this tutorial is being written during the holiday season, the Leds interface is retained so that Blink can fire a red LED while the BlinkHandler implementation fires a green LED. </p> <p> In the Blink module file (BlinkM.nc) we need to add a few lines of code: </p> <center> <table class="code"> <tbody> <tr> <td width="100%"> <b>BlinkM.nc</b> <pre> module BlinkM { provides { interface StdControl; interface BlinkHandler; } uses { interface Timer; interface Leds; } } implementation { ... event result_t Timer.fired() { signal BlinkHandler.Blink(); call Leds.redToggle(); return SUCCESS; } ... default event result_t BlinkHandler.Blink() { return SUCCESS; } ... } </pre> </td> </tr> </tbody> </table> </center> <p> Now when the timer fires, the BlinkHandler is signaled as well as toggling the red LED. Since the BlinkHandler interface is provided, a default Blink event is implemented. </p> <h2>The BlinkHandler interface</h2> The interface is really simple. The entire BlinkHandler.nc file consists of 3 lines of code: <center> <table class="code"> <tbody> <tr> <td width="100%"> <b>BlinkHandler.nc</b> <pre> interface BlinkHandler { event result_t Blink (); } </pre> </td> </tr> </tbody> </table> </center> <h2>The Blinker program</h2> <p> Since Blink is a component, not a program, it can't run by itself: something, somewhere with a Main needs to wire to it. The Blinker program fits the bill: </p> <center> <table class="code"> <tbody> <tr> <td width="100%"> <b>Blinker.nc</b> <pre> configuration Blinker { } implementation { components Main, Blink, LedsC, BlinkerM; Main.StdControl -> BlinkerM.StdControl; Main.StdControl -> Blink.StdControl; BlinkerM.Leds -> LedsC; BlinkerM.BlinkHandler -> Blink.BlinkHandler; } </pre> </td> </tr> </tbody> </table> </center> <h2>Catching the BlinkHandler.Blink event</h2> <p> The final bit is to provide an overriding event for for catching the BlinkHandler.Blink signal. This is implemented like so: </p> <center> <table class="code"> <tbody> <tr> <td width="100%"> <b>BlinkerM.nc</b> <pre> module BlinkerM { provides { interface StdControl; } uses { interface BlinkHandler; interface StdControl as Blink; interface Leds; } } implementation { // StdControl implementation. ... event result_t BlinkHandler.Blink() { call Leds.greenToggle(); return SUCCESS; } } </pre> </td> </tr> </tbody> </table> </center> <h1>Summary</h1> <p> nesC interfaces are indispenable for rapidly and accurately implementing reusable components. This tutorial and accompanying code is intended to help clarify some of the implementation details for creating and implementing interfaces. </p> <p> Comments and corrections to: doolin at ce dot berkeley dot edu. </p> <hr /> </body> </html> --- NEW FILE: main.css --- BODY, TD, P { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #000000;} .black { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #000000;} .grey { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #676767;} .white { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: #FFFFFF;} a.white { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight:bold; color: #FFFFFF;} .orange {color: #FF6600;} .titlered {color: #960707; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 18px; font-weight:bold;} .titleorange {color: #CC6633; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 18px; font-weight:bold;} .red { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #990000;} .small {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; font-weight:normal;} a.nav-main { font-size: 10px; color: #FFFFFF; font-weight:bold; text-decoration:none; } a.nav-main:hover { font-size: 10px; color: #FFF; font-weight:bold; text-decoration:none; } a.nav-sub { font-size: 10px; color: #FFFFFF; text-decoration:none; } a.nav-sub:hover { font-size: 10px; color: #CCCCCC; text-decoration:none; } A { font-family: Verdana, Arial, Helvetica, sans-serif; color: #0066CC;} A:HOVER { color: #FF9900; text-decoration: underline;} A:HOVER.white { color: #FFFFDD; text-decoration: underline;} A:HOVER.black { color: #FF9900; text-decoration: underline;} A:HOVER.orange { color: #993300; text-decoration: underline;} A.small { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #0066CC;} .topnav { font-size: 10px;} .topnav_active {background-color:#FDCD85; color:#394D73; font-weight: bold; font-size: 10px;} a.topnav{font-weight: bold; text-decoration:none; color:#394D73;} a.topnav:hover{background-color:#FDCD85; color:#394D73; text-decoration:none;} .header { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; color: #000000; font-weight: bold;} .headerwhite { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; color: #FFFFFF; font-weight: bold;} .wl {font-family:verdana, Helvetica, Sans-Serif; font-size: 12px; font-weight:bold; color:#666633;} .wlt {font-family:verdana, Helvetica, Sans-Serif; font-size: 11px; color:#666633;} .blueh {font-family:verdana, Helvetica, Sans-Serif; font-size: 13px;font-weight:bold;color:#336699;} .bluet {font-family:verdana, Helvetica, Sans-Serif; font-size: 12px;color:#336699;} .bluetsml {font-family:verdana, Helvetica, Sans-Serif; font-size: 10px; color:#336699;} .bluetout {font-family:verdana, Helvetica, Sans-Serif; font-size: 10px;color:#336699;} .boldsmall {font-family:verdana, Helvetica, Sans-Serif; font-size: 10px;color:#000000; font-weight:bold} .spacer1p {margin-top:1px;} .spacer2p {margin-top:2px;} .spacer4p {margin-top:4px;} .spacer5p {margin-top:5px;} .spacer7p {margin-top:7px;} .spacer10p {margin-top:10px;} .spacer12p {margin-top:12px;} .spacer15p {margin-top:15px;} .spacer20p {margin-top:20px;} .spacer25p {margin-top:25px;} .navbox {margin-top:2px;} TR.NavRow TD { vertical-align: middle; border: 1px solid; border-color: #369 #003 #003; border-left: none; cursor: pointer; } .Nav { background-color: #384ccc; color: #fff; cursor: pointer; } .NavText, .NavHighlightText, .NavGroupText { font-family: verdana, arial, sans-serif; font-size: 10px; font-weight: bold; line-height: 14px; padding-left: 6px; text-decoration: none; } .Nav A:link, .Nav A:visited { color: #fff; Text-decoration: none;} .NavHilite { background-color: #5A6B94; color: #fff; } .NavHilite A:link, .NavHilite A:visited { color: #fff; } TR TD.NavHilite A:link, TR TD.NavHilite A:visited { text-decoration: none; } TR.NavHiliteRow TD { vertical-align: middle; border: 1px solid; border-color: #000 #5A6B94 #000; border-left: none; } --- NEW FILE: tutorial.css --- table.header { background-color:#e0e0ff; width:100%; font-family:tahoma,arial,helvetica; font-weight:bold; font-size:150%; } table.code { background-color:#e0e0e0; border:none; width:80%; } table.db_schema { background-color:#ffff66; border:solid; width:80%; font-size:75%; } table.new { width:50%; } tr.code { /*background-color:#ffff66; */ } tr.msg_header { background-color:#ffcc00; text-align:center; } td.code { padding:5px; width:100%; } h1 { background-color:#e0e0ff; /* color:#ffffff;*/ font-family:tahoma,helvetica,arial; font-size:150%; } h2 { background-color:#e0e0ff; //color:#ff3300; font-family:tahoma,helvetica,arial; font-size:100%; } code.progname { font-weight:bold; } BODY { color:black; background-color:#FFFFF5; } SPAN.title {color:green} SPAN.author {color:purple;} SPAN.publication {color:green} SPAN.fortran { font-variant: small-caps; } span.invisible { color:#FFFFF5; } P.abstract {color:blue; margin-left: 10%; /* width: 80%; */ margin-right: auto; /* background-color: gray; */ } /* a:active { color:red; } a:visited { color:yellow; background-color:blue; } a:link { color:green; } a:hover { color:green; font:bold; } */ /* IMG.inlinemath { text-align: bottom } */ /************************************************/ body { margin:9px 9px 0 9px; padding:0; background-color:#ffffff; } #level0{ background-color:#ffcc00; } #level1 { margin-left:143px; padding-left:9px; background-color:#FFFFFF; } #level2 { background:#FFF3AC; position:relative; } #level3 { margin-right:143px; padding-right:9px; background:#FFFFFF; } #main { background:#fff3ac; } #topBar { background:#ffffff; } #advBar { background:#fff3ac; } #tipDay { float:right; width:175px; background:#FFF3AC; } #lftBar { position:absolute; width:143px; top:9px; left:9px; } #rgtBar { position:absolute; width:143px; top:0; right:0; } |