]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/rf230/LowPowerListeningLayerP.nc
Proper MSP_BSL_FLAGS for telosa and telosb based platforms using TMI modular tos...
[tinyos-2.x.git] / tos / chips / rf230 / LowPowerListeningLayerP.nc
index 8b4876daf702a66d2553c9431a5d070f077fc9cd..ef4bac568622da67001c384b7a0f47ca8256962b 100644 (file)
@@ -52,13 +52,13 @@ implementation
        enum
        {
                // minimum wakeup time to catch a transmission in milliseconds
-               LISTEN_WAKEUP = 6     // use xxxL if LISTEN_WAKEUP * 10000 > 65535
+               LISTEN_WAKEUP = 6U,     // use xxxL if LISTEN_WAKEUP * 10000 > 65535
 
                // extra wakeup time after receiving a message in milliseconds
-               AFTER_RECEIVE = 10,
+               AFTER_RECEIVE = 10U,
 
                // extra wakeup time after transmitting a message in milliseconds
-               AFTER_TRANSMIT = 10,
+               AFTER_TRANSMIT = 10U,
 
                MIN_SLEEP = 2,          // the minimum sleep interval in milliseconds
                MAX_SLEEP = 30000,      // the maximum sleep interval in milliseconds
@@ -253,7 +253,7 @@ implementation
 
        event void Timer.fired()
        {
-               ASSERT( state == LISTEN || state == SLEEP || state == SEND_SUBSEND|| state == SEND_SUBSEND_DONE );
+               ASSERT( state == LISTEN || state == SLEEP || state == SEND_SUBSEND || state == SEND_SUBSEND_DONE );
 
                if( state == LISTEN )
                        state = SLEEP_SUBSTOP;
@@ -267,16 +267,6 @@ implementation
                post transition();
        }
 
-       void sleepIntervalChanged()
-       {
-               if( (state == LISTEN && sleepInterval == 0) || state == SLEEP )
-               {
-                       call Timer.stop();
-                       --state;
-                       post transition();
-               }
-       }
-
        event message_t* SubReceive.receive(message_t* msg, void* payload, uint8_t len)
        {
                if( state == SLEEP_SUBSTOP )
@@ -296,11 +286,11 @@ implementation
                        post transition();
                }
 
-               if( state == LISTEN_SUBSTART || state == SLEEP_TIMER || state == LISTEN )
+               if( state == LISTEN_SUBSTART || state == SLEEP_TIMER || state == SLEEP )
                        state = SEND_SUBSTART;
                else if( state == LISTEN_SUBSTART_DONE )
                        state = SEND_SUBSTART_DONE;
-               else if( state == LISTEN_TIMER || state == SLEEP_SUBSTOP|| state == LISTEN )
+               else if( state == LISTEN_TIMER || state == SLEEP_SUBSTOP || state == LISTEN )
                        state = SEND_TIMER;
                else
                        return EBUSY;
@@ -308,6 +298,8 @@ implementation
                txMsg = msg;
                txLen = len;
                txError = FAIL;
+
+               return SUCCESS;
        }
 
        command error_t Send.cancel(message_t* msg)
@@ -315,12 +307,19 @@ implementation
                if( state == SEND_SUBSEND )
                {
                        call Timer.stop();
-                       state = LISTEN_TIMER;
+                       state = SEND_DONE;
+                       txError = ECANCEL;
                        post transition();
 
-                       // TODO: ask if sendDone should be called after a succesfull cancel
                        return SUCCESS;
                }
+               else if( state == SEND_SUBSEND_DONE )
+               {
+                       // we stop sending the message even if SubSend.cancel was not succesfull
+                       state = SEND_SUBSEND_DONE_LAST;
+
+                       return call SubSend.cancel(txMsg);
+               }
                else
                        return FAIL;
        }
@@ -366,7 +365,7 @@ implementation
                else if( dutyCycle <= MIN_DUTY  )
                        return MAX_SLEEP;
 
-               return ((10000 * LISTEN_WAKEUP) / dutyCycle) - LISTEN_WAKEUP;
+               return ((10000U * LISTEN_WAKEUP) / dutyCycle) - LISTEN_WAKEUP;
        }
 
        command uint16_t LowPowerListening.sleepIntervalToDutyCycle(uint16_t interval)
@@ -376,7 +375,7 @@ implementation
                else if( interval >= MAX_SLEEP )
                        return MIN_DUTY;
 
-               return (10000 * LISTEN_WAKEUP) / (LISTEN_WAKEUP + interval);
+               return (10000U * LISTEN_WAKEUP) / (LISTEN_WAKEUP + interval);
        }
 
        command void LowPowerListening.setLocalSleepInterval(uint16_t interval)
@@ -387,7 +386,13 @@ implementation
                        interval = MAX_SLEEP;
 
                sleepInterval = interval;
-               sleepIntervalChanged();
+
+               if( (state == LISTEN && sleepInterval == 0) || state == SLEEP )
+               {
+                       call Timer.stop();
+                       --state;
+                       post transition();
+               }
        }
 
        command uint16_t LowPowerListening.getLocalSleepInterval()
@@ -419,23 +424,20 @@ implementation
        command uint16_t LowPowerListening.getRxSleepInterval(message_t *msg)
     {
                if( ! call PacketSleepInterval.isSet(msg) )
-                       return 0;
+                       return sleepInterval;
 
                return call PacketSleepInterval.get(msg);
        }
 
        command void LowPowerListening.setRxDutyCycle(message_t *msg, uint16_t dutyCycle)
     {
-               call PacketSleepInterval.set(msg, 
+               call LowPowerListening.setRxSleepInterval(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));
+                       call LowPowerListening.getRxSleepInterval(msg));
        }
 }