]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
low power listening
authormmaroti <mmaroti>
Mon, 21 Apr 2008 20:58:08 +0000 (20:58 +0000)
committermmaroti <mmaroti>
Mon, 21 Apr 2008 20:58:08 +0000 (20:58 +0000)
tos/chips/rf230/DefaultMacC.nc
tos/chips/rf230/DefaultPacketC.nc
tos/chips/rf230/DefaultPacketP.nc
tos/chips/rf230/DummyLPLMacC.nc [deleted file]
tos/chips/rf230/DummyLPLP.nc [deleted file]
tos/chips/rf230/LowPowerListeningLayerC.nc [new file with mode: 0644]
tos/chips/rf230/LowPowerListeningLayerP.nc [new file with mode: 0644]
tos/chips/rf230/MessageBufferLayerP.nc
tos/chips/rf230/Neighborhood.nc
tos/chips/rf230/RF230LayerC.nc

index 9db81a0d8d8bb60793c206b9a1ed87a54de46cc4..382b8b89069b636f1cb9c521251f7a30d7fa443e 100644 (file)
@@ -36,6 +36,7 @@ configuration DefaultMacC
                interface Packet;
                interface AMPacket;
                interface PacketAcknowledgements;
+               interface LowPowerListening;
 
                interface PacketField<uint8_t> as PacketLinkQuality;
                interface PacketTimeStamp<TRF230, uint16_t>;
@@ -61,11 +62,13 @@ implementation
        PacketAcknowledgements = DefaultPacketC;
        PacketLinkQuality = DefaultPacketC.PacketLinkQuality;
        PacketTimeStamp = DefaultPacketC.PacketTimeStamp;
+       LowPowerListening = LowPowerListeningLayerC;
 
        PacketLastTouch = DefaultPacketC;
        RF230LayerC.lastTouch -> DefaultPacketC.lastTouch;
 
        components ActiveMessageLayerC;
+       components LowPowerListeningLayerC;
        components MessageBufferLayerC;
        components UniqueLayerC;
        components TrafficMonitorLayerC;
@@ -75,7 +78,7 @@ implementation
        components new DummyLayerC() as CsmaLayerC;
        components RF230LayerC;
 
-       SplitControl = MessageBufferLayerC;
+       SplitControl = LowPowerListeningLayerC;
        AMSend = ActiveMessageLayerC;
        Receive = ActiveMessageLayerC.Receive;
        Snoop = ActiveMessageLayerC.Snoop;
@@ -83,10 +86,14 @@ implementation
        ActiveMessageLayerC.Config -> DefaultMacP;
        ActiveMessageLayerC.AMPacket -> IEEE154PacketC;
        ActiveMessageLayerC.SubSend -> UniqueLayerC;
-       ActiveMessageLayerC.SubReceive -> MessageBufferLayerC;
+       ActiveMessageLayerC.SubReceive -> LowPowerListeningLayerC;
 
        UniqueLayerC.Config -> DefaultMacP;
-       UniqueLayerC.SubSend -> MessageBufferLayerC;
+       UniqueLayerC.SubSend -> LowPowerListeningLayerC;
+
+       LowPowerListeningLayerC.SubControl -> MessageBufferLayerC;
+       LowPowerListeningLayerC.SubSend -> MessageBufferLayerC;
+       LowPowerListeningLayerC.SubReceive -> MessageBufferLayerC;
 
        MessageBufferLayerC.Packet -> DefaultPacketC;
        MessageBufferLayerC.RadioSend -> TrafficMonitorLayerC;
index 1658139d7f14af21161431a6c388ce3212d19bdb..79981597393946ed1b33e48e56028068ad145c67 100644 (file)
@@ -32,6 +32,7 @@ configuration DefaultPacketC
                interface PacketAcknowledgements;
                interface PacketField<uint8_t> as PacketLinkQuality;
                interface PacketField<uint8_t> as PacketTransmitPower;
+               interface PacketField<uint16_t> as PacketSleepInterval;
 
                interface PacketTimeStamp<TRF230, uint16_t>;
                interface PacketLastTouch;
