📄 pwr.c
字号:
/************************************************************************************
* Function to handle the different power down states.
*
*
* (c) Copyright 2005, Freescale Semiconductor, Inc. All rights reserved.
*
* Freescale Confidential Proprietary
* Digianswer Confidential
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale.
*
************************************************************************************/
/************************************************************************************
*************************************************************************************
* Includes
*************************************************************************************
************************************************************************************/
#include "PortConfig.h"
#include "PWR_Configuration.h"
#include "PWR_Interface.h"
#include "PWRLib.h"
#include "AppAspInterface.h"
#include "MsgSystem.h"
#include "IrqControlLib.h"
#include "Mc1319xDrv.h"
#include "TMR_Interface.h"
#include "nv_data.h"
extern uint8_t gPowerSaveMode;
extern void Phy_InitOnStartup(uint16_t phyRfCalibration, bool_t useDualAntenna);
/******************************************************************************
*******************************************************************************
* Private macros
*******************************************************************************
******************************************************************************/
/******************************************************************************
*******************************************************************************
* Private prototypes
*******************************************************************************
******************************************************************************/
/******************************************************************************
*******************************************************************************
* Private type definitions
*******************************************************************************
******************************************************************************/
/******************************************************************************
*******************************************************************************
* Private memory declarations
*******************************************************************************
******************************************************************************/
#if (cPWR_DeepSleepMode==31)
uint8_t PWR_RemainingLoops = 1;
#endif /* if (cPWR_DeepSleepMode==31) */
/******************************************************************************
*******************************************************************************
* Public memory declarations
*******************************************************************************
******************************************************************************/
uint8_t mLPMFlag = gAllowDeviceToSleep_c;
/* but recommended to be regarded as private */
/************************************************************************************
* Set the NVM write operation semaphore.
*
* This function will set the NVM write operation semaphore so that the idle task wont
* do a NVM write operation unless this is released by calling
* NVM_ClearCriticalNVMSection.
*
* Interface assumptions:
* None
*
* Return value:
* None
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 230606 SP Created
*
************************************************************************************/
void PWR_AllowDeviceToSleep(void)
{
uint8_t ccr;
IrqControlLib_BackupIrqStatus(ccr);/*To protect from re entrant*/
IrqControlLib_DisableAllIrqs();
if( mLPMFlag != 0 ){
mLPMFlag--;
}
IrqControlLib_RestoreIrqStatus(ccr);
}
/************************************************************************************
* Release the NVM write operation semaphore.
*
* This function will release the NVM write operation semaphore so that the idle task
* can do a NVM write operation.
*
* Interface assumptions:
* None
*
* Return value:
* None
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 230606 SP Created
*
************************************************************************************/
void PWR_DisallowDeviceToSleep(void)
{
uint8_t ccr;
IrqControlLib_BackupIrqStatus(ccr);/*To protect from re entrant*/
IrqControlLib_DisableAllIrqs();
mLPMFlag++;
IrqControlLib_RestoreIrqStatus(ccr);
}
/***********************************************************************************
* This function is used to Check the Permission flag to go to
* low power mode
*
* Interface assumptions:
* None
*
* The routine limitations.
* None
*
* Return value:
* TRUE : If the device is allowed to go to the LPM else FALSE
*
* Effects on global data.
* None
*
* Source of algorithm used.
* None
*
* Revison history:
*
* date Author Comments
* ------ ------ --------
* 030706 USR Created
*****************************************************************************/
bool_t PWR_CheckIfDeviceCanGoToSleep( void )
{
uint8_t ccr;
bool_t returnValue;
IrqControlLib_BackupIrqStatus(ccr);/*To protect from re entrant*/
IrqControlLib_DisableAllIrqs();
returnValue = mLPMFlag == 0 ? TRUE : FALSE;
IrqControlLib_RestoreIrqStatus(ccr);
return returnValue;
}
/*****************************************************************************/
/* Please see in PWRLib.h for description */
bool_t PWR_Stop3AndOff(void) {
#if (cPWR_UsePowerDownMode)
bool_t res;
res = PWRLib_RadioHibernateReq();
if (res == TRUE) {
PWRLib_ClockSetup( SelfClk_2MHz);
IrqControlLib_DisableMC1319xIrq();
PWRLib_SetMCUIOForPowerSavingMode();
PWRLib_RadioOffReq(); /* To Reset RADIO. Has to be after PWRLib_SetMCUIOForPowerSavingMode */
PWRLib_MCUStop3();
}
return res;
#else
return FALSE;
#endif /* #if (cPWR_UsePowerDownMode) */
} /* PWR_Stop3AndOff(void) =================================================== */
/*****************************************************************************/
/* Please see in PWRLib.h for description */
bool_t PWR_AllOff(void) {
#if (cPWR_UsePowerDownMode)
bool_t res;
res = PWRLib_RadioHibernateReq();
if ( res == TRUE) {
IrqControlLib_DisableMC1319xIrq();
PWRLib_SetMCUIOForPowerSavingMode();
PWRLib_RadioOffReq(); /* To Reset RADIO. Has to be after PWRLib_SetMCUIOForPowerSavingMode */
PWRLib_MCUStop1();
}
return res;
#else
return FALSE;
#endif /* #if (cPWR_UsePowerDownMode) */
} /* PWR_AllOff(void) ========================================================*/
/*****************************************************************************/
/* Please see in PWRLib.h for description */
void PWR_RunAgain(void) {
#if (cPWR_UsePowerDownMode)
PWRLib_RadioOnReq();
PWRLib_ResetMCUIOAfterPowerSavingMode();
#if (cPWR_MACVersionUsed != 1.05)
/* AbelRegisterSetup(); */
/* InitializePhy(); */
PWRLib_ClockSetup( Normal_16MHz);
/* We must enable interrupt before initializing Abel, to get the Reset irq.(wakeupisr()), */
IrqControlLib_EnableMC1319xIrq();
/* Init 802.15.4 MAC/PHY stack */
Phy_InitOnStartup(gpMacNvram->Abel_HF_Calibration,gpMacNvram->useDualAntenna);
#else
IrqControlLib_EnableMC1319xIrq();
#endif
/* InitializeMac(FALSE); */ /* Don't init PIB */
(void) PWRLib_RadioWakeReq();
#if (cPWR_MACVersionUsed == 1.05)
PWRLib_ClockSetup( Normal_16MHz);
#endif
#endif /* #if (cPWR_UsePowerDownMode) */
} /* PWR_RunAgain(void) ======================================================*/
/*****************************************************************************/
/* Please see in PWRLib.h for description */
bool_t PWR_DeepSleepAllowed(void) {
#if ( cPWR_UsePowerDownMode)
#if ( cPWR_DeepSleepMode<30) /* Normal running mode*/
if (PWRLib_GetCurrentZigbeeStackPowerState == StackPS_DeepSleep) {
#if (cPWR_MACVersionUsed != 1.05)
if ( PWRLib_GetMacStateReq() == gAspMacStateIdle_c) {
return TRUE;
} else {
return FALSE;
}
#else
return TRUE;
#endif
} else {
return FALSE;
}
#else /* Debug mode */
return TRUE;
#endif
#else /* Debug mode */
return TRUE;
#endif /* #if (cPWR_UsePowerDownMode)*/
} /* PWR_DeepSleepAllowed ==================================================*/
/*****************************************************************************/
/* Please see in PWRLib.h for description */
bool_t PWR_SleepAllowed(void) {
#if (cPWR_UsePowerDownMode)
#if (cPWR_DeepSleepMode<30) /* Normal running mode*/
if (( PWRLib_GetCurrentZigbeeStackPowerState == StackPS_Sleep) || \
( PWRLib_GetCurrentZigbeeStackPowerState == StackPS_DeepSleep)) {
/* if ( PWRLib_GetMacStateReq()==gAspMacStateBusy_c) { This can't be used */
#if (cPWR_MACVersionUsed != 1.05)
if (( PWRLib_GetMacStateReq()==gAspMacStateNotEmpty_c) || \
( PWRLib_GetMacStateReq()==gAspMacStateIdle_c)) {
return TRUE;
} else {
return FALSE;
}
#else /* Debug mode */
return TRUE;
#endif
} else {
return FALSE;
}
#else /* Debug mode */
return TRUE;
#endif
#else /* Debug mode */
return TRUE;
#endif /* #if (cPWR_UsePowerDownMode) else */
} /* PWR_SleepAllowed ======================================================*/
/*****************************************************************************/
/* Please see in PWRLib.h for description */
PWRLib_WakeupReason_t PWR_HandleDeepSleep( zbClock24_t DozeDuration) {
PWRLib_WakeupReason_t Res;
Res.AllBits = 0;
#if (cPWR_UsePowerDownMode)
/* Insure that Key Wakeup interrupts are enabled!! Note insert next line of code if you
always need the keyboard irq enabled while entering sleep.
KBISC |= cKBI1SC; */
/*---------------------------------------------------------------------------*/
#if (cPWR_DeepSleepMode==0)
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
/* No code */
/*---------------------------------------------------------------------------*/
#elif (cPWR_DeepSleepMode==1)
#if (cPWR_KBIWakeupEnable==1)
if (PWR_Stop3AndOff() != FALSE) {
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
PWR_RunAgain();
}
#else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -