From dac274225f4101f5dd61d0df8c6647d7f7a4c05f Mon Sep 17 00:00:00 2001 From: janhauer Date: Thu, 23 Oct 2008 16:09:28 +0000 Subject: [PATCH] Fixed a bug with the resource transfer --- tos/lib/mac/tkn154/BeaconSynchronizeP.nc | 33 ++++++--- tos/lib/mac/tkn154/BeaconTransmitP.nc | 22 +++--- tos/lib/mac/tkn154/CsmaP.nc | 72 +++++++------------ tos/lib/mac/tkn154/PibP.nc | 14 ++-- tos/lib/mac/tkn154/RxEnableP.nc | 4 +- tos/lib/mac/tkn154/SimpleTransferArbiterP.nc | 24 +------ tos/lib/mac/tkn154/TKN154P.nc | 9 ++- tos/lib/mac/tkn154/TKN154_DEBUG.h | 1 + .../tkn154/dummies/NoBeaconSynchronizeP.nc | 3 +- .../mac/tkn154/dummies/NoBeaconTransmitP.nc | 3 +- tos/lib/mac/tkn154/dummies/NoCoordCfpP.nc | 22 +++--- tos/lib/mac/tkn154/dummies/NoCsmaP.nc | 2 +- tos/lib/mac/tkn154/dummies/NoDeviceCfpP.nc | 21 +++--- tos/lib/mac/tkn154/dummies/NoRxEnableP.nc | 2 +- .../private/ResourceTransferControl.nc | 1 - .../interfaces/private/ResourceTransferred.nc | 3 +- 16 files changed, 107 insertions(+), 129 deletions(-) diff --git a/tos/lib/mac/tkn154/BeaconSynchronizeP.nc b/tos/lib/mac/tkn154/BeaconSynchronizeP.nc index db92fd9b..c4c570c5 100644 --- a/tos/lib/mac/tkn154/BeaconSynchronizeP.nc +++ b/tos/lib/mac/tkn154/BeaconSynchronizeP.nc @@ -71,10 +71,11 @@ module BeaconSynchronizeP interface Alarm as TrackAlarm; interface RadioRx as BeaconRx; interface RadioOff; - interface Get as IsBeaconEnabledPAN; + interface GetNow as IsBeaconEnabledPAN; interface DataRequest; interface FrameRx as CoordRealignmentRx; interface Resource as Token; + interface GetNow as IsTokenRequested; interface ResourceTransferred as TokenTransferred; interface ResourceTransfer as TokenToCap; interface TimeCalc; @@ -157,7 +158,7 @@ implementation currentChannelBit <<= logicalChannel; if (!(currentChannelBit & supportedChannels) || (call MLME_GET.macPANId() == 0xFFFF) || - (channelPage != IEEE154_SUPPORTED_CHANNELPAGE) || !call IsBeaconEnabledPAN.get()) + (channelPage != IEEE154_SUPPORTED_CHANNELPAGE) || !call IsBeaconEnabledPAN.getNow()) return IEEE154_INVALID_PARAMETER; call Debug.log(LEVEL_INFO,SyncP_REQUEST, logicalChannel, channelPage, trackBeacon); @@ -171,7 +172,12 @@ implementation m_internalRequest = FALSE; m_updatePending = TRUE; call Debug.log(LEVEL_INFO,SyncP_RESOURCE_REQUEST, 0, 0, 0); - call Token.request(); + atomic { + // if we are tracking then we'll get the Token automatically, + // otherwise request it now + if (!m_tracking && !call Token.isOwner()) + call Token.request(); + } } call Debug.flush(); return IEEE154_SUCCESS; @@ -191,7 +197,6 @@ implementation event void Token.granted() { - call Debug.flush(); call Debug.log(LEVEL_INFO,SyncP_GOT_RESOURCE, m_lastBeaconRxTime+m_beaconInterval, m_beaconInterval, (m_updatePending<<1)+m_tracking); if (m_updatePending){ @@ -209,6 +214,7 @@ implementation call MLME_GET.macPANId(), m_updateLogicalChannel); } getNextBeacon(); + call Debug.flush(); } void getNextBeacon() @@ -218,11 +224,12 @@ implementation // we have received at least one previous beacon m_state = S_PREPARE; if (!m_tracking){ + // nothing to do, just give up the token call Debug.log(LEVEL_INFO,SyncP_RELEASE_RESOURCE, 0, 0, 0); call Token.release(); return; } - while (call TimeCalc.hasExpired(m_lastBeaconRxTime, m_dt)){ // missed a beacon + while (call TimeCalc.hasExpired(m_lastBeaconRxTime, m_dt)){ // missed a beacon! missed = TRUE; call Debug.log(LEVEL_INFO,SyncP_BEACON_MISSED_1, m_lastBeaconRxTime, m_dt, missed); m_dt += m_beaconInterval; @@ -247,7 +254,12 @@ implementation async event void TokenTransferred.transferred() { - if (m_updatePending) + if (call IsTokenRequested.getNow()){ + // some other component needs the token - we give it up for now, + // but make another request to get it back later + call Token.request(); + call Token.release(); + } else if (m_updatePending) post signalGrantedTask(); else getNextBeacon(); @@ -327,10 +339,10 @@ implementation task void processBeaconTask() { - // valid beacon timestamp is pre-condition for slotted CSMA-CA if (m_beaconSwapBufferReady || !call Frame.isTimestampValid(m_beaconBufferPtr)){ // missed a beacon! + m_sfSlotDuration = 0; // CAP len will be 0 m_numBeaconsLost++; m_dt += m_beaconInterval; call Debug.log(LEVEL_IMPORTANT, SyncP_BEACON_MISSED_3,m_numBeaconsLost,0,m_lastBeaconRxTime); @@ -392,11 +404,12 @@ implementation if (m_stopTracking){ m_tracking = FALSE; call Debug.log(LEVEL_INFO,SyncP_RELEASE_RESOURCE, 0, 0, 0); + if (m_updatePending) // there is already a new request pending... + call Token.request(); call Token.release(); } else { - error_t req = call Token.request(); - call Debug.log(LEVEL_INFO,SyncP_TRANSFER_RESOURCE, req, 0, 0); - call TokenToCap.transfer(); + call Debug.log(LEVEL_INFO,SyncP_TRANSFER_RESOURCE, 0, 0, 0); + call TokenToCap.transfer(); // borrow Token to CAP/CFP module, we'll get it back afterwards } if (pendAddrSpec & PENDING_ADDRESS_SHORT_MASK) diff --git a/tos/lib/mac/tkn154/BeaconTransmitP.nc b/tos/lib/mac/tkn154/BeaconTransmitP.nc index c7b88333..b3b04dbd 100644 --- a/tos/lib/mac/tkn154/BeaconTransmitP.nc +++ b/tos/lib/mac/tkn154/BeaconTransmitP.nc @@ -65,13 +65,14 @@ module BeaconTransmitP interface Alarm as BeaconTxAlarm; interface Timer as BeaconPayloadUpdateTimer; interface RadioOff; - interface Get as IsBeaconEnabledPAN; + interface GetNow as IsBeaconEnabledPAN; interface RadioTx as BeaconTx; interface MLME_GET; interface MLME_SET; interface Resource as Token; interface ResourceTransferred as TokenTransferred; interface ResourceTransfer as TokenToBroadcast; + interface GetNow as IsTokenRequested; interface FrameTx as RealignmentBeaconEnabledTx; interface FrameTx as RealignmentNonBeaconEnabledTx; interface FrameRx as BeaconRequestRx; @@ -229,8 +230,8 @@ implementation status = IEEE154_INVALID_PARAMETER; else if (m_requests & (REQUEST_CONFIRM_PENDING | REQUEST_UPDATE_SF)) status = IEEE154_TRANSACTION_OVERFLOW; - else if ((call IsBeaconEnabledPAN.get() && beaconOrder > 14) || - (!call IsBeaconEnabledPAN.get() && beaconOrder < 15)) + else if ((call IsBeaconEnabledPAN.getNow() && beaconOrder == 15) || + (!call IsBeaconEnabledPAN.getNow() && beaconOrder < 15)) status = IEEE154_INVALID_PARAMETER; else { // new configuration *will* be put in operation @@ -253,7 +254,7 @@ implementation if (coordRealignment) m_requests |= REQUEST_REALIGNMENT; if (m_beaconOrder == 15) // only request token if we're not already transmitting beacons - call Token.request(); + call Token.request(); // otherwise we'll get it eventually and update the superframe then } return status; } @@ -413,7 +414,13 @@ implementation async event void TokenTransferred.transferred() { - post grantedTask(); + if (call IsTokenRequested.getNow()){ + // some other component needs the token - we give it up for now, + // but make another request to get it back later + call Token.request(); + call Token.release(); + } else + post grantedTask(); } async event void RadioOff.offDone() @@ -428,7 +435,7 @@ implementation post grantedTask(); call Debug.log(LEVEL_CRITICAL, StartP_OWNER_TOO_FAST, 0, 0, 0); return; - } else if (m_beaconOrder > 14){ + } else if (m_beaconOrder == 15){ call Token.release(); } else { atomic { @@ -535,8 +542,7 @@ implementation m_BLELen += m_battLifeExtPeriods; } else m_BLELen = 0; - call Token.request(); // register another request, before ... - call TokenToBroadcast.transfer(); // ... we let Broadcast module take over + call TokenToBroadcast.transfer(); // borrow Token to Broadcast/CAP/CFP module, we'll get it back afterwards post txDoneTask(); } diff --git a/tos/lib/mac/tkn154/CsmaP.nc b/tos/lib/mac/tkn154/CsmaP.nc index 18354816..4567accf 100644 --- a/tos/lib/mac/tkn154/CsmaP.nc +++ b/tos/lib/mac/tkn154/CsmaP.nc @@ -72,10 +72,9 @@ generic module CsmaP(uint8_t superframeDirection) interface Alarm as IndirectTxWaitAlarm; interface Alarm as BroadcastAlarm; interface Resource as Token; + interface GetNow as IsTokenRequested; interface ResourceTransfer as TokenToCfp; interface ResourceTransferred as TokenTransferred; - interface ResourceRequested as TokenRequested; - interface GetNow as IsTokenRequested; interface GetNow as CapStart; interface GetNow as CapStartRefTime; interface GetNow as CapLen; @@ -89,7 +88,7 @@ generic module CsmaP(uint8_t superframeDirection) interface RadioTx; interface RadioRx; interface RadioOff; - interface Get as IsBeaconEnabledPAN; + interface GetNow as IsBeaconEnabledPAN; interface MLME_GET; interface MLME_SET; interface Ieee802154Debug as Debug; @@ -138,7 +137,6 @@ implementation norace bool m_indirectTxPending = FALSE; norace bool m_broadcastRxPending; norace ieee154_macMaxFrameTotalWaitTime_t m_macMaxFrameTotalWaitTime; - norace bool m_isBeaconEnabledPAN; uint16_t generateRandomBackoff(uint8_t BE); void stopAllAlarms(); @@ -156,10 +154,6 @@ implementation command error_t Reset.init() { - if (call Token.isOwner()){ - call Leds.led0On(); // internal error - return FAIL; - } if (m_currentFrame) signal FrameTx.transmitDone(m_currentFrame, IEEE154_TRANSACTION_OVERFLOW); if (m_lastFrame) @@ -167,8 +161,6 @@ implementation if (m_bcastFrame) signalTxBroadcastDone(m_bcastFrame, IEEE154_TRANSACTION_OVERFLOW); m_currentFrame = m_lastFrame = m_bcastFrame = NULL; - m_macMaxFrameTotalWaitTime = call MLME_GET.macMaxFrameTotalWaitTime(); - m_isBeaconEnabledPAN = call IsBeaconEnabledPAN.get(); stopAllAlarms(); return SUCCESS; } @@ -177,11 +169,18 @@ implementation { // we got the token, i.e. CAP has just started uint32_t actualCapLen = call CapLen.getNow(); - if (m_isBeaconEnabledPAN && (DEVICE_ROLE && !call IsTrackingBeacons.getNow())){ - // rare case: we're on a beacon-enabled PAN, not tracking beacons, searched - // and didn't find a beacon for aBaseSuperframeDuration*(2n+1) symbols + if (!call IsBeaconEnabledPAN.getNow()){ + call Leds.led0On(); // internal error! + call TokenToCfp.transfer(); + call Debug.log(LEVEL_IMPORTANT, CapP_INTERNAL_ERROR, 0,0,0); + } else if (DEVICE_ROLE && actualCapLen == 0){ + // very rare case: + // this can only happen, if we're on a beacon-enabled PAN, not tracking beacons, + // and searched but didn't find a beacon for aBaseSuperframeDuration*(2n+1) symbols // -> transmit current frame using unslotted CSMA-CA m_numCCA = 1; + updateState(); + return; } else if (actualCapLen < IEEE154_RADIO_GUARD_TIME){ call Debug.log(LEVEL_IMPORTANT, CapP_TOO_SHORT, superframeDirection, actualCapLen, IEEE154_RADIO_GUARD_TIME); call TokenToCfp.transfer(); @@ -216,7 +215,7 @@ implementation return IEEE154_TRANSACTION_OVERFLOW; else { setCurrentFrame(frame); - if (!m_isBeaconEnabledPAN){ + if (!call IsBeaconEnabledPAN.getNow()){ call Token.request(); // prepare for unslotted CSMA-CA } else { // a beacon must be found before transmitting in a beacon-enabled PAN @@ -270,7 +269,7 @@ implementation if (call MLME_GET.macBattLifeExt() && m_macMinBE > 2) m_macMinBE = 2; m_BE = m_macMinBE; - if (m_isBeaconEnabledPAN) + if (call IsBeaconEnabledPAN.getNow()) m_numCCA = 2; else m_numCCA = 1; @@ -337,7 +336,7 @@ implementation m_lock = TRUE; // lock // Check 1: for beacon-enabled PANs, has the CAP finished? - if (m_isBeaconEnabledPAN + if (call IsBeaconEnabledPAN.getNow() && (COORD_ROLE || call IsTrackingBeacons.getNow()) // FALSE only if device could't find a beacon && (call TimeCalc.hasExpired(call CapStart.getNow(), call CapLen.getNow()-IEEE154_RADIO_GUARD_TIME) || !call CapEndAlarm.isRunning())){ @@ -375,11 +374,13 @@ implementation } // Check 4: is some other operation (like MLME-SCAN or MLME-RESET) pending? - else if (call IsTokenRequested.getNow()) { + else if (call IsTokenRequested.getNow() && call IsBeaconEnabledPAN.getNow()) { if (call RadioOff.isOff()) { - stopAllAlarms(); // may still fire, locked through isOwner() - call Token.release(); - next = DO_NOTHING; + stopAllAlarms(); // may still fire, but is locked through isOwner() + // nothing more to do... just release the Token + m_lock = FALSE; // unlock + call TokenToCfp.transfer(); + return; } else next = SWITCH_OFF; } @@ -411,10 +412,12 @@ implementation // Check 8: just make sure the radio is switched off else { next = trySwitchOff(); - if (next == DO_NOTHING && (!m_isBeaconEnabledPAN || (DEVICE_ROLE && !call IsTrackingBeacons.getNow()))){ + if (next == DO_NOTHING && + (!call IsBeaconEnabledPAN.getNow() || (DEVICE_ROLE && call CapLen.getNow() == 0))){ // nothing more to do... just release the Token + stopAllAlarms(); // may still fire, but is locked through isOwner() m_lock = FALSE; // unlock - call TokenToCfp.transfer(); + call Token.release(); return; } } @@ -703,31 +706,10 @@ implementation event void Token.granted() { - // will not happen - } - - task void tokenRequestedTask() - { - signal TokenRequested.requested(); - } - - async event void TokenRequested.requested() - { - // TODO: this event can be generated by the BeaconTransmitP or - // BeaconSynchronizeP component - in this case the Token should - // probably not be released! - atomic { - if (call Token.isOwner()){ - if (!m_lock && !(DEVICE_ROLE && m_indirectTxPending) && !(COORD_ROLE && m_bcastFrame)) - call Token.release(); - else - post tokenRequestedTask(); - } - } + // the current frame should be transmitted using unslotted CSMA-CA + updateState(); } - async event void TokenRequested.immediateRequested() {} - default event void FrameTx.transmitDone(ieee154_txframe_t *data, ieee154_status_t status){} default event message_t* FrameRx.received[uint8_t client](message_t* data){return data;} default async command bool IsRxEnableActive.getNow(){return FALSE;} diff --git a/tos/lib/mac/tkn154/PibP.nc b/tos/lib/mac/tkn154/PibP.nc index eb2f9bd0..d8f1c286 100644 --- a/tos/lib/mac/tkn154/PibP.nc +++ b/tos/lib/mac/tkn154/PibP.nc @@ -50,7 +50,7 @@ module PibP { interface Set as SetMacBeaconTxTime; interface Set as SetMacPanCoordinator; interface Get as IsMacPanCoordinator; - interface Get as IsBeaconEnabledPAN; + interface GetNow as IsBeaconEnabledPAN; interface FrameUtility; interface IEEE154Frame as Frame; interface IEEE154BeaconFrame as BeaconFrame; @@ -77,7 +77,8 @@ implementation ieee154_PIB_t m_pib; uint8_t m_numResetClientPending; bool m_setDefaultPIB; - uint8_t m_panType; + norace uint8_t m_panType; + uint8_t m_updatePANType; uint8_t m_resetSpin; #ifdef IEEE154_EXTENDED_ADDRESS @@ -176,7 +177,7 @@ implementation if (call PromiscuousModeGet.get()) return IEEE154_TRANSACTION_OVERFLOW; // must first cancel promiscuous mode! m_setDefaultPIB = SetDefaultPIB; - m_panType = PANType; + m_updatePANType = PANType; if (!call Token.isOwner()) call Token.request(); return IEEE154_SUCCESS; @@ -202,8 +203,9 @@ implementation event void RadioControl.stopDone(error_t error) { - call CapReset.init(); // resets the CAP component(s) - call CapQueueReset.init(); // resets the CAP queue component(s) + m_panType = m_updatePANType; + call CapReset.init(); // resets the CAP component(s), spool out frames + call CapQueueReset.init(); // resets the CAP queue component(s), spool out frames call MacReset.init(); // resets the remaining components m_resetSpin = 5; post resetSpinTask(); @@ -1047,7 +1049,7 @@ implementation return dest == m_pib.macCoordExtendedAddress; } - command bool IsBeaconEnabledPAN.get() + async command bool IsBeaconEnabledPAN.getNow() { return (m_panType == BEACON_ENABLED_PAN); } diff --git a/tos/lib/mac/tkn154/RxEnableP.nc b/tos/lib/mac/tkn154/RxEnableP.nc index b7dad3a8..100ddac1 100644 --- a/tos/lib/mac/tkn154/RxEnableP.nc +++ b/tos/lib/mac/tkn154/RxEnableP.nc @@ -48,7 +48,7 @@ module RxEnableP { interface Ieee802154Debug as Debug; interface Timer as RxEnableTimer; - interface Get as IsBeaconEnabledPAN; + interface GetNow as IsBeaconEnabledPAN; interface Get as IsMacPanCoordinator; interface GetNow as IsTrackingBeacons; interface GetNow as IncomingSfStart; @@ -95,7 +95,7 @@ implementation return IEEE154_TRANSACTION_OVERFLOW; if (RxOnTime > 0xFFFFFF || RxOnDuration > 0xFFFFFF) return IEEE154_INVALID_PARAMETER; - if (call IsBeaconEnabledPAN.get()){ + if (call IsBeaconEnabledPAN.getNow()){ if (call IsSendingBeacons.getNow() && call IsMacPanCoordinator.get()){ // for OUTGOING SUPERFRAME lastBeaconTime = call OutgoingSfStart.getNow(); diff --git a/tos/lib/mac/tkn154/SimpleTransferArbiterP.nc b/tos/lib/mac/tkn154/SimpleTransferArbiterP.nc index 76ae05b4..e1f8d68a 100644 --- a/tos/lib/mac/tkn154/SimpleTransferArbiterP.nc +++ b/tos/lib/mac/tkn154/SimpleTransferArbiterP.nc @@ -68,17 +68,12 @@ implementation { uint8_t state = RES_IDLE; norace uint8_t resId = NO_RES; norace uint8_t reqResId; - norace uint8_t numTransfers; - norace bool reqWhileTransferred; task void grantedTask(); - task void checkResourceRequestedTask(); async command error_t Resource.request[uint8_t id]() { signal ResourceRequested.requested[resId](); atomic { - if (numTransfers > 0) - reqWhileTransferred = TRUE; if(state == RES_IDLE) { state = RES_GRANTING; reqResId = id; @@ -106,8 +101,6 @@ implementation { bool released = FALSE; atomic { if(state == RES_BUSY && resId == id) { - numTransfers = 0; - reqWhileTransferred = FALSE; if(call Queue.isEmpty() == FALSE) { reqResId = call Queue.dequeue(); state = RES_GRANTING; @@ -129,34 +122,21 @@ implementation { async command bool IsResourceRequested.getNow() { - return reqWhileTransferred; - } - - task void checkResourceRequestedTask() - { - if (numTransfers && reqWhileTransferred) - signal ResourceRequested.requested[resId](); + return !(call Queue.isEmpty()); } async command error_t ResourceTransferControl.transfer(uint8_t fromClient, uint8_t toClient) { atomic { if (call ArbiterInfo.userId() == fromClient){ - numTransfers += 1; call ResourceConfigure.unconfigure[fromClient](); call ResourceConfigure.configure[resId](); resId = toClient; - post checkResourceRequestedTask(); return SUCCESS; } - } + } return FAIL; } - - async command error_t ResourceTransferControl.release(uint8_t client) - { - return call Resource.release[client](); - } /** Check if the Resource is currently in use diff --git a/tos/lib/mac/tkn154/TKN154P.nc b/tos/lib/mac/tkn154/TKN154P.nc index 0f838375..99d3c848 100644 --- a/tos/lib/mac/tkn154/TKN154P.nc +++ b/tos/lib/mac/tkn154/TKN154P.nc @@ -255,6 +255,7 @@ implementation BeaconTransmitP.SetMacBeaconTxTime -> PibP.SetMacBeaconTxTime; BeaconTransmitP.SetMacPanCoordinator -> PibP.SetMacPanCoordinator; BeaconTransmitP.Token -> BeaconTxRadioClient; + BeaconTransmitP.IsTokenRequested -> BeaconTxRadioClient; BeaconTransmitP.TokenTransferred -> BeaconTxRadioClient; BeaconTransmitP.TokenToBroadcast -> BeaconTxRadioClient; BeaconTransmitP.RealignmentBeaconEnabledTx -> CoordBroadcastP.RealignmentTx; @@ -291,6 +292,7 @@ implementation BeaconSynchronizeP.IsBeaconEnabledPAN -> PibP.IsBeaconEnabledPAN; BeaconSynchronizeP.DataRequest -> PollP.DataRequest[SYNC_CLIENT]; BeaconSynchronizeP.Token -> SyncRadioClient; + BeaconSynchronizeP.IsTokenRequested -> SyncRadioClient; BeaconSynchronizeP.TokenTransferred -> SyncRadioClient; BeaconSynchronizeP.TokenToCap -> SyncRadioClient; BeaconSynchronizeP.TimeCalc -> PibP; @@ -428,10 +430,9 @@ implementation DeviceCap.IndirectTxWaitAlarm = Alarm5; DeviceCap.BroadcastAlarm = Alarm6; DeviceCap.Token -> DeviceCapRadioClient; + DeviceCap.IsTokenRequested -> DeviceCapRadioClient; DeviceCap.TokenToCfp -> DeviceCapRadioClient; DeviceCap.TokenTransferred -> DeviceCapRadioClient; - DeviceCap.TokenRequested -> DeviceCapRadioClient; - DeviceCap.IsTokenRequested -> DeviceCapRadioClient; DeviceCap.CapStart -> BeaconSynchronizeP.CapStart; DeviceCap.CapStartRefTime -> BeaconSynchronizeP.CapStartRefTime; DeviceCap.CapLen -> BeaconSynchronizeP.CapLen; @@ -464,7 +465,6 @@ implementation CoordCap.Token -> CoordCapRadioClient; CoordCap.TokenToCfp -> CoordCapRadioClient; CoordCap.TokenTransferred -> CoordCapRadioClient; - CoordCap.TokenRequested -> CoordCapRadioClient; CoordCap.IsTokenRequested -> CoordCapRadioClient; CoordCap.CapStart -> BeaconTransmitP.CapStart; CoordCap.CapStartRefTime -> BeaconTransmitP.CapStartRefTime; @@ -492,7 +492,6 @@ implementation components new RadioClientC() as DeviceCfpRadioClient; PibP.MacReset -> DeviceCfp; - DeviceCfp.Token -> DeviceCfpRadioClient; DeviceCfp.TokenTransferred -> DeviceCfpRadioClient; DeviceCfp.TokenRequested -> DeviceCfpRadioClient; DeviceCfp.TokenToBeaconSync -> DeviceCfpRadioClient; @@ -515,9 +514,9 @@ implementation components new RadioClientC() as CoordCfpRadioClient; PibP.MacReset -> CoordCfp; - CoordCfp.Token -> CoordCfpRadioClient; CoordCfp.TokenTransferred -> CoordCfpRadioClient; CoordCfp.TokenRequested -> CoordCfpRadioClient; + CoordCfp.IsTokenRequested -> CoordCfpRadioClient; CoordCfp.TokenToBeaconTransmit -> CoordCfpRadioClient; CoordCfp.IsTrackingBeacons -> BeaconSynchronizeP.IsTrackingBeacons; CoordCfp.CfpEnd -> BeaconTransmitP.CfpEnd; diff --git a/tos/lib/mac/tkn154/TKN154_DEBUG.h b/tos/lib/mac/tkn154/TKN154_DEBUG.h index 117ededf..8169f913 100644 --- a/tos/lib/mac/tkn154/TKN154_DEBUG.h +++ b/tos/lib/mac/tkn154/TKN154_DEBUG.h @@ -134,6 +134,7 @@ #define CapP_TOO_SHORT 0 #define CapP_SET_CAP_END 1 #define CapP_CAP_END_FIRED 2 +#define CapP_INTERNAL_ERROR 3 #define DeviceCapTransmitP_CONTINUE 0 #define DeviceCapTransmitP_TOVERFLOW 1 diff --git a/tos/lib/mac/tkn154/dummies/NoBeaconSynchronizeP.nc b/tos/lib/mac/tkn154/dummies/NoBeaconSynchronizeP.nc index be14b1bc..5d49ff36 100644 --- a/tos/lib/mac/tkn154/dummies/NoBeaconSynchronizeP.nc +++ b/tos/lib/mac/tkn154/dummies/NoBeaconSynchronizeP.nc @@ -71,10 +71,11 @@ module NoBeaconSynchronizeP interface Alarm as TrackAlarm; interface RadioRx as BeaconRx; interface RadioOff; - interface Get as IsBeaconEnabledPAN; + interface GetNow as IsBeaconEnabledPAN; interface DataRequest; interface FrameRx as CoordRealignmentRx; interface Resource as Token; + interface GetNow as IsTokenRequested; interface ResourceTransfer as TokenToCap; interface ResourceTransferred as TokenTransferred; interface GetNow as IsSendingBeacons; diff --git a/tos/lib/mac/tkn154/dummies/NoBeaconTransmitP.nc b/tos/lib/mac/tkn154/dummies/NoBeaconTransmitP.nc index 16c443e9..9d6a059f 100644 --- a/tos/lib/mac/tkn154/dummies/NoBeaconTransmitP.nc +++ b/tos/lib/mac/tkn154/dummies/NoBeaconTransmitP.nc @@ -65,11 +65,12 @@ module NoBeaconTransmitP interface Alarm as BeaconTxAlarm; interface Timer as BeaconPayloadUpdateTimer; interface RadioOff; - interface Get as IsBeaconEnabledPAN; + interface GetNow as IsBeaconEnabledPAN; interface RadioTx as BeaconTx; interface MLME_GET; interface MLME_SET; interface Resource as Token; + interface GetNow as IsTokenRequested; interface ResourceTransfer as TokenToBroadcast; interface ResourceTransferred as TokenTransferred; interface FrameTx as RealignmentBeaconEnabledTx; diff --git a/tos/lib/mac/tkn154/dummies/NoCoordCfpP.nc b/tos/lib/mac/tkn154/dummies/NoCoordCfpP.nc index e142bf62..76974d2d 100644 --- a/tos/lib/mac/tkn154/dummies/NoCoordCfpP.nc +++ b/tos/lib/mac/tkn154/dummies/NoCoordCfpP.nc @@ -52,10 +52,10 @@ module NoCoordCfpP interface FrameTx as CfpTx; interface Purge; } uses { - interface Resource as Token; interface ResourceTransferred as TokenTransferred; - interface ResourceRequested as TokenRequested; interface ResourceTransfer as TokenToBeaconTransmit; + interface ResourceRequested as TokenRequested; + interface GetNow as IsTokenRequested; interface GetNow as IsTrackingBeacons; interface GetNow as CfpEnd; interface GetNow as CapStartRefTime; @@ -94,13 +94,11 @@ implementation async event void TokenTransferred.transferred() { // the CFP has started, this component now owns the token - - // because GTS is not implemented we release the token - // (or pass it back to BeaconTransmitP if - // we are not tracking beacons) - if (call IsTrackingBeacons.getNow()) - call Token.release(); - else - call TokenToBeaconTransmit.transfer(); + // because GTS is not implemented we pass it back to the + // BeaconTransmitP component + // Note: this component must not use the Resource + // interface to release the token! + call TokenToBeaconTransmit.transfer(); } async event void CfpEndAlarm.fired() {} @@ -134,10 +132,10 @@ implementation async event void TokenRequested.requested() { - // someone (e.g. SCAN component) requested access to the radio, - // you might want to release the token... + // someone (e.g. SCAN component) requested access to the radio, we + // should pass the token back to BeaconTransmitP, which can release it + // call TokenToBeaconTransmit.transfer(); } async event void TokenRequested.immediateRequested(){ } - event void Token.granted(){ } } diff --git a/tos/lib/mac/tkn154/dummies/NoCsmaP.nc b/tos/lib/mac/tkn154/dummies/NoCsmaP.nc index 790fb7e2..7137064c 100644 --- a/tos/lib/mac/tkn154/dummies/NoCsmaP.nc +++ b/tos/lib/mac/tkn154/dummies/NoCsmaP.nc @@ -73,7 +73,7 @@ generic module NoCsmaP() interface RadioTx; interface RadioRx; interface RadioOff; - interface Get as IsBeaconEnabledPAN; + interface GetNow as IsBeaconEnabledPAN; interface MLME_GET; interface MLME_SET; interface Ieee802154Debug as Debug; diff --git a/tos/lib/mac/tkn154/dummies/NoDeviceCfpP.nc b/tos/lib/mac/tkn154/dummies/NoDeviceCfpP.nc index 0d672ce6..0cda4b60 100644 --- a/tos/lib/mac/tkn154/dummies/NoDeviceCfpP.nc +++ b/tos/lib/mac/tkn154/dummies/NoDeviceCfpP.nc @@ -51,7 +51,6 @@ module NoDeviceCfpP interface FrameTx as CfpTx; interface Purge; } uses { - interface Resource as Token; interface ResourceTransferred as TokenTransferred; interface ResourceRequested as TokenRequested; interface ResourceTransfer as TokenToBeaconSync; @@ -92,14 +91,12 @@ implementation async event void TokenTransferred.transferred() { - // the CFP has started, this component now owns the token. - // because GTS is not implemented we release the token - // (or pass it back to BeaconSynchronizeP if - // we are not transmitting beacons) - if (call IsSendingBeacons.getNow()) - call Token.release(); - else - call TokenToBeaconSync.transfer(); + // the CFP has started, this component now owns the token - + // because GTS is not implemented we pass it back to the + // BeaconTransmitP component + // Note: this component must not use the Resource + // interface to release the token! + call TokenToBeaconSync.transfer(); } async event void CfpEndAlarm.fired() {} @@ -117,10 +114,10 @@ implementation async event void TokenRequested.requested() { - // someone requested access to the radio, you might - // consider releasing it... + // someone (e.g. SCAN component) requested access to the radio, we + // should pass the token back to BeaconSynchronizeP, which can release it + // call TokenToBeaconSync.transfer(); } async event void TokenRequested.immediateRequested(){ } - event void Token.granted(){ } } diff --git a/tos/lib/mac/tkn154/dummies/NoRxEnableP.nc b/tos/lib/mac/tkn154/dummies/NoRxEnableP.nc index 97ad43b8..63d76d82 100644 --- a/tos/lib/mac/tkn154/dummies/NoRxEnableP.nc +++ b/tos/lib/mac/tkn154/dummies/NoRxEnableP.nc @@ -48,7 +48,7 @@ module NoRxEnableP { interface Ieee802154Debug as Debug; interface Timer as RxEnableTimer; - interface Get as IsBeaconEnabledPAN; + interface GetNow as IsBeaconEnabledPAN; interface Get as IsMacPanCoordinator; interface GetNow as IsTrackingBeacons; interface GetNow as IncomingSfStart; diff --git a/tos/lib/mac/tkn154/interfaces/private/ResourceTransferControl.nc b/tos/lib/mac/tkn154/interfaces/private/ResourceTransferControl.nc index 06013582..a7a82ea4 100644 --- a/tos/lib/mac/tkn154/interfaces/private/ResourceTransferControl.nc +++ b/tos/lib/mac/tkn154/interfaces/private/ResourceTransferControl.nc @@ -34,5 +34,4 @@ interface ResourceTransferControl { async command error_t transfer(uint8_t fromClient, uint8_t toClient); - async command error_t release(uint8_t client); } diff --git a/tos/lib/mac/tkn154/interfaces/private/ResourceTransferred.nc b/tos/lib/mac/tkn154/interfaces/private/ResourceTransferred.nc index 1e9ccd7f..48f36507 100644 --- a/tos/lib/mac/tkn154/interfaces/private/ResourceTransferred.nc +++ b/tos/lib/mac/tkn154/interfaces/private/ResourceTransferred.nc @@ -37,8 +37,7 @@ interface ResourceTransferred /** * Ownership of a resource is transferred, possibly overriding the default * queueing policy. This event is similar to an async Resource.granted() - * event, but when a the resource is released, it is released on behalf of - * the client who was last signalled the Resource.granted() event. + * event, initiated by the previous owner of the resource. * * @see ResourceTransfer interface */ -- 2.39.2