From: idgay Date: Tue, 8 Aug 2006 20:04:07 +0000 (+0000) Subject: lpl fixes: X-Git-Tag: tinyos/2.0.1~303 X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=commitdiff_plain;h=eec188dd3e6f09bd63a2976affa77b43274f4e42;p=tinyos-2.x.git lpl fixes: - 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 --- diff --git a/tos/chips/cc1000/CC1000CsmaP.nc b/tos/chips/cc1000/CC1000CsmaP.nc index 8449652e..905ff6c8 100644 --- a/tos/chips/cc1000/CC1000CsmaP.nc +++ b/tos/chips/cc1000/CC1000CsmaP.nc @@ -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) { diff --git a/tos/chips/cc1000/CC1000CsmaRadioC.nc b/tos/chips/cc1000/CC1000CsmaRadioC.nc index b5a169c2..4ca30177 100644 --- a/tos/chips/cc1000/CC1000CsmaRadioC.nc +++ b/tos/chips/cc1000/CC1000CsmaRadioC.nc @@ -108,6 +108,7 @@ implementation { Csma.BusyWait -> BusyWaitMicroC; Rssi.ActualRssi -> Hpl; + Rssi.Resource -> Hpl; Control.CC -> Hpl; Control.BusyWait -> BusyWaitMicroC; } diff --git a/tos/chips/cc1000/CC1000RssiP.nc b/tos/chips/cc1000/CC1000RssiP.nc index 7b768d50..275bb2f8 100644 --- a/tos/chips/cc1000/CC1000RssiP.nc +++ b/tos/chips/cc1000/CC1000RssiP.nc @@ -47,7 +47,10 @@ module CC1000RssiP interface ReadNow as Rssi[uint8_t reason]; async command void cancel(); } - uses interface Read as ActualRssi; + uses { + interface Resource; + interface ReadNow 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); } }