]> 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 3030f26b078b1828022a5aee646ac15a01abbc58..b965af8a4f61c159edae10bbdf1b112990bed615 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <RadioAssert.h>
 #include <LowPowerListeningLayer.h>
+#include <Lpl.h>
 
 module LowPowerListeningLayerP
 {
@@ -47,20 +48,15 @@ module LowPowerListeningLayerP
                interface LowPowerListeningConfig as Config;
                interface Timer<TMilli>;
                interface SystemLowPowerListening;
+
+               interface Leds;
        }
 }
 
 implementation
 {
-#ifndef LPL_DEF_LOCAL_WAKEUP
-#define LPL_DEF_LOCAL_WAKEUP 0
-#endif
-
        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
        };
 
@@ -111,7 +107,10 @@ implementation
                        ASSERT( error == SUCCESS || error == EBUSY );
 
                        if( error == SUCCESS )
+                       {
+                               call Leds.led2On();
                                ++state;
+                       }
                        else
                                post transition();
                }
@@ -121,7 +120,10 @@ implementation
                        ASSERT( error == SUCCESS || error == EBUSY );
 
                        if( error == SUCCESS )
+                       {
                                ++state;
+                               call Leds.led2Off();
+                       }
                        else
                                post transition();
                }
@@ -141,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,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();
@@ -267,6 +270,8 @@ implementation
 
        event message_t* SubReceive.receive(message_t* msg)
        {
+               call Leds.led0Toggle();
+
                if( state == SLEEP_SUBSTOP )
                        state = LISTEN;
 
@@ -293,6 +298,9 @@ implementation
                else
                        return EBUSY;
 
+               if( call Config.needsAutoAckRequest(msg) )
+                       call PacketAcknowledgements.requestAck(msg);
+
                txMsg = msg;
                txError = FAIL;
 
@@ -332,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;
@@ -341,6 +349,9 @@ implementation
                        state = SEND_SUBSEND;
 
                post transition();
+
+               if( error == SUCCESS )
+                       call Leds.led1Toggle();
        }
 
 /*----------------- LowPowerListening -----------------*/