[Tinyos-2-commits] CVS: tinyos-2.x/apps/tests/TestRadioPM/lib/radioPM/components/sleepSchedulers/sss RadioDutyCyclingC.nc, NONE, 1.1.2.1 SimpleSynchronousSchedulerC.nc, NONE, 1.1.2.1 SimpleSynchronousSchedulerP.nc, NONE, 1.1.2.1

Kevin Klues klueska at users.sourceforge.net
Mon May 15 12:36:11 PDT 2006


Update of /cvsroot/tinyos/tinyos-2.x/apps/tests/TestRadioPM/lib/radioPM/components/sleepSchedulers/sss
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv9561/apps/tests/TestRadioPM/lib/radioPM/components/sleepSchedulers/sss

Added Files:
      Tag: tos-2-resource-pm-eval-cand
	RadioDutyCyclingC.nc SimpleSynchronousSchedulerC.nc 
	SimpleSynchronousSchedulerP.nc 
Log Message:
Radio Power Management protocol architecture

--- NEW FILE: RadioDutyCyclingC.nc ---
/*
 * "Copyright (c) 2005 Washington University in St. Louis.
 * 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 WASHINGTON UNIVERSITY IN ST. LOUIS 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 WASHINGTON 
 * UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * WASHINGTON UNIVERSITY IN ST. LOUIS 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 WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO 
 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
 * MODIFICATIONS."
 */

/**
 *
 * @author Kevin Klues (klueska at cs.wustl.edu)
 * @version $Revision: 1.1.2.1 $
 * @date $Date: 2006/05/15 19:36:08 $ 
 */

generic configuration RadioDutyCyclingC() {
  provides {
    interface SplitControl;
    interface RadioDutyCycling;
  }
}
implementation {
  components SimpleSynchronousSchedulerC;
  
  SplitControl = SimpleSynchronousSchedulerC;
  RadioDutyCycling = SimpleSynchronousSchedulerC;
}


--- NEW FILE: SimpleSynchronousSchedulerC.nc ---
// $Id: SimpleSynchronousSchedulerC.nc,v 1.1.2.1 2006/05/15 19:36:08 klueska Exp $
/* Copyright (C) 2004, Washington University in Saint Louis 
 * 
 * Washington University states that this is free software; 
 * you can redistribute it and/or modify it under the terms of 
 * the current version of the GNU Lesser General Public License 
 * as published by the Free Software Foundation.
 * 
 * This software is distributed in the hope that it will be useful, but 
 * THERE ARE NO WARRANTIES, WHETHER ORAL OR WRITTEN, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.
 *
 * YOU UNDERSTAND THAT THIS SOFTWARE IS PROVIDED "AS IS" FOR WHICH NO 
 * WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. THERE ARE NO 
 * WARRANTIES AND NO REPRESENTATION THAT AGILLA IS FREE OF 
 * INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR OTHER 
 * PROPRIETARY RIGHTS.  THERE ARE NO WARRANTIES THAT SOFTWARE IS 
 * FREE FROM "BUGS", "VIRUSES", "TROJAN HORSES", "TRAP DOORS", "WORMS", 
 * OR OTHER HARMFUL CODE.  
 *
 * YOU ASSUME THE ENTIRE RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR 
 * ASSOCIATED MATERIALS, AND TO THE PERFORMANCE AND VALIDITY OF 
 * INFORMATION GENERATED USING SOFTWARE. By using this code you agree to 
 * indemnify, defend, and hold harmless WU, its employees, officers and 
 * agents from any and all claims, costs, or liabilities, including 
 * attorneys fees and court costs at both the trial and appellate levels 
 * for any loss, damage, or injury caused by your actions or actions of 
 * your officers, servants, agents or third parties acting on behalf or 
 * under authorization from you, as a result of using this code. 
 *
 * See the GNU Lesser General Public License for more details, which can 
 * be found here: http://www.gnu.org/copyleft/lesser.html
 */
/**
 * @author Kevin Klues
 */

#include "DutyCycling.h"

