当前文档版本为 v0.4.0,您可以访问当前页面的 开发中 版本以获取最近可能的更新。

Driver: Power Management

1 功能概述

本文主要介绍PAN1080 EVB板PM中进入低功耗前后的回调函数使用说明。

2 环境要求

  • board: pan1080a_afld_evb

  • uart (option): 显示串口log

3 编译和烧录

项目位置:zephyr\samples_panchip\drivers\pm

目前可使用ZAL工具或quick build脚本进行编译和下载。

脚本位置:quick_build_samples\drivers\pm.bat

打开脚本后默认会编译项目,编译完成时,可输入字符进行后续下载等操作:

Input the keyword to continue:
  'b' build                         编译项目
  'r' make clean and rebuild        重新编译项目
  'f' flash download                下载
  'e' erase chip                    擦除芯片
  'o' open project by VS Code       打开 `VS Code`,可查看源码,执行编译下载等
  others exit                       退出
wait input:

4 演示说明

*** Booting Zephyr OS build zephyr-v2.7.0-413-g0af245658bdf  ***
pm entry
pm exit
Wake up from runtime-idle
pm entry
pm exit
Wake up from suspend-to-idle
pm entry
pm exit
Wake up from runtime-idle
pm entry
pm exit
Wake up from suspend-to-idle
pm entry
pm exit
Wake up from runtime-idle
pm entry

上电后打印如上数据,该sample未和蓝牙deepsleep功能绑定,暂时只用于pm_notifier_register演示,只会进入MCU Sleep模式。

5 开发者说明

进入低功耗的时机

&cpu0 {
	cpu-power-states = <&state1>;
};

&state1 {
	compatible = "zephyr,power-state";
	power-state-name = "suspend-to-idle";
	min-residency-us = <6000>;
	exit-latency-us = <32>;
};

以该参数来说明:

cpu0只有一种低功耗状态,为state1:suspend-to-idle

如果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(&notifier);

/** 撤销注册低功耗回调函数*/
pm_notifier_unregister(&notifier);