/*--------------------------------------------------------------------------- * Name: PWR_CheckForAndEnterNewPowerState * Description: - * Parameters: - * Return: - *---------------------------------------------------------------------------*/ static PWRLib_WakeupReason_t PWR_CheckForAndEnterNewPowerState(PWR_CheckForAndEnterNewPowerState_t NewPowerState) { PWRLib_WakeupReason_t ReturnValue; ReturnValue.AllBits = 0; #if (cPWR_UsePowerDownMode) if (NewPowerState == PWR_Run) { /* ReturnValue = 0; */ } else if(NewPowerState == PWR_OFF) { /* Disable all wake up sources */ #if cPWR_EnableDeepSleepMode_4 void PWRLib_LLWU_DisableAllWakeupSources(); /* Configure MCU in VLLS0 mode */ PWR_HandleDeepSleepMode_4(); #endif /* Never returns */ for(;;){} } else if(NewPowerState == PWR_Reset) { /* Never returns */ PWR_SystemReset(); } else if(NewPowerState == PWR_DeepSleep) { if(PWR_CheckIfDeviceCanGoToSleep() && PWR_DeepSleepAllowed()) { ReturnValue = PWR_HandleDeepSleep(); } } else if(NewPowerState == PWR_Sleep) { if(PWR_CheckIfDeviceCanGoToSleep() && PWR_SleepAllowed()) { ReturnValue = PWR_HandleSleep(); } } else { /* ReturnValue = FALSE; */ } /* Clear wakeup reason */ #else /* To remove warning for variabels in function call */ (void)NewPowerState; #endif /* #if (cPWR_UsePowerDownMode) */ return ReturnValue; }
/* 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 ============================================*/