configuration SimpleSynchronousSchedulerC {
  provides {
    interface SplitControl;
    interface RadioDutyCycling;
  }
}
implementation 
{
  components MainC;
  components SimpleSynchronousSchedulerP as SleepScheduler;
  components TimeSyncC;
  components CsmaRadioC;
  components new TimerMilliC() as Timer;
//   components NoLedsC as Leds;
  components LedsC as Leds;

  MainC.SoftwareInit -> SleepScheduler;
  
  SplitControl = SleepScheduler;
  RadioDutyCycling = SleepScheduler;

  SleepScheduler.RadioPowerControl -> CsmaRadioC;
  SleepScheduler.Timer -> Timer;
  SleepScheduler.TimeSyncControl -> TimeSyncC;
  SleepScheduler.Leds -> Leds;
}

--- NEW FILE: SimpleSynchronousSchedulerP.nc ---
/*
 * "Copyright (c) 2005 Washington University in St. Louis.
 * 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 WASHINGTON UNIVERSITY IN ST. LOUIS 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 WASHINGTON 
 * UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * WASHINGTON UNIVERSITY IN ST. LOUIS 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 WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO 
 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
 * MODIFICATIONS."
 */

/**
 *
 * @author Kevin Klues (klueska at cs.wustl.edu)
 * @version $Revision: 1.1.2.1 $
 * @date $Date: 2006/05/15 19:36:08 $ 
 */

module SimpleSynchronousSchedulerP {
  provides {
    interface Init;
    interface SplitControl;
    interface RadioDutyCycling;
  }
  uses {
    interface SplitControl as TimeSyncControl;
    interface RadioPowerControl;
    interface Timer<TMilli> as Timer;
    interface Leds;
  }
}
implementation 
{
  uint16_t onTime = 300;
  uint16_t offTime = 0;

  struct {
    uint8_t timerForOn : 1 ;
    uint8_t isOn : 1 ;
    uint8_t radioOn : 1 ;
  } f; //for flags

  /* Time lookups */

  uint16_t setTime(DutyCycleModes mode) {
    return mode * DUTY_CYCLE_STEP;
  }

  command error_t Init.init() {
    f.radioOn = FALSE;
    f.timerForOn = TRUE;
    f.isOn = FALSE;
    return SUCCESS;
  }

  command error_t SplitControl.start() {
    return call TimeSyncControl.start();
  }

  event void TimeSyncControl.startDone(error_t error) {
    f.isOn = TRUE;
    f.timerForOn = TRUE;
    if(offTime > 0 && onTime > 0)
      call Timer.startOneShot(onTime);
    call RadioPowerControl.on();   
    signal SplitControl.startDone(error); 
  }

  command error_t SplitControl.stop() {
    f.isOn = FALSE;
    call Timer.stop();
    return call TimeSyncControl.stop();
  }

  event void TimeSyncControl.stopDone(error_t error) {
    signal SplitControl.stopDone(error);
  }  

  event void Timer.fired() {
    uint32_t timer;
    atomic {
      if(f.timerForOn == TRUE ) {
        call RadioPowerControl.off();
        timer = offTime;
      }
      else {
        call RadioPowerControl.on();
        timer = onTime;
      }
      f.timerForOn = !f.timerForOn;
    }
    call Timer.startOneShot(timer);
  }
  
  event void RadioPowerControl.offDone(error_t error) {
    if(error == SUCCESS) {
      atomic f.radioOn = FALSE;
      call Leds.led0Off();
      signal RadioDutyCycling.beginOffTime();
    }
  }

  event void RadioPowerControl.onDone(error_t error) {
    if(error == SUCCESS) {
      atomic f.radioOn = TRUE;
      call Leds.led0On();
      signal RadioDutyCycling.beginOnTime();
    }
  }

  command error_t RadioDutyCycling.setModes(DutyCycleModes onMode, DutyCycleModes offMode) {
    atomic if(f.isOn == TRUE) return FAIL;
    atomic onTime = setTime(onMode);
    atomic offTime = setTime(offMode);
    return SUCCESS;
  }

  /**
   * Set the current Dutycycling on time mode
   * @return SUCCESS if the mode was successfully changed
   */
  command error_t RadioDutyCycling.setOnTimeMode(DutyCycleModes onMode) {
    atomic if(f.isOn == TRUE) return FAIL;
    atomic onTime = setTime(onMode);
    return SUCCESS;
  }

  /**
   * Set the current Dutycycling off time mode
   * @return SUCCESS if the mode was successfully changed
   */
  command error_t RadioDutyCycling.setOffTimeMode(DutyCycleModes offMode) {
    atomic if(f.isOn == TRUE) return FAIL;
    atomic offTime = setTime(offMode);
    return SUCCESS;
  }
}



More information about the Tinyos-2-commits mailing list