@@ -51,6 +52,7 @@ implementation
        PacketAcknowledgements = DefaultPacketP;
        PacketLinkQuality = DefaultPacketP.PacketLinkQuality;
        PacketTransmitPower = DefaultPacketP.PacketTransmitPower;
+       PacketSleepInterval = DefaultPacketP.PacketSleepInterval;
        PacketTimeStamp = DefaultPacketP;
 
        PacketLastTouch = DefaultPacketP;
index 577ff252ca8f17219935c1cb2fdccc0170f5d20d..e7d0442371c94a7ee9ab17a200b31a21631e62de 100644 (file)
@@ -31,6 +31,7 @@ module DefaultPacketP
                interface Packet;
                interface PacketField<uint8_t> as PacketLinkQuality;
                interface PacketField<uint8_t> as PacketTransmitPower;
+               interface PacketField<uint16_t> as PacketSleepInterval;
 
                interface PacketTimeStamp<TRF230, uint16_t>;
                interface PacketLastTouch;
@@ -167,9 +168,11 @@ implementation
        enum
        {
                FLAG_TXPOWER = 0x01,
+               FLAG_SLEEPINT = 0x02,
        };
 
        uint8_t transmitPower;
+       uint16_t sleepInterval;
 
 /*----------------- PacketTransmitPower -----------------*/
 
@@ -194,6 +197,29 @@ implementation
                transmitPower = value;
        }
 
+/*----------------- PacketSleepInterval -----------------*/
+
+       async command bool PacketSleepInterval.isSet(message_t* msg)
+       {
+               return flags & FLAG_SLEEPINT;
+       }
+
+       async command uint16_t PacketSleepInterval.get(message_t* msg)
+       {
+               return sleepInterval;
+       }
+
+       async command void PacketSleepInterval.clear(message_t* msg)
+       {
+               flags &= ~FLAG_SLEEPINT;
+       }
+
+       async command void PacketSleepInterval.set(message_t* msg, uint16_t value)
+       {
+               flags |= FLAG_SLEEPINT;
+               sleepInterval = value;
+       }
+
 /*----------------- PacketLastTouch -----------------*/
        
        async command void PacketLastTouch.request(message_t* msg)
diff --git a/tos/chips/rf230/DummyLPLMacC.nc b/tos/chips/rf230/DummyLPLMacC.nc
deleted file mode 100644 (file)
index ae42f5e..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2007, Vanderbilt University
- * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
- * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- *
- * Author: Janos Sallai
- */
-
-/* This component adds a dummy Low Power Listening support to the default rf230
- * MAC. The functions of the LowPowerListening interface do nothing. */
-configuration DummyLPLMacC
-{
-       provides 
-       {
-               interface SplitControl;
-
-               interface AMSend[am_id_t id];
-               interface Receive[am_id_t id];
-               interface Receive as Snoop[am_id_t id];
-
-               interface Packet;
-               interface AMPacket;
-               interface PacketAcknowledgements;
-               interface LowPowerListening;
-       }
-}
-
-implementation
-{
-       components DefaultMacC, DummyLPLP;
-
-       SplitControl = DefaultMacC;
-       AMSend = DefaultMacC;
-       Receive = DefaultMacC.Receive;
-       Snoop = DefaultMacC.Snoop;
-       Packet = DefaultMacC;
-       AMPacket = DefaultMacC;
-       PacketAcknowledgements = DefaultMacC;
-       LowPowerListening = DummyLPLP;
-}
diff --git a/tos/chips/rf230/DummyLPLP.nc b/tos/chips/rf230/DummyLPLP.nc
deleted file mode 100644 (file)
index 7ee79b9..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2007, Vanderbilt University
- * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
- * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- *
- * Author: Janos Sallai
- */
-
-module DummyLPLP {
-  provides interface LowPowerListening as LPL;
-}
-implementation {
-  command void LPL.setLocalSleepInterval(uint16_t sleepIntervalMs)
-    {}
-  command uint16_t LPL.getLocalSleepInterval()
-    { return 0; }
-  command void LPL.setLocalDutyCycle(uint16_t dutyCycle) {}
-  command uint16_t LPL.getLocalDutyCycle()
-    { return 10000; }
-  command void LPL.setRxSleepInterval(message_t *msg, uint16_t sleepIntervalMs)
-    {}
-  command uint16_t LPL.getRxSleepInterval(message_t *msg)
-    { return 0; }
-  command void LPL.setRxDutyCycle(message_t *msg, uint16_t dutyCycle)
-    {}
-  command uint16_t LPL.getRxDutyCycle(message_t *msg)
-    { return 10000; }
-  command uint16_t LPL.dutyCycleToSleepInterval(uint16_t dutyCycle)
-    { return 0; }
-  command uint16_t LPL.sleepIntervalToDutyCycle(uint16_t sleepInterval)
-    { return 10000; }
-}
diff --git a/tos/chips/rf230/LowPowerListeningLayerC.nc b/tos/chips/rf230/LowPowerListeningLayerC.nc
new file mode 100644 (file)
index 0000000..f860558
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Miklos Maroti
+ */
+
+configuration LowPowerListeningLayerC
+{
+       provides
+       {
+               interface SplitControl;
+               interface Send;
+               interface Receive;
+
+               interface LowPowerListening;
+       }
+       uses
+       {
+               interface SplitControl as SubControl;
+               interface Send as SubSend;
+               interface Receive as SubReceive;
+
+               interface PacketField<uint16_t> as PacketSleepInterval;
+       }
+}
+
+implementation
+{
+       components LowPowerListeningLayerP, new TimerMilliC();
+
+       LowPowerListening = LowPowerListeningLayerP;
+       PacketSleepInterval = LowPowerListeningLayerP;
+       SplitControl = LowPowerListeningLayerP;
+       SubControl = LowPowerListeningLayerP;
+       Send = LowPowerListeningLayerP;
+       SubSend = LowPowerListeningLayerP;
+       Receive = LowPowerListeningLayerP;
+       SubReceive = LowPowerListeningLayerP;
+       
+       LowPowerListeningLayerP.Timer -> TimerMilliC;
+}
diff --git a/tos/chips/rf230/LowPowerListeningLayerP.nc b/tos/chips/rf230/LowPowerListeningLayerP.nc
new file mode 100644 (file)
index 0000000..5325284
--- /dev/null
@@ -0,0 +1,379 @@
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Miklos Maroti
+ */
+
+#include <RadioAssert.h>
+
+module LowPowerListeningLayerP
+{
+       provides
+       {
+               interface SplitControl;
+               interface Send;
+               interface Receive;
+
+               interface LowPowerListening;
+       }
+
+       uses
+       {
+               interface SplitControl as SubControl;
+               interface Send as SubSend;
+               interface Receive as SubReceive;
+
+               interface PacketField<uint16_t> as PacketSleepInterval;
+               interface Timer<TMilli>;
+       }
+}
+
+implementation
+{
+       enum
+       {
+               // minimum wakeup time to catch a transmission in milliseconds
+               LISTEN_WAKEUP = 6,      // use xxxL if LISTEN_WAKEUP * 10000 > 65535
+
+               // extra wakeup time after receiving a message in milliseconds
+               AFTER_RECEIVE = 10,
+
+               // extra wakeup time after transmitting a message in milliseconds
+               AFTER_TRANSMIT = 10,
+
+               MIN_SLEEP = 2,          // the minimum sleep interval in milliseconds
+               MAX_SLEEP = 30000,      // the maximum sleep interval in milliseconds
+               MIN_DUTY = 2,           // the minimum duty cycle
+       };
+
+       uint16_t rxSleepInterval;
+
+/*----------------- state machine -----------------*/
+
+       enum
+       {
+               STATE_OFF = 0,          // timer off, radio off
+               STATE_SLEEP = 1,        // timer on, radio off
+               STATE_LISTEN = 2,       // timer on/off, radio on
+               STATE_SEND = 3,         // timer on/off, radio on
+
+               STATE_OFF_TO_LISTEN = 10,
+               STATE_SLEEP_TO_LISTEN = 11,
+               STATE_SLEEP_TO_SEND = 12,
+               STATE_SLEEP_TO_OFF = 13,
+               STATE_LISTEN_TO_SLEEP_1 = 14,   // we go back to listen if a message arrives in this state
+               STATE_LISTEN_TO_SLEEP_2 = 15,
+               STATE_LISTEN_TO_OFF = 16,
+               STATE_SEND_DONE = 17,
+       };
+
+       uint8_t state;
+
+       message_t* txMsg;
+       uint8_t txLen;
+
+       task void transition()
+       {
+               error_t error;
+
+               if( state == STATE_OFF_TO_LISTEN || state == STATE_SLEEP_TO_LISTEN || state == STATE_SLEEP_TO_SEND )
+               {
+                       error = call SubControl.start();
+                       ASSERT( error == SUCCESS || error == EBUSY );
+
+                       if( error != SUCCESS )
+                               post transition();
+               }
+               else if( state == STATE_LISTEN_TO_OFF || state == STATE_LISTEN_TO_SLEEP_1 )
+               {
+                       error = call SubControl.stop();
+                       ASSERT( error == SUCCESS || error == EBUSY );
+
+                       if( error != SUCCESS )
+                               post transition();
+                       else if( state == STATE_LISTEN_TO_SLEEP_1 )
+                               state = STATE_LISTEN_TO_SLEEP_2;
+               }
+               else if( state == STATE_SLEEP_TO_OFF )
+               {
+                       state = STATE_OFF;
+                       signal SplitControl.stopDone(SUCCESS);
+               }
+               else if( state == STATE_SEND )
+               {
+                       error = call SubSend.send(txMsg, txLen);
+                       if( error == SUCCESS )
+                               state = STATE_SEND_DONE;
+                       else
+                       {
+                               state = STATE_LISTEN;
+                               if( rxSleepInterval > 0 )
+                                       call Timer.startOneShot(AFTER_TRANSMIT);
+
+                               signal Send.sendDone(txMsg, error);
+                       }
+               }
+               else if( state == STATE_LISTEN )
+               {
+                       if( rxSleepInterval > 0 )
+                               call Timer.startOneShot(LISTEN_WAKEUP);
+               }
+               else if( state == STATE_SLEEP )
+               {
+                       if( rxSleepInterval > 0 )
+                               call Timer.startOneShot(rxSleepInterval);
+                       else
+                       {
+                               state = STATE_SLEEP_TO_LISTEN;
+                               post transition();
+                       }
+               }
+       }
+
+       command error_t SplitControl.start()
+       {
+               if( state != STATE_OFF )
+                       return EALREADY;
+
+               state = STATE_OFF_TO_LISTEN;
+               post transition();
+
+               return SUCCESS;
+       }
+
+       event void SubControl.startDone(error_t error)
+       {
+               ASSERT( error == SUCCESS || error == EBUSY );
+               ASSERT( state == STATE_OFF_TO_LISTEN || state == STATE_SLEEP_TO_LISTEN || state == STATE_SLEEP_TO_SEND );
+
+               if( error == SUCCESS )
+               {
+                       if( state == STATE_OFF_TO_LISTEN )
+                               signal SplitControl.startDone(SUCCESS);
+                       else if( state == STATE_SLEEP_TO_SEND )
+                               state = STATE_SEND;
+                       else
+                               state = STATE_LISTEN;
+               }
+
+               post transition();
+       }
+
+       command error_t SplitControl.stop()
+       {
+               if( state == STATE_OFF )
+                       return EALREADY;
+               else if( state != STATE_LISTEN || state != STATE_SLEEP )
+                       return EBUSY;
+
+               call Timer.stop();
+               if( state == STATE_SLEEP )
+                       state = STATE_SLEEP_TO_OFF;
+               else
+                       state = STATE_LISTEN_TO_OFF;
+
+               post transition();
+
+               return SUCCESS;
+       }
+
+       event void SubControl.stopDone(error_t error)
+       {
+               ASSERT( error == SUCCESS || error == EBUSY );
+               ASSERT( state == STATE_LISTEN_TO_SLEEP_2 || state == STATE_LISTEN_TO_OFF );
+
+               if( error == SUCCESS )
+               {
+                       if( state == STATE_LISTEN_TO_OFF )
+                               state = STATE_SLEEP_TO_OFF;
+                       else
+                               state = STATE_SLEEP;
+               }
+
+               post transition();
+       }
+
+       event void Timer.fired()
+       {
+               ASSERT( state == STATE_LISTEN || state == STATE_SLEEP );
+
+               if( state == STATE_LISTEN )
+                       state = STATE_LISTEN_TO_SLEEP_1;
+               else
+                       state = STATE_SLEEP_TO_LISTEN;
+
+               post transition();
+       }
+
+       void rxSleepIntervalChanged()
+       {
+               if( rxSleepInterval == 0 )
+               {
+                       call Timer.stop();
+                       if( state == STATE_SLEEP )
+                               state = STATE_SLEEP_TO_LISTEN;
+               }
+
+               post transition();
+       }
+
+       event message_t* SubReceive.receive(message_t* msg, void* payload, uint8_t len)
+       {
+               if( state == STATE_LISTEN_TO_SLEEP_1 )
+                       state = STATE_LISTEN;
+
+               if( state == STATE_LISTEN && rxSleepInterval > 0 )
+                       call Timer.startOneShot(AFTER_RECEIVE);
+
+               return signal Receive.receive(msg, payload, len);
+       }
+
+       command error_t Send.send(message_t* msg, uint8_t len)
+       {
+               if( state == STATE_LISTEN || state == STATE_SLEEP )
+                       call Timer.stop();
+
+               if( state == STATE_LISTEN || state == STATE_LISTEN_TO_SLEEP_1 )
+               {
+                       state = STATE_SEND;
+                       post transition();
+               }
+               else if( state == STATE_SLEEP )
+               {
+                       state = STATE_SLEEP_TO_SEND;
+                       post transition();
+               }
+               else if( state == STATE_SLEEP_TO_LISTEN )
+                       state = STATE_SLEEP_TO_SEND;
+               else
+                       return EBUSY;
+
+               txMsg = msg;
+               txLen = len;
+       }
+
+       command error_t Send.cancel(message_t* msg)
+       {
+               return call SubSend.cancel(msg);
+       }
+
+       event void SubSend.sendDone(message_t* msg, error_t error)
+       {
+               ASSERT( state == STATE_SEND_DONE );
+
+               state = STATE_LISTEN;
+               if( rxSleepInterval > 0 )
+                       call Timer.startOneShot(AFTER_TRANSMIT);
+
+               signal Send.sendDone(msg, error);
+       }
+
+       command uint8_t Send.maxPayloadLength()
+       {
+               return call SubSend.maxPayloadLength();
+       }
+
+       command void* Send.getPayload(message_t* msg, uint8_t len)
+       {
+               return call SubSend.getPayload(msg, len);
+       }
+
+/*----------------- LowPowerListening -----------------*/
+
+       command uint16_t LowPowerListening.dutyCycleToSleepInterval(uint16_t dutyCycle)
+       {
+               if( dutyCycle >= 10000 )
+                       return 0;
+               else if( dutyCycle <= MIN_DUTY  )
+                       return MAX_SLEEP;
+
+               return ((10000 * LISTEN_WAKEUP) / dutyCycle) - LISTEN_WAKEUP;
+       }
+
+       command uint16_t LowPowerListening.sleepIntervalToDutyCycle(uint16_t sleepInterval)
+       {
+               if( sleepInterval < MIN_SLEEP )
+                       return 10000;
+               else if( sleepInterval >= MAX_SLEEP )
+                       return MIN_DUTY;
+
+               return (10000 * LISTEN_WAKEUP) / (LISTEN_WAKEUP + sleepInterval);
+       }
+
+       command void LowPowerListening.setLocalSleepInterval(uint16_t sleepInterval)
+    {
+               if( sleepInterval < MIN_SLEEP )
+                       sleepInterval = 0;
+               else if( sleepInterval > MAX_SLEEP )
+                       sleepInterval = MAX_SLEEP;
+
+               rxSleepInterval = sleepInterval;
+               rxSleepIntervalChanged();
+       }
+
+       command uint16_t LowPowerListening.getLocalSleepInterval()
+    {  
+               return rxSleepInterval;
+       }
+
+       command void LowPowerListening.setLocalDutyCycle(uint16_t dutyCycle)
+       {
+               call LowPowerListening.setLocalSleepInterval(
+                       call LowPowerListening.dutyCycleToSleepInterval(dutyCycle));
+       }
+
+       command uint16_t LowPowerListening.getLocalDutyCycle()
+       {
+               return call LowPowerListening.sleepIntervalToDutyCycle(rxSleepInterval);
+       }
+
+       command void LowPowerListening.setRxSleepInterval(message_t *msg, uint16_t sleepInterval)
+       {
+               if( sleepInterval < MIN_SLEEP )
+                       sleepInterval = 0;
+               else if( sleepInterval > MAX_SLEEP )
+                       sleepInterval = MAX_SLEEP;
+
+               call PacketSleepInterval.set(msg, sleepInterval);
+       }
+
+       command uint16_t LowPowerListening.getRxSleepInterval(message_t *msg)
+    {
+               if( ! call PacketSleepInterval.isSet(msg) )
+                       return 0;
+
+               return call PacketSleepInterval.get(msg);
+       }
+
+       command void LowPowerListening.setRxDutyCycle(message_t *msg, uint16_t dutyCycle)
+    {
+               call PacketSleepInterval.set(msg, 
+                       call LowPowerListening.dutyCycleToSleepInterval(dutyCycle));
+       }
+
+       command uint16_t LowPowerListening.getRxDutyCycle(message_t *msg)
+    {
+               if( ! call PacketSleepInterval.isSet(msg) )
+                       return 10000;
+
+               return call LowPowerListening.sleepIntervalToDutyCycle(
+                       call PacketSleepInterval.get(msg));
+       }
+}
index 091b6cdc6c888ceafcded1bbbcbe5ac9b4032f51..738835b0f35131d2d148350ba24106bfea6d2926 100644 (file)
@@ -104,7 +104,7 @@ implementation
                
                s = state;
 
-               // change the state before so we can be reentered rom the event
+               // change the state before so we can be reentered from the event
                if( s == STATE_TURN_ON || s == STATE_TURN_OFF )
                        state = STATE_READY;
 
@@ -258,7 +258,7 @@ implementation
        {
                bool notFull;
 
-               // this prevents undelivered messages to be acknowledged
+               // this prevents undeliverable messages to be acknowledged
                atomic notFull = receiveQueueSize < RECEIVE_QUEUE_SIZE;
 
                return notFull;
index ec00392b24e17467c436158c5d5a817e647acbd1..cc4b7db4a81befc174d70bdae5046cf949a7dc3d 100644 (file)
@@ -41,7 +41,7 @@ interface Neighborhood
         * Returns the age of the given entry. The age is incremented by one
         * every time a new node is inserted into the neighborhood table that
         * is not already at the very end. If the age would get too large to
-        * fit into a byte, then it is periodically reset to a large value.
+        * fit into a byte, then it is periodically reset to a smaller value.
         */
        tasklet_async command uint8_t getAge(uint8_t index);
 
index 3cd59d8a254fad08d04a332868f88ff355b942ba..66eca0ded58d20f7343a7d22789ad450b1cbcac9 100644 (file)
@@ -21,6 +21,8 @@
  * Author: Miklos Maroti
  */
 
+#include <HplRF230.h>
+
 configuration RF230LayerC
 {
        provides