/************************************************************************************************** * @fn macSleep * * @brief Puts radio into the selected sleep mode. * * @param sleepState - selected sleep level, see #defines in .h file * * @return TRUE if radio was successfully put into selected sleep mode. * FALSE if it was not safe for radio to go to sleep. ************************************************************************************************** */ uint8 macSleep(uint8 sleepState) { halIntState_t s; /* disable interrupts until macSleepState can be set */ HAL_ENTER_CRITICAL_SECTION(s); /* assert checks */ MAC_ASSERT(macSleepState == MAC_SLEEP_STATE_AWAKE); /* radio must be awake to put it to sleep */ MAC_ASSERT(macRxFilter == RX_FILTER_OFF); /* do not sleep when scanning or in promiscuous mode */ /* if either RX or TX is active or any RX enable flags are set, it's not OK to sleep */ if (macRxActive || macRxOutgoingAckFlag || macTxActive || macRxEnableFlags) { HAL_EXIT_CRITICAL_SECTION(s); return(FALSE); } /* turn off the receiver */ macRxOff(); /* update sleep state variable */ macSleepState = sleepState; /* macSleepState is now set, re-enable interrupts */ HAL_EXIT_CRITICAL_SECTION(s); /* put MAC timer to sleep */ MAC_RADIO_TIMER_SLEEP(); /* put radio in selected sleep mode */ if (sleepState == MAC_SLEEP_STATE_OSC_OFF) { MAC_RADIO_TURN_OFF_OSC(); } else { MAC_ASSERT(sleepState == MAC_SLEEP_STATE_RADIO_OFF); /* unknown sleep state */ MAC_RADIO_TURN_OFF_POWER(); } /* radio successfully entered sleep mode */ return(TRUE); }
/************************************************************************************************** * @fn macSleep * * @brief Puts radio into the selected sleep mode. * * @param sleepState - selected sleep level, see #defines in .h file * * @return TRUE if radio was successfully put into selected sleep mode. * FALSE if it was not safe for radio to go to sleep. ************************************************************************************************** */ BOOL macSleep(void) { BOOL s; /* disable interrupts until macSleepState can be set */ HAL_ENTER_CRITICAL_SECTION(s); /* assert checks */ //MAC_ASSERT(macSleepState == MAC_SLEEP_STATE_AWAKE); /* radio must be awake to put it to sleep */ //MAC_ASSERT(macRxFilter == RX_FILTER_OFF); /* do not sleep when scanning or in promiscuous mode */ if (macSleepState != MAC_SLEEP_STATE_AWAKE) { HAL_EXIT_CRITICAL_SECTION(s); return(FALSE); } /* if either RX or TX is active or any RX enable flags are set, it's not OK to sleep */ if (macTXBusy()) { HAL_EXIT_CRITICAL_SECTION(s); return(FALSE); } /* turn off the receiver */ MAC_RADIO_RXTX_OFF(); MAC_RADIO_FLUSH_RX_FIFO(); /* update sleep state variable */ macSleepState = MAC_SLEEP_STATE_RADIO_OFF; /* macSleepState is now set, re-enable interrupts */ HAL_EXIT_CRITICAL_SECTION(s); /* put MAC timer to sleep */ /* MAC timer 关闭时, T2THD:T2TLD自动保存到T2CAPHPH:T2CAPLPL,T2OF2:T2OF1:T2OF0自动保存到T2PEROF2:T2PEROF1:T2PEROF0 */ MAC_RADIO_TIMER_SLEEP(); /* put radio in selected sleep mode */ MAC_RADIO_TURN_OFF_POWER(); /* radio successfully entered sleep mode */ return(TRUE); }