X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Flib%2Fmac%2Ftkn154%2FBeaconSynchronizeP.nc;h=57f4faeb753ec26a7649801071bcbf3718cf18e4;hb=f671bb50bd1080d906f927b3a6625d5573d5ede8;hp=779a81f41bcf3904ecae0948378fcb95f3266363;hpb=c1b80c969da4a2a77e66e1b1b92b091e774aea5f;p=tinyos-2.x.git diff --git a/tos/lib/mac/tkn154/BeaconSynchronizeP.nc b/tos/lib/mac/tkn154/BeaconSynchronizeP.nc index 779a81f4..57f4faeb 100644 --- a/tos/lib/mac/tkn154/BeaconSynchronizeP.nc +++ b/tos/lib/mac/tkn154/BeaconSynchronizeP.nc @@ -244,8 +244,8 @@ implementation if (call RadioOff.isOff()) signal RadioOff.offDone(); - else - ASSERT(call RadioOff.off() == SUCCESS); + else if (call RadioOff.off() != SUCCESS) + ASSERT(0); } async event void RadioOff.offDone() @@ -267,18 +267,29 @@ implementation async event void BeaconRx.enableRxDone() { + uint32_t dt; + switch (m_state) { case S_INITIAL_SCAN: + // "To acquire beacon synchronization, a device shall enable its + // receiver and search for at most [aBaseSuperframeDuration * (2^n + 1)] + // symbols, where n is the value of macBeaconOrder [...] Once the number + // of missed beacons reaches aMaxLostBeacons, the MLME shall notify the + // next higher layer." (Sect. 7.5.4.1) m_state = S_RECEIVING; - call TrackAlarm.start((((uint32_t) 1 << m_beaconOrder) + (uint32_t) 1) * - (uint32_t) IEEE154_aBaseSuperframeDuration * (uint32_t) IEEE154_aMaxLostBeacons); + dt = (((uint32_t) 1 << m_beaconOrder) + (uint32_t) 1) * + (uint32_t) IEEE154_aBaseSuperframeDuration * + (uint32_t) IEEE154_aMaxLostBeacons; + call TrackAlarm.start(dt); + dbg_serial("BeaconSynchronizeP","Rx enabled, expecting beacon within %lu symbols.\n", dt); break; case S_PREPARE: m_state = S_RECEIVING; - dbg_serial("BeaconSynchronizeP","Rx enabled, expecting beacon in %lu symbols.\n", - (uint32_t) ((m_lastBeaconRxTime + m_dt) - call TrackAlarm.getNow())); - call TrackAlarm.startAt(m_lastBeaconRxTime, m_dt + IEEE154_MAX_BEACON_LISTEN_TIME(m_beaconOrder)); + dt = m_dt + IEEE154_MAX_BEACON_LISTEN_TIME(m_beaconOrder); + call TrackAlarm.startAt(m_lastBeaconRxTime, dt); + dbg_serial("BeaconSynchronizeP","Rx enabled, expecting beacon within %lu symbols.\n", + (uint32_t) ((m_lastBeaconRxTime + dt) - call TrackAlarm.getNow())); break; default: ASSERT(0);