Driver: Power Management¶
1 功能概述¶
本文主要介绍PAN1080 EVB板PM中进入低功耗前后的回调函数使用说明。
2 环境要求¶
PAN1080 EVB 一块
USB-TypeC 线一条(用于供电和查看串口打印 Log)
硬件接线:
使用 USB 线,将 PC USB 与 EVB USB-TypeC(USB->UART)相连
使用杜邦线将 EVB 上的:
TX0 与 P00 相连
RX0 与 P01 相连
PC 软件: 串口调试助手(UartAssist)或终端工具(SecureCRT),波特率921600
3 编译和烧录¶
例程位置:zephyr\samples_panchip\drivers\pm
使用 ZAL 工具可以对其进行编译、烧录、打开 VS Code 调试等操作。关于 ZAL 工具的详细介绍请参考:Zephyr APP Launcher 工具介绍。
4 演示说明¶
*** Booting Zephyr OS build zephyr-v2.7.0-667-gae423d90e384 ***
Remained loop count: 1
Wake up from cpu idle
pm entry hook, state=1
pm exit hook, state=1
Wake up from runtime-idle
pm entry hook, state=2
pm exit hook, state=2
Wake up from suspend-to-idle
Remained loop count: 0
Wake up from cpu idle
pm entry hook, state=1
pm exit hook, state=1
Wake up from runtime-idle
pm entry hook, state=2
pm exit hook, state=2
Wake up from suspend-to-idle
Expect wake up from suspend-to-ram retention:0
pm entry hook, state=4
*** Booting Zephyr OS build zephyr-v2.7.0-667-gae423d90e384 ***
Remained loop count: 1
Wake up from cpu idle
pm entry hook, state=1
pm exit hook, state=1
Wake up from runtime-idle
pm entry hook, state=2
pm exit hook, state=2
Wake up from suspend-to-idle
Remained loop count: 0
Wake up from cpu idle
pm entry hook, state=1
pm exit hook, state=1
Wake up from runtime-idle
pm entry hook, state=2
pm exit hook, state=2
Wake up from suspend-to-idle
Expected wake up from soft-off retention:1
pm entry hook, state=6
上电后打印如上数据,该sample未和蓝牙deepsleep功能绑定,暂时只用于pm_notifier_register演示,会进入MCU Sleep,deepsleep,standby mode1,standby mode0模式。
standby mode会使SOC复位,其中mode1模式会保持ram数据不掉电,因此通过ram_retention_flag
来区分standby 模式。
该例程依次运行run mode–>deepsleep mode–>standby mode1–>reset–>run mode–>deepsleep mode–>standby mode0
5 开发者说明¶
进入低功耗的时机¶
&cpu0 {
cpu-power-states = <&state0 &state1 &state2 &state3>;
};
&state0 {
compatible = "zephyr,power-state";
power-state-name = "runtime-idle";
min-residency-us = <200000>;
exit-latency-us = <32>;
};
&state1 {
compatible = "zephyr,power-state";
power-state-name = "suspend-to-idle";
min-residency-us = <500000>;
exit-latency-us = <32>;
};
&state2 {
compatible = "zephyr,power-state";
power-state-name = "suspend-to-ram";
min-residency-us = <800000>;
exit-latency-us = <32>;
};
&state3 {
compatible = "zephyr,power-state";
power-state-name = "soft-off";
min-residency-us = <1500000>;
exit-latency-us = <32>;
};
以该参数来说明:
cpu0有四种低功耗状态,分别为
state0:
runtime-idle
(run mode)state1:
suspend-to-idle
(deepsleep mode)state2:
suspend-to-ram
(standby mode1)state3:
soft-off
(standby mode0)
如果idle时间满足以下条件:
if (time_to_next_scheduled_event >= (state.min_residency_us + state.exit_latency))) {
return state
}
则进入相应的state。
进入低功耗前后的回调函数¶
static void notify_pm_state_entry(enum pm_state state)
{
printk("pm entry\n");
}
static void notify_pm_state_exit(enum pm_state state)
{
printk("pm exit\n");
}
static struct pm_notifier notifier = {
.state_entry = notify_pm_state_entry, //进入低功耗前的回调函数
.state_exit = notify_pm_state_exit, //从低功耗出来后的回调函数
};
/** 注册低功耗回调函数*/
pm_notifier_register(¬ifier);
/** 撤销注册低功耗回调函数*/
pm_notifier_unregister(¬ifier);
6 RAM/Flash资源使用情况¶
Memory region Used Size Region Size %age Used
FLASH: 19132 B 1020 KB 1.83%
SRAM: 4904 B 64 KB 7.48%
IDT_LIST: 0 GB 2 KB 0.00%