]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/rf2xx/layers/LowPowerListeningLayerP.nc
tune the LPL constants (use 5 ms listen check)
[tinyos-2.x.git] / tos / chips / rf2xx / layers / LowPowerListeningLayerP.nc
index 5a78dcce5f6429be4ab1f706bdff7b10641f7c8d..b965af8a4f61c159edae10bbdf1b112990bed615 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <RadioAssert.h>
 #include <LowPowerListeningLayer.h>
+#include <Lpl.h>
 
 module LowPowerListeningLayerP
 {
@@ -46,6 +47,9 @@ module LowPowerListeningLayerP
                interface PacketAcknowledgements;
                interface LowPowerListeningConfig as Config;
                interface Timer<TMilli>;
+               interface SystemLowPowerListening;
+
+               interface Leds;
        }
 }
 
@@ -53,21 +57,10 @@ implementation
 {
        enum
        {
-               // minimum wakeup time to catch a transmission in milliseconds
-               LISTEN_WAKEUP = 6U,     // use xxxL if LISTEN_WAKEUP * 10000 > 65535
-
-               // extra wakeup time after receiving a message in milliseconds
-               AFTER_RECEIVE = 10U,
-
-               // extra wakeup time after transmitting a message in milliseconds
-               AFTER_TRANSMIT = 10U,
-
                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 sleepInterval;
+       uint16_t sleepInterval = LPL_DEF_LOCAL_WAKEUP;
 
        message_t* txMsg;
        error_t txError;
@@ -114,7 +107,10 @@ implementation
                        ASSERT( error == SUCCESS || error == EBUSY );
 
                        if( error == SUCCESS )
+                       {
+                               call Leds.led2On();
                                ++state;
+                       }
                        else
                                post transition();
                }
@@ -124,7 +120,10 @@ implementation
                        ASSERT( error == SUCCESS || error == EBUSY );
 
                        if( error == SUCCESS )
+                       {
                                ++state;
+                               call Leds.led2Off();
+                       }
                        else
                                post transition();
                }
@@ -144,7 +143,7 @@ implementation
                {
                        state = LISTEN;
                        if( sleepInterval > 0 )
-                               call Timer.startOneShot(LISTEN_WAKEUP);
+                               call Timer.startOneShot(call Config.getListenLength());
                }
                else if( state == SLEEP_TIMER )
                {
@@ -161,10 +160,11 @@ implementation
                }
                else if( state == SEND_TIMER )
                {
-                       transmitInterval = call LowPowerListening.getRxSleepInterval(txMsg);
+                       transmitInterval = call LowPowerListening.getRemoteWakeupInterval(txMsg);
 
                        if( transmitInterval > 0 )
-                               call Timer.startOneShot(transmitInterval);
+                               call Timer.startOneShot(transmitInterval 
+                                       + 2 * call Config.getListenLength());
 
                        state = SEND_SUBSEND;
                        post transition();
@@ -185,7 +185,7 @@ implementation
                {
                        state = LISTEN;
                        if( sleepInterval > 0 )
-                               call Timer.startOneShot(AFTER_TRANSMIT);
+                               call Timer.startOneShot(call SystemLowPowerListening.getDelayAfterReceive());
 
                        signal Send.sendDone(txMsg, txError);
                }
@@ -270,11 +270,13 @@ implementation
 
        event message_t* SubReceive.receive(message_t* msg)
        {
+               call Leds.led0Toggle();
+
                if( state == SLEEP_SUBSTOP )
                        state = LISTEN;
 
                if( state == LISTEN && sleepInterval > 0 )
-                       call Timer.startOneShot(AFTER_RECEIVE);
+                       call Timer.startOneShot(call SystemLowPowerListening.getDelayAfterReceive());
 
                return signal Receive.receive(msg);
        }
@@ -296,6 +298,9 @@ implementation
                else
                        return EBUSY;
 
+               if( call Config.needsAutoAckRequest(msg) )
+                       call PacketAcknowledgements.requestAck(msg);
+
                txMsg = msg;
                txError = FAIL;
 
@@ -333,9 +338,9 @@ implementation
 
                // TODO: extend the PacketAcknowledgements interface with getAckRequired
                if( error != SUCCESS
-                       || call LowPowerListening.getRxSleepInterval(msg) == 0
+                       || call LowPowerListening.getRemoteWakeupInterval(msg) == 0
                        || state == SEND_SUBSEND_DONE_LAST
-                       || (call Config.getAckRequired(msg) && call PacketAcknowledgements.wasAcked(msg)) )
+                       || (call Config.ackRequested(msg) && call PacketAcknowledgements.wasAcked(msg)) )
                {
                        call Timer.stop();
                        state = SEND_DONE;
@@ -344,6 +349,9 @@ implementation
                        state = SEND_SUBSEND;
 
                post transition();
+
+               if( error == SUCCESS )
+                       call Leds.led1Toggle();
        }
 
 /*----------------- LowPowerListening -----------------*/
@@ -353,32 +361,10 @@ implementation
                return ((void*)msg) + sizeof(message_t) - call RadioPacket.metadataLength(msg);
        }
 
-       command uint16_t LowPowerListening.dutyCycleToSleepInterval(uint16_t dutyCycle)
-       {
-               if( dutyCycle >= 10000 )
-                       return 0;
-               else if( dutyCycle <= MIN_DUTY  )
-                       return MAX_SLEEP;
-
-               return ((10000U * LISTEN_WAKEUP) / dutyCycle) - LISTEN_WAKEUP;
-       }
-
-       command uint16_t LowPowerListening.sleepIntervalToDutyCycle(uint16_t interval)
-       {
-               if( interval < MIN_SLEEP )
-                       return 10000;
-               else if( interval >= MAX_SLEEP )
-                       return MIN_DUTY;
-
-               return (10000U * LISTEN_WAKEUP) / (LISTEN_WAKEUP + interval);
-       }
-
-       command void LowPowerListening.setLocalSleepInterval(uint16_t interval)
+       command void LowPowerListening.setLocalWakeupInterval(uint16_t interval)
        {
                if( interval < MIN_SLEEP )
                        interval = 0;
-               else if( interval > MAX_SLEEP )
-                       interval = MAX_SLEEP;
 
                sleepInterval = interval;
 
@@ -390,49 +376,24 @@ implementation
                }
        }
 
-       command uint16_t LowPowerListening.getLocalSleepInterval()
+       command uint16_t LowPowerListening.getLocalWakeupInterval()
        {       
                return sleepInterval;
        }
 
-       command void LowPowerListening.setLocalDutyCycle(uint16_t dutyCycle)
-       {
-               call LowPowerListening.setLocalSleepInterval(
-                       call LowPowerListening.dutyCycleToSleepInterval(dutyCycle));
-       }
-
-       command uint16_t LowPowerListening.getLocalDutyCycle()
-       {
-               return call LowPowerListening.sleepIntervalToDutyCycle(sleepInterval);
-       }
-
-       command void LowPowerListening.setRxSleepInterval(message_t *msg, uint16_t interval)
+       command void LowPowerListening.setRemoteWakeupInterval(message_t *msg, uint16_t interval)
        {
                if( interval < MIN_SLEEP )
                        interval = 0;
-               else if( interval > MAX_SLEEP )
-                       interval = MAX_SLEEP;
 
                getMeta(msg)->sleepint = interval;
        }
 
-       command uint16_t LowPowerListening.getRxSleepInterval(message_t *msg)
+       command uint16_t LowPowerListening.getRemoteWakeupInterval(message_t *msg)
        {
                return getMeta(msg)->sleepint;
        }
 
-       command void LowPowerListening.setRxDutyCycle(message_t *msg, uint16_t dutyCycle)
-       {
-               call LowPowerListening.setRxSleepInterval(msg, 
-                       call LowPowerListening.dutyCycleToSleepInterval(dutyCycle));
-       }
-
-       command uint16_t LowPowerListening.getRxDutyCycle(message_t *msg)
-       {
-               return call LowPowerListening.sleepIntervalToDutyCycle(
-                       call LowPowerListening.getRxSleepInterval(msg));
-       }
-
 /*----------------- RadioPacket -----------------*/
        
        async command uint8_t RadioPacket.headerLength(message_t* msg)