2021-05-17 01:19:43 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021 Fabio Baltieri
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-25 15:58:46 +08:00
|
|
|
#include <zephyr/kernel.h>
|
2022-05-06 17:11:04 +08:00
|
|
|
#include <zephyr/pm/pm.h>
|
2021-05-17 01:19:43 +08:00
|
|
|
#include <soc.h>
|
2022-05-06 17:11:04 +08:00
|
|
|
#include <zephyr/init.h>
|
2021-05-17 01:19:43 +08:00
|
|
|
|
|
|
|
#include <stm32l0xx_ll_utils.h>
|
|
|
|
#include <stm32l0xx_ll_bus.h>
|
|
|
|
#include <stm32l0xx_ll_cortex.h>
|
|
|
|
#include <stm32l0xx_ll_pwr.h>
|
|
|
|
#include <stm32l0xx_ll_rcc.h>
|
|
|
|
#include <stm32l0xx_ll_system.h>
|
|
|
|
#include <clock_control/clock_stm32_ll_common.h>
|
2022-05-06 17:11:04 +08:00
|
|
|
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
|
2021-05-17 01:19:43 +08:00
|
|
|
|
2022-05-06 17:11:04 +08:00
|
|
|
#include <zephyr/logging/log.h>
|
2021-05-17 01:19:43 +08:00
|
|
|
LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL);
|
|
|
|
|
|
|
|
/* Select MSI as wake-up system clock if configured, HSI otherwise */
|
|
|
|
#if STM32_SYSCLK_SRC_MSI
|
|
|
|
#define RCC_STOP_WAKEUPCLOCK_SELECTED LL_RCC_STOP_WAKEUPCLOCK_MSI
|
|
|
|
#else
|
|
|
|
#define RCC_STOP_WAKEUPCLOCK_SELECTED LL_RCC_STOP_WAKEUPCLOCK_HSI
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Invoke Low Power/System Off specific Tasks */
|
2023-07-17 23:03:00 +08:00
|
|
|
void pm_state_set(enum pm_state state, uint8_t substate_id)
|
2021-05-17 01:19:43 +08:00
|
|
|
{
|
2022-01-22 01:28:10 +08:00
|
|
|
ARG_UNUSED(substate_id);
|
|
|
|
|
|
|
|
switch (state) {
|
2021-05-17 01:19:43 +08:00
|
|
|
case PM_STATE_SUSPEND_TO_IDLE:
|
|
|
|
LL_RCC_SetClkAfterWakeFromStop(RCC_STOP_WAKEUPCLOCK_SELECTED);
|
|
|
|
LL_PWR_ClearFlag_WU();
|
|
|
|
LL_PWR_SetPowerMode(LL_PWR_MODE_STOP);
|
|
|
|
LL_PWR_SetRegulModeLP(LL_PWR_REGU_LPMODES_LOW_POWER);
|
|
|
|
LL_LPM_EnableDeepSleep();
|
|
|
|
k_cpu_idle();
|
|
|
|
break;
|
|
|
|
default:
|
2022-01-22 01:28:10 +08:00
|
|
|
LOG_DBG("Unsupported power state %u", state);
|
2021-05-17 01:19:43 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle SOC specific activity after Low Power Mode Exit */
|
2023-07-17 23:03:00 +08:00
|
|
|
void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
|
2021-05-17 01:19:43 +08:00
|
|
|
{
|
2022-01-22 01:28:10 +08:00
|
|
|
ARG_UNUSED(substate_id);
|
|
|
|
|
|
|
|
switch (state) {
|
2021-05-17 01:19:43 +08:00
|
|
|
case PM_STATE_SUSPEND_TO_IDLE:
|
|
|
|
LL_LPM_DisableSleepOnExit();
|
|
|
|
LL_LPM_EnableSleep();
|
2022-01-24 17:26:14 +08:00
|
|
|
LL_PWR_SetRegulModeLP(LL_PWR_REGU_LPMODES_MAIN);
|
2021-05-17 01:19:43 +08:00
|
|
|
|
|
|
|
/* Restore the clock setup. */
|
|
|
|
stm32_clock_control_init(NULL);
|
|
|
|
break;
|
|
|
|
default:
|
2022-01-22 01:28:10 +08:00
|
|
|
LOG_DBG("Unsupported power substate-id %u", state);
|
2021-05-17 01:19:43 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* System is now in active mode. Reenable interrupts which were
|
|
|
|
* disabled when OS started idling code.
|
|
|
|
*/
|
|
|
|
irq_unlock(0);
|
|
|
|
}
|