征程 6 | power management sample
本文通過示例演示如何通過相關接口對啟動標志進行讀寫,以及對 main 域電源進行控制與查詢。相關 API 定義,請查詢 電源管理用戶手冊 API 部分 。
2. main 域上下電及狀態查詢示例代碼請參考版本中 Service/Cmd_Utility/power_sample_cmd/src/PowerControl.c 相關代碼:
// PowerControl.c代碼 #include "Os.h" #include "Log.h" #include "Pmu.h" #include "Boot.h" #include "Shell_Port.h" // main域電源狀態定義 #define MAINDOMAIN_STATUS_UNINIT (0U) #define MAINDOMAIN_STATUS_RUNNING (1U)
注意
注意以下章節中的截圖,在不同的版本上可能會有一些差異,只要關鍵信息部分一致即可。 請結合其中提到的驗證方法做進一步確認。
2.1. MCU 對 Acore 進行上下電接口及命令說明// 需要包含的頭文件 #include "Power_Manager_Cust.h" // 通知Acore進行下電 hb_PM_RequestSt(MAINSTATE_OFF_ST); // 對Acore進行強制下電 hb_PM_RequestSt(MAINSTATE_FORCE_OFF_IT); // 對Acore進行上電
地平線版本中可使用如下命令:
testmainpower 0 # 通知Acore下電,同時會做bootflag和power狀態查詢 testmainpower forceoff # 對Acore強制下電 testmainpower 1 # 對Acore上電,同時會做bootflag和power狀態查詢
效果確認:
當對 Acore 進行下電,MCU 會有如下打印:
此時 MCU 正常,Acore 因為下電串口無法交互;
當對 Acore 進行強制下電,MCU 會有如下打印:
此時 MCU 正常,Acore 因為下電串口無法交互;
當對 Acore 進行上電,MCU 會有很長的打印,MCU 走完相關流程后,會有如下關鍵打印:
同時 Acore 會進入 kernel:
并可以正常進行命令行交互;
2.2. MCU 讀寫 bootflag 接口及命令說明// 需要包含的頭文件 #include "Boot.h" // 設置bootflag Std_ReturnType Bl_MainDomainBootFlagSet(uint32 Flag); // 獲取bootflag Std_ReturnType Bl_MainDomainBootFlagGet(uint32 *Flag);
地平線版本中可使用如下命令:
testmainpower 0 # 對Acore下電,同時會做bootflag和power狀態查詢 testmainpower 1 # 對Acore上電,同時會做bootflag和power狀態查詢
效果確認:
示例代碼中會嘗試對 bootflag 進行讀取/修改/恢復的流程;后邊的數值代表對應 boot 標志,可以查詢相關頭文件。
2.3. MCU 獲取 Acore power 狀態接口及命令說明?// 需要包含的頭文件 #include "Pmu.h" // 獲取main power狀態 Std_ReturnType Pmu_MainDomainStatusGet(uint32 *Status);
地平線版本中可使用如下命令:
getmainstatus # main power狀態查詢
效果確認:
示例代碼中嘗試去獲取狀態并打印出對應通過函數獲取到的 Acore power 狀態。
3. main 域 reset 示例調用如下接口后,如果有接 Acore 串口,可以看到 Acore 串口有重啟并再次正常進入 kernel,并且 Acore 的命令行可以進行正常交互。
3.1. main 域 reset 接口說明// 需要包含的頭文件 #include "Power_Manager_Cust.h" hb_PM_RequestSt(MAINSTATE_RESET_IT);4. 征程 6X 全部下電示例
調用對應接口,MCU 和 Acore 都下電,兩者的命令行都無法進行交互。要想重新啟動,需要斷電重啟。
4.1. 全部下電接口說明// 需要包含的頭文件 #include "Power_Manager_Cust.h" hb_PM_RequestSt(SYSSTATE_SHUTDOWN_ST);5. 不同場景休眠喚醒示例代碼
請參考版本中 Service/Cmd_Utility/power_sample_cmd/src/PowerControl.c 相關代碼,目前主要實現以下六個場景:
horizon:/$ powersample
[0512.790449 0]powersample {index:d} rtc_time:d>
[0512.790824 0] index: 0: main suspend + mcu suspend + rtc wakeup + shutdown
[0512.791703 0] 1: main off + mcu suspend + rtc wakeup + shutdown
[0512.792538 0] 2: main suspend + mcu suspend + can wakeup + resume
[0512.793395 0] 3: main off + mcu suspend + can wakeup + poweron
[0512.794337 0] 4: main suspend + mcu suspend + rtc wakeup + resume
[0512.795077 0] 5: main off + mcu suspend + rtc wakeup + poweron注意:各 sample 場景為都是單獨流程,不要混合使用。如果在執行完一個 sample 場景后,需要更換場景測試,需要先進行整機下電,再重新上電。
場景拆分為以下幾種流程:
流程 1: main off + mcu suspend:
流程 2:main suspend + mcu suspend:
流程 3:mcu on + main on:
流程 4:mcu on + main resume:
流程 5:rtc wakeup + shutdown:
在 rtc 喚醒場景中 - 如果需要 rtc 喚醒后直接關機,需要外部 kl15 信號源為低電平,否則會導致喚醒后一級電源無法正常下電
5.1. sample0//sample0: main suspend + mcu suspend + rtc wakeup + shutdown
// 設置rtc喚醒時間
Ret = SysPower_RtcWakeupSet(RtcWakeupTime);
if (Ret != E_OK)
{
LogNotice("set rtc wakeup failed with %d\r\n", Ret);
return -1;
}5.2. sample1//main off + mcu suspend + rtc wakeup + shutdown
/** acore scmi just control acore */
scmi_reset_mode = 1;
// 通知acore進入下電
Ret = hb_PM_RequestSt(MAINSTATE_OFF_ST);
if (Ret != E_OK)
{
LogNotice("notify shutdown failed with %d\r\n", Ret);5.3. sample2//main suspend + mcu suspend + can wakeup + resume
//設置一個較大的rtc喚醒時間,以防止rtc誤喚醒
Ret = SysPower_RtcWakeupSet(8388);
if (E_OK != Ret)
{
LogNotice("SysPower_RtcWakeupSet failed with %d.\r\n", Ret);
return -1;
}
//TJA1145進入低功耗模式相關配置
Ret = TJA1145_EnterLowPowerMode(1);5.4. sample3//3: main off + mcu suspend + can wakeup + poweron
/** acore scmi just control acore */
scmi_reset_mode = 1;
// 通知acore進入下電
Ret = hb_PM_RequestSt(MAINSTATE_OFF_ST);
if (Ret != E_OK)
{
LogNotice("notify shutdown failed with %d\r\n", Ret);
return -1;5.5. sample4//main suspend + mcu suspend + rtc wakeup + resume
//設置一個rtc喚醒時間
Ret = SysPower_RtcWakeupSet(RtcWakeupTime);
if (Ret != E_OK)
{
LogNotice("set rtc wakeup failed with %d\r\n", Ret);
return -1;
}
// 通知acore開始休眠流程
Ret = hb_PM_RequestSt(MAINSTATE_SLEEP_ST);5.6. sample5//main off + mcu suspend + rtc wakeup + poweron
/** acore scmi just control acore */
scmi_reset_mode = 1;
// 通知acore進入下電
Ret = hb_PM_RequestSt(MAINSTATE_OFF_ST);
if (Ret != E_OK)
{
LogNotice("notify shutdown failed with %d\r\n", Ret);
return -1;*博客內容為網友個人發布,僅代表博主個人觀點,如有侵權請聯系工作人員刪除。






