]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
lpl fixes:
authoridgay <idgay>
Tue, 8 Aug 2006 20:04:07 +0000 (20:04 +0000)
committeridgay <idgay>
Tue, 8 Aug 2006 20:04:07 +0000 (20:04 +0000)
- faster resource management using immediateRequest (~5% lifetime improvement)
- turn off radio before computing new squelch value (thanks to David Moss)
- fix bug that made radio sometimes stay on for long periods (2.5s) after send

tos/chips/cc1000/CC1000CsmaP.nc
tos/chips/cc1000/CC1000CsmaRadioC.nc
tos/chips/cc1000/CC1000RssiP.nc

index 8449652e9f1ddad82190fae084370ba81a2d3233..905ff6c87e9989dfb4b969c9e9d61cb12fc52feb 100644 (file)
@@ -153,8 +153,8 @@ implementation
   }
 
   void radioOff() {
-    call ByteRadio.off();
     call CC1000Control.off();
+    call ByteRadio.off();
   }
 
   /* LPL preamble length and sleep time computation */
@@ -234,11 +234,13 @@ implementation
       {
       case IDLE_STATE:
        /* Timer already running means that we have a noise floor
-          measurement scheduled. */
+          measurement scheduled. If we just set a new alarm here, we
+          might indefinitely delay noise floor measurements if we're,
+          e,g, transmitting frequently. */
        if (!call WakeupTimer.isRunning())
          if (call CC1000Squelch.settled())
            {
-             if (lplRxPower == 0 || f.txPending)
+             if (lplRxPower == 0)
                call WakeupTimer.startOneShot(CC1K_SquelchIntervalSlow);
              else
                // timeout for receiving a message after an lpl check
@@ -341,6 +343,7 @@ implementation
     */
     if (data > call CC1000Squelch.get() - (call CC1000Squelch.get() >> 2))
       {
+       post sleepCheck();
        // don't be too agressive (ignore really quiet thresholds).
        if (data < call CC1000Squelch.get() + (call CC1000Squelch.get() >> 3))
          {
@@ -348,7 +351,6 @@ implementation
            rssiForSquelch = data;
            post adjustSquelch();
          }
-       post sleepCheck();
       }
     else if (count++ > 5)
       {
index b5a169c2147669d80227701612b588bbda942c74..4ca30177bad4aba3e7174f6be1fe8e3e0bf14c54 100644 (file)
@@ -108,6 +108,7 @@ implementation {
   Csma.BusyWait -> BusyWaitMicroC;
 
   Rssi.ActualRssi -> Hpl;
+  Rssi.Resource -> Hpl;
   Control.CC -> Hpl;
   Control.BusyWait -> BusyWaitMicroC;
 }
index 7b768d504f76bc8fd1b85ed360eabf34c1d77cf2..275bb2f876fc49851f5713b6f2b2c26e514f686f 100644 (file)
@@ -47,7 +47,10 @@ module CC1000RssiP
     interface ReadNow<uint16_t> as Rssi[uint8_t reason];
     async command void cancel();
   }
-  uses interface Read<uint16_t> as ActualRssi;
+  uses {
+    interface Resource;
+    interface ReadNow<uint16_t> as ActualRssi;
+  }
 }
 implementation
 {
@@ -65,43 +68,42 @@ implementation
       currentOp = CANCELLED;
   }
 
-  void startNextOp() {
-    if (nextOp != IDLE)
-      {
-       currentOp = nextOp;
-       nextOp = IDLE;
-       call ActualRssi.read();
-      }
-    else
-      currentOp = IDLE;
-  }
-
-  task void startOpTask() {
-    atomic startNextOp();
+  event void Resource.granted() {
+    call ActualRssi.read();
   }
 
   async command error_t Rssi.read[uint8_t reason]() {
     if (currentOp == IDLE)
       {
-       nextOp = reason;
-       post startOpTask();
+       currentOp = reason;
+       if (call Resource.immediateRequest() == SUCCESS)
+         call ActualRssi.read();
+       else
+         call Resource.request();
       }
-    else // We should only come here with currentOp = CANCELLED
+    else
       nextOp = reason;
     return SUCCESS;
   }
 
-  event void ActualRssi.readDone(error_t result, uint16_t data) {
-    atomic
+  void startNextOp() {
+    currentOp = nextOp;
+    if (nextOp != IDLE)
       {
-       uint8_t op = currentOp;
+       nextOp = IDLE;
+       call ActualRssi.read();
+      }
+    else
+      call Resource.release();
+  }
 
+  async event void ActualRssi.readDone(error_t result, uint16_t data) {
+    atomic
+      {
        /* The code assumes that RSSI measurements are 10-bits 
           (legacy effect) */
-       data >>= 6;
+       signal Rssi.readDone[currentOp](result, data >> 6);
        startNextOp();
-
-       signal Rssi.readDone[op](result, data);
       }
   }