📄 pwr.c
字号:
#error "*** ERROR: cPWR_KBIWakeupEnable has to be set to 1"
#endif
/*---------------------------------------------------------------------------*/
#elif (cPWR_DeepSleepMode==2)
#if (cPWR_KBIWakeupEnable==0)
PWRLib_RTIClockStart( cPWR_RTITickTime, DozeDuration);
if (PWR_Stop3AndOff() != FALSE) {
while ( PWRLib_RTIClockCheck() > 0) {
PWRLib_MCUStop3();
}
PWRLib_RTIClockStop();
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
Res.Bits.DeepSleepTimeout = 1;
PWR_RunAgain();
cPWR_DeepSleepWakeupStackProc; /* User function called only on timeout */
}
#else
#error "*** ERROR: cPWR_KBIWakeupEnable has to be set to 0"
#endif
/*---------------------------------------------------------------------------*/
#elif (cPWR_DeepSleepMode==3)
#if (cPWR_KBIWakeupEnable)
PWRLib_RTIClockStart( cPWR_RTITickTime, DozeDuration);
if (PWR_Stop3AndOff() != FALSE) {
while ((PWRLib_MCU_WakeupReason.Bits.FromKBI == 0 ) && ( PWRLib_RTIClockCheck() > 0)) {
(void) PWRLib_MCUStop3();
}
PWRLib_RTIClockStop();
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
PWR_RunAgain();
if ( PWRLib_RTIClockCheck() == 0) {
Res.Bits.DeepSleepTimeout = 1;
cPWR_DeepSleepWakeupStackProc; /* User function called only on timeout */
}
}
#else
#error "*** ERROR: cPWR_KBIWakeupEnable has to be set to 1"
#endif
/*---------------------------------------------------------------------------*/
#elif (cPWR_DeepSleepMode==30)
#error "*** ERROR: cPWR_DeepSleepMode == 30 not allowed"
/*---------------------------------------------------------------------------*/
#elif (cPWR_DeepSleepMode==31)
#if (cPWR_KBIWakeupEnable)
if ( PWR_RemainingLoops > 0) {
PWR_RemainingLoops--;
PWRLib_RTIClockStart( cSRTISC_Int1024ms, DozeDuration);
if (PWR_Stop3AndOff() != FALSE) {
while (( PWRLib_MCU_WakeupReason.Bits.FromKBI == 0) && ( PWRLib_RTIClockCheck() > 0)) {
(void) PWRLib_MCUStop3();
}
PWRLib_RTIClockStop();
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
PWR_RunAgain();
if ( PWRLib_RTIClockCheck() == 0) {
Res.Bits.DeepSleepTimeout = 1;
cPWR_DeepSleepWakeupStackProc; /* User function called only on timeout*/
}
}
}
#else
#error "*** ERROR: cPWR_KBIWakeupEnable has to be set to 1"
#endif
/*---------------------------------------------------------------------------*/
#elif (cPWR_DeepSleepMode==33)
PWRLib_SetMCUIOForPowerSavingMode();
PWRLib_MCUWait();
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
/*---------------------------------------------------------------------------*/
#elif (cPWR_DeepSleepMode==34)
PWRLib_SetMCUIOForPowerSavingMode();
PWRLib_MCUStop3();
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
/*---------------------------------------------------------------------------*/
#elif (cPWR_DeepSleepMode==35)
PWRLib_SetMCUIOForPowerSavingMode();
PWRLib_MCUStop2();
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
/*---------------------------------------------------------------------------*/
#elif (cPWR_DeepSleepMode==36)
PWRLib_SetMCUIOForPowerSavingMode();
PWRLib_MCUStop1();
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
/*---------------------------------------------------------------------------*/
#elif (cPWR_DeepSleepMode==37)
/*IrqControlLib_DisableAllIrqs(); */
(void) PWRLib_RadioDozeReq(0x0ffff0, FALSE);
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
/*---------------------------------------------------------------------------*/
#elif (cPWR_DeepSleepMode==38)
/*IrqControlLib_DisableAllIrqs(); */
(void) PWRLib_RadioAcomaDozeReq( FALSE);
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
/*---------------------------------------------------------------------------*/
#elif (cPWR_DeepSleepMode==39)
/* IrqControlLib_DisableAllIrqs(); */
PWRLib_RadioHibernateReq();
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
/*---------------------------------------------------------------------------*/
#elif (cPWR_DeepSleepMode==40)
/* IrqControlLib_DisableAllIrqs(); */
PWRLib_RadioHibernateReq();
/* IrqControlLib_DisableAllIrqs(); */
PWRLib_RadioOffReq();
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
/*---------------------------------------------------------------------------*/
#else
#error "*** ERROR: Not a valid cPWR_DeepSleepMode chosen"
#endif
PWRLib_MCU_WakeupReason.AllBits = 0;
return Res;
#else /* #if (cPWR_UsePowerDownMode) else */
Res.AllBits = 0xff | (uint8_t) DozeDuration; /* Last part to avoid unused warning*/
PWRLib_MCU_WakeupReason.AllBits = 0;
return Res; /*(PWRLib_WakeupReason_t) DozeDuration;*/
#endif /* #if (cPWR_UsePowerDownMode) end*/
} /* PWR_HandleDeepSleep =====================================================*/
/*****************************************************************************/
/* Please see in PWRLib.h for description */
PWRLib_WakeupReason_t PWR_HandleSleep( zbClock24_t DozeDuration) {
PWRLib_WakeupReason_t Res;
bool_t ReturnValue;
uint8_t i =10; /* ~10us ATTN pulse @ 62.5KHz */
Res.AllBits = 0;
#if (cPWR_UsePowerDownMode)
/* check whether timer is enabled ? */
if (TPM1SC & 0x40 == 0x40) {
/* 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_SleepMode==0)
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
PWRLib_MCU_WakeupReason.AllBits = 0;
ReturnValue = (bool_t) DozeDuration; /* Dummy line to remove warning */
return Res;
/*---------------------------------------------------------------------------*/
#elif (cPWR_SleepMode==1)
#if (cPWR_MACVersionUsed != 1.05)
if (DozeDuration == 0) {
ReturnValue = PWRLib_RadioAcomaDozeReq(TRUE);
} else {
ReturnValue = PWRLib_RadioDozeReq( DozeDuration, TRUE);
}
#else
ReturnValue = (bool_t) DozeDuration; /* Dummy line to remove warning*/
ReturnValue |= TRUE;
#endif
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
if ( ReturnValue) {
PWRLib_MCUWait();
Res.AllBits = PWRLib_MCU_WakeupReason.AllBits;
Res.Bits.SleepTimeout = 1;
/* Make attn pulse instead of calling AbelWakeUp()
This is done because we have clk0 running (true on the ..Dozereq)
If this is changed to FALSE, call AbelWakeUp instead. */
MC1319xDrv_AttEnable();
while(i) { i--;}
MC1319xDrv_AttDisable();
/* Wait for attn irq to arrive... */
while ( gPowerSaveMode != 0){
}
}
PWRLib_MCU_WakeupReason.AllBits = 0;
return Res;
/*---------------------------------------------------------------------------*/
#else
#error "*** ERROR: Not a valid cPWR_SleepMode chosen"
#endif
} else {
return Res;
}
#else /* #if (cPWR_UsePowerDownMode) else */
Res.AllBits = 0xff | (uint8_t) DozeDuration | ReturnValue; // Last part to avoid unused warning
return Res;
#endif /* #if (cPWR_UsePowerDownMode) end */
} /* PWR_HandleSleep =========================================================*/
/************************************************************************************
*************************************************************************************
* Very Public functions, recommended for general use
*************************************************************************************
************************************************************************************/
/*****************************************************************************/
/* Please see in PWRLib.h for description */
PWRLib_WakeupReason_t PWR_CheckForAndEnterNewPowerState(PWR_CheckForAndEnterNewPowerState_t NewPowerState, zbClock24_t DozeDuration) {
PWRLib_WakeupReason_t ReturnValue;
ReturnValue.AllBits = 0;
#if (cPWR_UsePowerDownMode)
mSETPIN_CHKPWRSTATE_MODE;
if ( NewPowerState == PWR_Run) {
/* ReturnValue = 0; */
}
else if ( NewPowerState == PWR_OFF) {
while ( PWR_AllOff() == FALSE) ; /* Never returns */
}
else if ( NewPowerState == PWR_Reset) {
PWRLib_Reset(); /* Never returns */
}
else if (( NewPowerState == PWR_DeepSleep) && PWR_DeepSleepAllowed()) {
ReturnValue = PWR_HandleDeepSleep( DozeDuration);
}
else if (( NewPowerState == PWR_Sleep) && PWR_SleepAllowed()) {
ReturnValue = PWR_HandleSleep( DozeDuration);
}
else {
/* ReturnValue = FALSE; */
}
/*--- Come here after sleeping or ... */
mMCU_SetStatus( MCU_Running);
mRESETPIN_CHKPWRSTATE_MODE
PWRLib_MCU_WakeupReason.AllBits = 0; /* Clear wakeup reason */
#else
ReturnValue.AllBits = 0xff | (NewPowerState > 0) | (DozeDuration > 0);
/* To remove warning for variabels in functioncall */
#endif /* #if (cPWR_UsePowerDownMode) */
return ReturnValue;
} /* PWR_CheckForAndEnterNewPowerState ============================================*/
/*****************************************************************************/
/* Please see in PWRLib.h for description */
PWRLib_LVD_VoltageLevel_t PWRLib_LVD_ReportLevel(void) {
PWRLib_LVD_VoltageLevel_t Level;
#if (cPWR_LVD_Enable==0)
Level = PWR_NODEPOWER_LEVEL_100;
#elif (cPWR_LVD_Enable==1)
Level = PWRLib_LVD_CollectLevel();
#elif (cPWR_LVD_Enable==2)
Level = PWRLib_LVD_SavedLevel;
#else
#error "*** ERROR: Illegal value for cPWR_LVD_Enable"
#endif /* #if (cPWR_LVD_Enable) */
return Level;
} /* PWRLib_LVD_ReportLevel ================================================*/
/*****************************************************************************/
/* Please see in PWR.h for description */
void PWR_CheckForAndEnterNewPowerState_Init(void) {
#if (cPWR_UsePowerDownMode)
PWRLib_Init();
#endif /* #if (cPWR_UsePowerDownMode) */
} /* PWR_CheckForAndEnterNewPowerState_Init ==================================*/
/********************************************************************************/
void PWR_EnterLowPower(void)
{
uint8_t ccr;
if (PWRLib_LVD_ReportLevel() == PWR_NODEPOWER_LEVEL_CRITICAL) {
/* Voltage <= 1.8V so enter power-off state - to disable false Tx'ing(void)*/
( void )PWR_CheckForAndEnterNewPowerState( PWR_OFF, 0);
}
IrqControlLib_BackupIrqStatus(ccr);
IrqControlLib_DisableAllIrqs();
if (TS_PendingEvents() == FALSE)
{
PWRLib_SetCurrentZigbeeStackPowerState(StackPS_DeepSleep);
if (TMR_AreAllTimersOff()) /*No timer running*/
{
(void)PWR_CheckForAndEnterNewPowerState ( PWR_DeepSleep, cPWR_RTITicks);
}else /*timers are running*/
{
(void)PWR_CheckForAndEnterNewPowerState ( PWR_Sleep, 0);
}
} /* enable irq's if there is pending evens */
IrqControlLib_RestoreIrqStatus(ccr);
IrqControlLib_EnableAllIrqs();
}
/******************************************************************************
*******************************************************************************
* Private functions
*******************************************************************************
******************************************************************************/
/******************************************************************************
*******************************************************************************
* Private Debug stuff
*******************************************************************************
******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -