X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=blobdiff_plain;f=tos%2Flib%2Fmac%2Ftkn154%2FRxEnableP.nc;h=5e260174532fba151ba5371707b1cd4b09f63266;hp=6835bed8ae845b454253e3b6717c2967f086edde;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hpb=adf1de6c009d13b7b52e68535c63b28f59c97400 diff --git a/tos/lib/mac/tkn154/RxEnableP.nc b/tos/lib/mac/tkn154/RxEnableP.nc index 6835bed8..5e260174 100644 --- a/tos/lib/mac/tkn154/RxEnableP.nc +++ b/tos/lib/mac/tkn154/RxEnableP.nc @@ -39,56 +39,36 @@ module RxEnableP { provides { - interface Init; + interface Init as Reset; interface MLME_RX_ENABLE; - interface SplitControl as PromiscuousMode; - interface FrameRx; - interface Get as PromiscuousModeGet; interface GetNow as IsRxEnableActive; interface Notify as RxEnableStateChange; } uses { - interface Resource as Token; - interface RadioRx as PromiscuousRx; - interface RadioOff; - interface Set as RadioPromiscuousMode; - interface Ieee802154Debug as Debug; interface Timer as RxEnableTimer; - interface Get as IsBeaconEnabledPAN; interface Get as IsMacPanCoordinator; + interface SuperframeStructure as IncomingSuperframeStructure; + interface SuperframeStructure as OutgoingSuperframeStructure; interface GetNow as IsTrackingBeacons; - interface GetNow as IncomingSfStart; - interface GetNow as IncomingBeaconInterval; - interface Get as IsSendingBeacons; - interface GetNow as OutgoingSfStart; - interface GetNow as OutgoingBeaconInterval; + interface GetNow as IsSendingBeacons; interface Notify as WasRxEnabled; interface TimeCalc; } } implementation { - enum promiscuous_state { - S_IDLE, - S_STARTING, - S_STARTED, - S_STOPPING, - } m_promiscuousState; uint32_t m_rxOnDuration; uint32_t m_rxOnOffset; uint32_t m_rxOnAnchor; norace bool m_isRxEnabled; - bool m_isRxEnableConfirmPending; + bool m_confirmPending; - task void prepareDoneTask(); - task void radioOffDoneTask(); - - command error_t Init.init() + command error_t Reset.init() { - if (m_isRxEnableConfirmPending){ - m_isRxEnableConfirmPending = FALSE; + if (m_confirmPending) { + m_confirmPending = FALSE; signal MLME_RX_ENABLE.confirm(IEEE154_SUCCESS); } m_isRxEnabled = FALSE; @@ -96,70 +76,79 @@ implementation return SUCCESS; } -/* ----------------------- MLME-RX-ENABLE ----------------------- */ + /* ----------------------- MLME-RX-ENABLE ----------------------- */ command ieee154_status_t MLME_RX_ENABLE.request ( bool DeferPermit, uint32_t RxOnTime, - uint32_t RxOnDuration - ) + uint32_t RxOnDuration) { + ieee154_status_t status = IEEE154_SUCCESS; uint32_t lastBeaconTime=0; uint32_t beaconInterval=0; - if (m_isRxEnableConfirmPending) - return IEEE154_TRANSACTION_OVERFLOW; - if (RxOnTime > 0xFFFFFF || RxOnDuration > 0xFFFFFF) - return IEEE154_INVALID_PARAMETER; - if (call IsBeaconEnabledPAN.get()){ - if (call IsSendingBeacons.get() && call IsMacPanCoordinator.get()){ + if (m_confirmPending) + status = IEEE154_TRANSACTION_OVERFLOW; + else if (IEEE154_BEACON_ENABLED_PAN && RxOnTime > 0xFFFFFF) + status = IEEE154_INVALID_PARAMETER; + else if (RxOnDuration > 0xFFFFFF) + status = IEEE154_INVALID_PARAMETER; + else if (IEEE154_BEACON_ENABLED_PAN) { + if (call IsSendingBeacons.getNow() && call IsMacPanCoordinator.get()) { // for OUTGOING SUPERFRAME - lastBeaconTime = call OutgoingSfStart.getNow(); - beaconInterval = call OutgoingBeaconInterval.getNow(); - } else if (call IsTrackingBeacons.getNow()){ + lastBeaconTime = call OutgoingSuperframeStructure.sfStartTime(); + beaconInterval = call OutgoingSuperframeStructure.sfSlotDuration() * 16; + } else if (call IsTrackingBeacons.getNow()) { // for INCOMING SUPERFRAME - lastBeaconTime = call IncomingSfStart.getNow(); - beaconInterval = call IncomingBeaconInterval.getNow(); + lastBeaconTime = call IncomingSuperframeStructure.sfStartTime(); + beaconInterval = call IncomingSuperframeStructure.sfSlotDuration() * 16; } if (beaconInterval == 0) - return IEEE154_PAST_TIME; // we're not even sending/receiving beacons - if (RxOnTime+RxOnDuration >= beaconInterval) - return IEEE154_ON_TIME_TOO_LONG; - if (call TimeCalc.hasExpired(lastBeaconTime, RxOnTime - IEEE154_aTurnaroundTime)){ + status = IEEE154_PAST_TIME; // we're not even sending/receiving beacons + else if (RxOnTime+RxOnDuration >= beaconInterval) + status = IEEE154_ON_TIME_TOO_LONG; + else if (call TimeCalc.hasExpired(lastBeaconTime, RxOnTime - IEEE154_aTurnaroundTime)) { if (!DeferPermit) - return IEEE154_PAST_TIME; + status = IEEE154_PAST_TIME; else { // defer to next beacon RxOnTime += beaconInterval; } } - m_rxOnAnchor = lastBeaconTime; - m_rxOnOffset = RxOnTime; + if (status == IEEE154_SUCCESS) { + m_rxOnAnchor = lastBeaconTime; + m_rxOnOffset = RxOnTime; + } } else { + // this is a nonbeacon-enabled PAN m_rxOnAnchor = call RxEnableTimer.getNow(); m_rxOnOffset = 0; } - m_rxOnDuration = RxOnDuration; - m_isRxEnabled = FALSE; - m_isRxEnableConfirmPending = TRUE; - call RxEnableTimer.startOneShotAt(m_rxOnAnchor, m_rxOnOffset); - signal RxEnableStateChange.notify(TRUE); - return IEEE154_SUCCESS; + + if (status == IEEE154_SUCCESS) { + m_rxOnDuration = RxOnDuration; + m_isRxEnabled = FALSE; + m_confirmPending = TRUE; + call RxEnableTimer.startOneShotAt(m_rxOnAnchor, m_rxOnOffset); + signal RxEnableStateChange.notify(TRUE); + } + dbg_serial("RxEnableP", "MLME_RX_ENABLE.request -> result: %lu\n", (uint32_t) status); + return status; } event void RxEnableTimer.fired() { - if (!m_isRxEnabled){ + if (!m_isRxEnabled) { m_isRxEnabled = TRUE; call RxEnableTimer.startOneShotAt(m_rxOnAnchor, m_rxOnOffset + m_rxOnDuration); } else { m_isRxEnabled = FALSE; - if (m_isRxEnableConfirmPending){ - // this means we tried to enable rx, but never - // succeeded, because there were "other - // responsibilities" - but is SUCCESS really + if (m_confirmPending) { + // this means we tried to enable rx, but never succeeded, because + // there were "other responsibilities" - but is SUCCESS really // an appropriate error code in this case? - m_isRxEnableConfirmPending = FALSE; + m_confirmPending = FALSE; + dbg_serial("RxEnableP", "never actually managed to switch to Rx mode\n"); signal MLME_RX_ENABLE.confirm(IEEE154_SUCCESS); } } @@ -171,104 +160,23 @@ implementation return m_isRxEnabled; } - event void WasRxEnabled.notify( bool val ) + event void WasRxEnabled.notify(bool val) { - if (m_isRxEnabled && m_isRxEnableConfirmPending){ - m_isRxEnableConfirmPending = FALSE; + if (m_isRxEnabled && m_confirmPending) { + m_confirmPending = FALSE; + dbg_serial("RxEnableP", "MLME_RX_ENABLE.confirm, radio is now in Rx mode\n"); signal MLME_RX_ENABLE.confirm(IEEE154_SUCCESS); } } - command error_t RxEnableStateChange.enable(){return FAIL;} - command error_t RxEnableStateChange.disable(){return FAIL;} - -/* ----------------------- Promiscuous Mode ----------------------- */ - - command bool PromiscuousModeGet.get() - { - return (m_promiscuousState == S_STARTED); - } - - command error_t PromiscuousMode.start() - { - if (m_promiscuousState != S_IDLE) - return FAIL; - m_promiscuousState = S_STARTING; - call Token.request(); - call Debug.log(LEVEL_INFO, EnableRxP_PROMISCUOUS_REQUEST, m_promiscuousState, 0, 0); - call Debug.flush(); - return SUCCESS; - } - - event void Token.granted() - { - if (m_promiscuousState != S_STARTING){ - call Token.release(); - return; - } - call RadioPromiscuousMode.set(TRUE); - if (call PromiscuousRx.prepare() != IEEE154_SUCCESS){ - m_promiscuousState = S_IDLE; - call Token.release(); - call Debug.log(LEVEL_IMPORTANT, EnableRxP_RADIORX_ERROR, 0, 0, 0); - signal PromiscuousMode.startDone(FAIL); - } - } - - async event void PromiscuousRx.prepareDone() - { - post prepareDoneTask(); - } - - task void prepareDoneTask() - { - if (m_promiscuousState != S_STARTING){ - call Token.release(); - return; - } - m_promiscuousState = S_STARTED; - call PromiscuousRx.receive(NULL, 0); - signal PromiscuousMode.startDone(SUCCESS); - call Debug.log(LEVEL_INFO, EnableRxP_PROMISCUOUS_ON, m_promiscuousState, 0, 0); - } - - event message_t* PromiscuousRx.received(message_t *frame, ieee154_reftime_t *timestamp) - { - if (m_promiscuousState == S_STARTED){ - ((ieee154_header_t*) frame->header)->length |= FRAMECTL_PROMISCUOUS; - return signal FrameRx.received(frame); - } else - return frame; - } - - command error_t PromiscuousMode.stop() - { - if (m_promiscuousState != S_STARTED) - return FAIL; - m_promiscuousState = S_STOPPING; - call RadioOff.off(); - return SUCCESS; - } - - async event void RadioOff.offDone() - { - post radioOffDoneTask(); - } - - task void radioOffDoneTask() - { - if (m_promiscuousState != S_STOPPING){ - call Token.release(); - return; - } - m_promiscuousState = S_IDLE; - call RadioPromiscuousMode.set(FALSE); - call Token.release(); - signal PromiscuousMode.stopDone(SUCCESS); - call Debug.log(LEVEL_INFO, EnableRxP_PROMISCUOUS_OFF, m_promiscuousState, 0, 0); - } - - default event void PromiscuousMode.startDone(error_t error){} - default event void PromiscuousMode.stopDone(error_t error){} - default event void MLME_RX_ENABLE.confirm(ieee154_status_t status){} + command error_t RxEnableStateChange.enable() {return FAIL;} + command error_t RxEnableStateChange.disable() {return FAIL;} + default event void MLME_RX_ENABLE.confirm(ieee154_status_t status) {} + default async command uint32_t IncomingSuperframeStructure.sfStartTime() {return 0;} + default async command uint16_t IncomingSuperframeStructure.sfSlotDuration() {return 0;} + default async command uint32_t OutgoingSuperframeStructure.sfStartTime() {return 0;} + default async command uint16_t OutgoingSuperframeStructure.sfSlotDuration() {return 0;} + default async command bool IsTrackingBeacons.getNow() { return FALSE;} + default async command bool IsSendingBeacons.getNow() { return FALSE;} + default command ieee154_macPanCoordinator_t IsMacPanCoordinator.get() { return FALSE;} }