soc: stm32wb: Factorize power procedures
Provide some factorization in pm_power_state_set procedure to prepare shutdown case introduction. Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
This commit is contained in:
parent
5bc0451f72
commit
bd00d4f6f9
1 changed files with 41 additions and 44 deletions
|
@ -36,14 +36,8 @@ static void switch_on_hsi(void)
|
|||
}
|
||||
}
|
||||
|
||||
/* Invoke Low Power/System Off specific Tasks */
|
||||
__weak void pm_power_state_set(struct pm_state_info info)
|
||||
static void lpm_hsem_lock(void)
|
||||
{
|
||||
if (info.state != PM_STATE_SUSPEND_TO_IDLE) {
|
||||
LOG_DBG("Unsupported power state %u", info.state);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Implementation of STM32 AN5289 algorithm to enter/exit lowpower */
|
||||
z_stm32_hsem_lock(CFG_HW_RCC_SEMID, HSEM_LOCK_WAIT_FOREVER);
|
||||
if (!LL_HSEM_1StepLock(HSEM, CFG_HW_ENTRY_STOP_MODE_SEMID)) {
|
||||
|
@ -58,47 +52,50 @@ __weak void pm_power_state_set(struct pm_state_info info)
|
|||
/* The switch on HSI before entering Stop Mode is required */
|
||||
switch_on_hsi();
|
||||
}
|
||||
}
|
||||
|
||||
/* Invoke Low Power/System Off specific Tasks */
|
||||
__weak void pm_power_state_set(struct pm_state_info info)
|
||||
{
|
||||
if (info.state == PM_STATE_SUSPEND_TO_IDLE) {
|
||||
|
||||
lpm_hsem_lock();
|
||||
|
||||
/* ensure HSI is the wake-up system clock */
|
||||
LL_RCC_SetClkAfterWakeFromStop(LL_RCC_STOP_WAKEUPCLOCK_HSI);
|
||||
|
||||
switch (info.substate_id) {
|
||||
case 1: /* this corresponds to the STOP0 mode: */
|
||||
/* ensure HSI is the wake-up system clock */
|
||||
LL_RCC_SetClkAfterWakeFromStop(LL_RCC_STOP_WAKEUPCLOCK_HSI);
|
||||
case 1:
|
||||
/* enter STOP0 mode */
|
||||
LL_PWR_SetPowerMode(LL_PWR_MODE_STOP0);
|
||||
z_stm32_hsem_unlock(CFG_HW_RCC_SEMID);
|
||||
LL_LPM_EnableDeepSleep();
|
||||
/* enter SLEEP mode : WFE or WFI */
|
||||
k_cpu_idle();
|
||||
break;
|
||||
case 2: /* this corresponds to the STOP1 mode: */
|
||||
/* ensure HSI is the wake-up system clock */
|
||||
LL_RCC_SetClkAfterWakeFromStop(LL_RCC_STOP_WAKEUPCLOCK_HSI);
|
||||
case 2:
|
||||
/* enter STOP1 mode */
|
||||
LL_PWR_SetPowerMode(LL_PWR_MODE_STOP1);
|
||||
z_stm32_hsem_unlock(CFG_HW_RCC_SEMID);
|
||||
LL_LPM_EnableDeepSleep();
|
||||
/* enter SLEEP mode : WFE or WFI */
|
||||
k_cpu_idle();
|
||||
break;
|
||||
case 3: /* this corresponds to the STOP2 mode: */
|
||||
/* ensure HSI is the wake-up system clock */
|
||||
LL_RCC_SetClkAfterWakeFromStop(LL_RCC_STOP_WAKEUPCLOCK_HSI);
|
||||
#ifdef PWR_CR1_RRSTP
|
||||
LL_PWR_DisableSRAM3Retention();
|
||||
#endif /* PWR_CR1_RRSTP */
|
||||
case 3:
|
||||
/* enter STOP2 mode */
|
||||
LL_PWR_SetPowerMode(LL_PWR_MODE_STOP2);
|
||||
z_stm32_hsem_unlock(CFG_HW_RCC_SEMID);
|
||||
LL_LPM_EnableDeepSleep();
|
||||
/* enter SLEEP mode : WFE or WFI */
|
||||
k_cpu_idle();
|
||||
break;
|
||||
default:
|
||||
/* Release RCC semaphore */
|
||||
z_stm32_hsem_unlock(CFG_HW_RCC_SEMID);
|
||||
LOG_DBG("Unsupported power substate-id %u", info.substate_id);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
LOG_DBG("Unsupported power state %u", info.state);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Release RCC semaphore */
|
||||
z_stm32_hsem_unlock(CFG_HW_RCC_SEMID);
|
||||
|
||||
LL_LPM_EnableDeepSleep();
|
||||
|
||||
/* enter SLEEP mode : WFE or WFI */
|
||||
k_cpu_idle();
|
||||
}
|
||||
|
||||
/* Handle SOC specific activity after Low Power Mode Exit */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue