]> 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 12fd1cfea7716554e63c109faa47f37c05ab7a90..b965af8a4f61c159edae10bbdf1b112990bed615 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <RadioAssert.h>
 #include <LowPowerListeningLayer.h>
+#include <Lpl.h>
 
 module LowPowerListeningLayerP
 {
@@ -47,6 +48,8 @@ module LowPowerListeningLayerP
                interface LowPowerListeningConfig as Config;
                interface Timer<TMilli>;
                interface SystemLowPowerListening;
+
+               interface Leds;
        }
 }
 
@@ -54,12 +57,7 @@ implementation
 {
        enum
        {
-               // minimum wakeup time to catch a transmission in milliseconds
-               LISTEN_WAKEUP = 6U,     // use xxxL if LISTEN_WAKEUP * 10000 > 65535
-
                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 = LPL_DEF_LOCAL_WAKEUP;
@@ -109,7 +107,10 @@ implementation
                        ASSERT( error == SUCCESS || error == EBUSY );
 
                        if( error == SUCCESS )
+                       {
+                               call Leds.led2On();
                                ++state;
+                       }
                        else
                                post transition();
                }
@@ -119,7 +120,10 @@ implementation
                        ASSERT( error == SUCCESS || error == EBUSY );
 
                        if( error == SUCCESS )
+                       {
                                ++state;
+                               call Leds.led2Off();
+                       }
                        else
                                post transition();
                }
@@ -139,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 )
                {
@@ -159,7 +163,8 @@ implementation
                        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();
@@ -265,6 +270,8 @@ implementation
 
        event message_t* SubReceive.receive(message_t* msg)
        {
+               call Leds.led0Toggle();
+
                if( state == SLEEP_SUBSTOP )
                        state = LISTEN;
 
@@ -291,6 +298,9 @@ implementation
                else
                        return EBUSY;
 
+               if( call Config.needsAutoAckRequest(msg) )
+                       call PacketAcknowledgements.requestAck(msg);
+
                txMsg = msg;
                txError = FAIL;
 
@@ -330,7 +340,7 @@ implementation
                if( error != SUCCESS
                        || 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;
@@ -339,6 +349,9 @@ implementation
                        state = SEND_SUBSEND;
 
                post transition();
+
+               if( error == SUCCESS )
+                       call Leds.led1Toggle();
        }
 
 /*----------------- LowPowerListening -----------------*/
@@ -352,8 +365,6 @@ implementation
        {
                if( interval < MIN_SLEEP )
                        interval = 0;
-               else if( interval > MAX_SLEEP )
-                       interval = MAX_SLEEP;
 
                sleepInterval = interval;
 
@@ -374,8 +385,6 @@ implementation
        {
                if( interval < MIN_SLEEP )
                        interval = 0;
-               else if( interval > MAX_SLEEP )
-                       interval = MAX_SLEEP;
 
                getMeta(msg)->sleepint = interval;
        }