]> 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 5266c356d16d672baf7d781b7a7b0b69c1fa8427..b965af8a4f61c159edae10bbdf1b112990bed615 100644 (file)
@@ -48,6 +48,8 @@ module LowPowerListeningLayerP
                interface LowPowerListeningConfig as Config;
                interface Timer<TMilli>;
                interface SystemLowPowerListening;
+
+               interface Leds;
        }
 }
 
@@ -55,9 +57,6 @@ 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
        };
 
@@ -108,7 +107,10 @@ implementation
                        ASSERT( error == SUCCESS || error == EBUSY );
 
                        if( error == SUCCESS )
+                       {
+                               call Leds.led2On();
                                ++state;
+                       }
                        else
                                post transition();
                }
@@ -118,7 +120,10 @@ implementation
                        ASSERT( error == SUCCESS || error == EBUSY );
 
                        if( error == SUCCESS )
+                       {
                                ++state;
+                               call Leds.led2Off();
+                       }
                        else
                                post transition();
                }
@@ -138,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 )
                {
@@ -158,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();
@@ -264,6 +270,8 @@ implementation
 
        event message_t* SubReceive.receive(message_t* msg)
        {
+               call Leds.led0Toggle();
+
                if( state == SLEEP_SUBSTOP )
                        state = LISTEN;
 
@@ -290,6 +298,9 @@ implementation
                else
                        return EBUSY;
 
+               if( call Config.needsAutoAckRequest(msg) )
+                       call PacketAcknowledgements.requestAck(msg);
+
                txMsg = msg;
                txError = FAIL;
 
@@ -329,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;
@@ -338,6 +349,9 @@ implementation
                        state = SEND_SUBSEND;
 
                post transition();
+
+               if( error == SUCCESS )
+                       call Leds.led1Toggle();
        }
 
 /*----------------- LowPowerListening -----------------*/