openharmony之充电空闲状态定制开发

概述

简介

OpenHarmony系统默认集成充电空闲状态检测功能。该功能通过综合评估设备热等级、电池电量、充电状态及充电电流等参数,判断设备是否满足空闲状态条件,从而触发后台任务执行。由于不同设备的硬件特性存在差异,各产品需根据实际设计需求进行定制化配置。

本指导文档以DAYU200开发套件为例,详细说明定制开发流程,开发者可根据具体产品需求调整实现方案。

关于电源管理模块学习欢迎订阅专栏文章《openharmony之电源管理模块需求定制总结》

约束与限制

  • 配置文件存储路径需遵循产品配置策略,示例中采用/vendor路径,实际开发中应根据项目规范调整
  • 热等级阈值需结合设备散热能力设定,建议通过温控测试确定合理范围
  • 电池参数配置应符合电池安全规范,避免设置超出硬件规格的电流阈值

开发流程

开发环境要求

  • 硬件平台:DAYU200/Hi3516DV300等标准系统开发板
  • 开发环境:基于Linux的编译环境

定制开发步骤

1. 创建配置目录

在产品专属目录下创建温控配置目录:

bash 复制代码
mkdir -p /vendor/hihope/rk3568/thermal
2. 配置文件准备

从默认配置目录获取模板文件:

bash 复制代码
cp -r /services/native/profile/thermal_service_config.xml /vendor/hihope/rk3568/thermal/
3. 配置参数说明

XML配置文件包含以下关键参数:

参数项 数据类型 取值范围 配置说明
thermallevel int 0-7 设备热等级阈值,当当前热等级≤该值时进入空闲状态
soc int 0-100 电池电量阈值,当电量≥该值时进入空闲状态
charging int 0/1 充电状态标识,1表示正在充电
current int ≥0(单位:mA) 充电电流阈值,当实际电流≥该值时进入空闲状态

打包路径:/vendor/etc/thermal_config/hdf

示例配置:

xml 复制代码
<idle name="charging">
    <thermallevel>1</thermallevel>  <!-- 热等级≤1 -->
    <soc>90</soc>                   <!-- 电量≥90% -->
    <charging>1</charging>          <!-- 正在充电 -->
    <current>1000</current>         <!-- 电流≥1000mA -->
</idle>
4. 构建配置文件

创建BUILD.gn构建配置:

gn 复制代码
import("//build/ohos.gni")

ohos_prebuilt_etc("thermal_service_config") {
    source = "thermal_service_config.xml"
    relative_install_dir = "thermal_config"
    install_images = [ chipset_base_dir ]
    part_name = "product_rk3568"
}
5. 集成编译配置

在ohos.build中添加编译模块:

json 复制代码
{
    "parts": {
        "product_rk3568": {
            "module_list": [
                ...
                "//vendor/hihope/rk3568/thermal/profile:thermal_service_config"
            ]
        }
    },
    "subsystem": "product_hihope"
}
6. 编译与烧录

执行编译命令:

bash 复制代码
./build.sh --product-name rk3568 --ccache

将生成的固件烧录至开发板完成部署。

调测验证

状态检测方法

  1. 通过HDC工具进入设备shell:

    bash 复制代码
    hdc shell
  2. 执行状态查询命令:

    bash 复制代码
    hidumper -s 3303 -a -i

预期输出示例

复制代码
-------------------------------[ability]-------------------------------
----------------------------------ThermalService---------------------------------
thermallevel: 1
soc: 90
charging: 1
current: 1000

参考资源

  • 默认配置文件路径:/services/native/profile/thermal_service_config.xml
  • 系统配置文档:/resources/base/etc/thermal_config/thermal_service_config.xml
  • 温控服务源码:/services/native/thermal/thermal_service.cpp

注意:实际开发中应结合设备硬件规格进行参数优化,建议通过温升测试验证配置有效性。电流阈值设置应留有安全余量,避免触发过流保护。

附录:完整配置文件示例

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright (c) 2022-2023 Huawei Device Co., Ltd.
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<thermal version="0.01" product="lya">
    <base>
        <item tag="history_temp_count" value="10"/>
        <item tag="temperature_query_enum" value="soc,battery,shell,cpu,charger,ambient,ap,pa"/>
        <item tag="sim_tz" value="1"/>
    </base>

    <level>
        <sensor_cluster name="screenoff_charge" sensor="battery">
            <state screen="0" charge="1"/>
            <item level="1" threshold="40000" threshold_clr="38000"/>
            <item level="2" threshold="43000" threshold_clr="41000"/>
        </sensor_cluster>
        <sensor_cluster name="base_safe" sensor="battery,charger,cpu,soc">
            <item level="1" threshold="40000,38000,30000,40000" threshold_clr="38000,36000,28000,38000"/>
            <item level="2" threshold="43000,41000,32000,42000" threshold_clr="41000,39000,30000,40000"/>
            <item level="3" threshold="46000,44000,34000,44000" threshold_clr="44000,42000,32000,42000"/>
            <item level="4" threshold="48000,46000,36000,46000" threshold_clr="46000,44000,34000,44000"/>
        </sensor_cluster>
        <sensor_cluster name="warm_5G" sensor="pa" aux_sensor="ambient">
            <item level="1" threshold="40000" threshold_clr="38000" aux_trigger_range="5000_35000"/>
            <item level="2" threshold="43000" threshold_clr="41000" aux_trigger_range="5000_35000"/>
            <item level="3" threshold="45000" threshold_clr="44000" aux_trigger_range="5000_35000"/>
        </sensor_cluster>
        <sensor_cluster name="warm_safe" sensor="ap,soc" aux_sensor="ambient,shell">
            <item level="1" threshold="75000,30000" threshold_clr="71000,28000" aux_trigger_range="0_900000,0_40000"/>
        </sensor_cluster>
        <sensor_cluster name="high_safe" sensor="shell">
            <item level="1" threshold="40000" threshold_clr="38000" temp_rise_rate="1.5"/>
            <item level="2" threshold="43000" threshold_clr="41000" temp_rise_rate="1.5"/>
            <item level="3" threshold="46000" threshold_clr="44000" temp_rise_rate="1.5"/>
            <item level="4" threshold="48000" threshold_clr="47000" temp_rise_rate="1.5"/>
        </sensor_cluster>
        <sensor_cluster name="cold_safe" sensor="battery,soc" desc="1">
            <item level="1" threshold="-9000,-8000" threshold_clr="-6000,-5000"/>
            <item level="2" threshold="-14000,-13000" threshold_clr="-11000,-10000"/>
            <item level="3" threshold="-19000,-18000" threshold_clr="-16000,-15000"/>
            <item level="4" threshold="-21000,-20000" threshold_clr="-20000,-19000"/>
        </sensor_cluster>
    </level>

    <state>
        <item name="scene" param="cam,call,game,test"/>
        <item name="screen"/>
        <item name="charge"/>
    </state>

    <action>
        <item name="airplane"/>
        <item name="cpu_big"/>
        <item name="cpu_med"/>
        <item name="cpu_lit"/>
        <item name="gpu"/>
        <item name="boost" event="1"/>
        <item name="isolate" event="1"/>
        <item name="lcd"/>
        <item name="volume" uid="2001,2002"/>
        <item name="current_sc" protocol="current" param="sc" event="1"/>
        <item name="current_buck" protocol="current" param="buck" event="1"/>
        <item name="voltage_sc" protocol="voltage" param="sc" event="1"/>
        <item name="voltage_buck" protocol="voltage" param="buck" event="1"/>
        <item name="process_ctrl" param="32,64,128,256" event=""/>
        <item name="shut_down" event="0"/>
        <item name="thermallevel" event="1"/>
        <item name="popup"/>
        <item name="test"/>
    </action>

    <policy>
        <config name="base_safe" level="1">
            <airplane>0</airplane>
            <lcd>1.00</lcd>
            <lcd scene="cam">0.99</lcd>
            <lcd scene="call">0.98</lcd>
            <lcd scene="game">0.97</lcd>
            <lcd scene="test">0.91</lcd>
            <cpu_big>1992000</cpu_big>
            <cpu_med>1991500</cpu_med>
            <cpu_lit>1991200</cpu_lit>
            <test>99999</test>
            <process_ctrl>3</process_ctrl>
            <cpu_big scene="cam" charge="1">1991800</cpu_big>
            <cpu_big scene="cam" charge="0">1991600</cpu_big>
            <gpu screen="0">524288</gpu>
            <gpu screen="1">512000</gpu>
            <thermallevel>1</thermallevel>
            <current_sc>1800</current_sc>
            <current_sc scene="cam">1200</current_sc>
            <current_buck>1200</current_buck>
            <voltage_sc>4000</voltage_sc>
            <voltage_buck>3000</voltage_buck>
            <volume>1.0</volume>
            <boost>1</boost>
            <isolate>0</isolate>
        </config>
        <config name="base_safe" level="2">
            <airplane>1</airplane>
            <lcd>0.90</lcd>
            <lcd scene="cam">0.89</lcd>
            <lcd scene="call">0.88</lcd>
            <lcd scene="game">0.87</lcd>
            <cpu_big>1991000</cpu_big>
            <cpu_med>1990500</cpu_med>
            <cpu_lit>1990200</cpu_lit>
            <process_ctrl>2</process_ctrl>
            <cpu_big scene="cam" charge="1">1990800</cpu_big>
            <cpu_big scene="cam" charge="0">1990600</cpu_big>
            <gpu screen="0">499712</gpu>
            <gpu screen="1">487424</gpu>
            <thermallevel>2</thermallevel>
            <current_sc>1500</current_sc>
            <current_sc scene="cam">1000</current_sc>
            <current_buck>1000</current_buck>
            <voltage_sc>3000</voltage_sc>
            <voltage_buck>2000</voltage_buck>
            <volume>0.8</volume>
            <boost>1</boost>
            <isolate>1</isolate>
        </config>
        <config name="base_safe" level="3">
            <lcd>0.80</lcd>
            <lcd scene="cam">0.79</lcd>
            <lcd scene="call">0.78</lcd>
            <lcd scene="game">0.77</lcd>
            <cpu_big>1990000</cpu_big>
            <cpu_med>1989500</cpu_med>
            <cpu_lit>1989200</cpu_lit>
            <process_ctrl>1</process_ctrl>
            <cpu_big scene="cam" charge="1">1989800</cpu_big>
            <cpu_big scene="cam" charge="0">1989600</cpu_big>
            <gpu screen="0">475136</gpu>
            <gpu screen="1">462848</gpu>
            <thermallevel>3</thermallevel>
            <current_sc>1300</current_sc>
            <current_sc scene="cam">800</current_sc>
            <current_buck>800</current_buck>
            <voltage_sc>2000</voltage_sc>
            <voltage_buck>1000</voltage_buck>
            <volume>0.7</volume>
            <shut_down>1</shut_down>
            <boost>0</boost>
            <isolate>2</isolate>
        </config>
        <config name="warm_5G" level="1">
            <lcd>0.70</lcd>
            <thermallevel>4</thermallevel>
            <process_ctrl>2</process_ctrl>
        </config>
        <config name="warm_5G" level="2">
            <lcd>0.60</lcd>
            <process_ctrl>3</process_ctrl>
            <thermallevel>5</thermallevel>
        </config>
        <config name="warm_5G" level="3">
            <thermallevel>7</thermallevel>
        </config>
        <config name="warm_safe" level="1">
            <process_ctrl screen="1">3</process_ctrl>
            <shut_down screen="1">1</shut_down>
            <thermallevel>6</thermallevel>
        </config>
        <config name="cold_safe" level="1">
            <current_sc>1850</current_sc>
            <thermallevel>0</thermallevel>
        </config>
        <config name="cold_safe" level="2">
            <current_sc>1550</current_sc>
            <thermallevel>0</thermallevel>
        </config>
        <config name="cold_safe" level="3">
            <current_sc>1150</current_sc>
            <thermallevel>0</thermallevel>
        </config>
    </policy>

    <fan>
        <sensor_cluster name="fan_fault_detect" sensor="soc,gpu,fan">
            <item fault="1" threshold="50000,50000,500"/>
            <item fault="2" threshold="30000,30000,1500"/>
        </sensor_cluster>
    </fan>

    <idle name="charging">
        <thermallevel>1</thermallevel>  <!-- thermal level is equal or less than 1 -->
        <soc>80</soc> <!-- battery soc is equal or more than 80% -->
        <charging>1</charging> <!-- battery is charging -->
        <current>1000</current> <!-- battery charging current is equal or more than 1000mA -->
    </idle>
</thermal>
相关推荐
爱写Bug的浮游1 天前
初识仓颉:5 分钟看懂核心语法
harmonyos·编程语言
程序猿追2 天前
鸿蒙 PC 的 Ionic 工单有两个错误,按下生成后光标该去哪儿
华为·harmonyos
KevinChaos2 天前
随手备忘录手记 04|HarmonyOS 7.0新特性实验:物品图鉴的加载逻辑
华为·harmonyos
Sirius_Ji2 天前
从硬解基座到字幕与滤镜链:ffmpeg-for-HarmonyOS v0.3.2
harmonyos
用户86194177207413 天前
uni-app 鸿蒙端提现点不动?我用 UTS 插件补上了微信"确认收款"
微信·harmonyos
码间留白3 天前
uni-app 鸿蒙端提现点不动?我用 UTS 插件补上了微信"确认收款"
uni-app·harmonyos·鸿蒙·uts插件·微信商家转账
GitCode官方3 天前
开源鸿蒙跨平台直播|AI 时代,用 cj-tauri 开发鸿蒙 PC 应用
人工智能·华为·harmonyos·atomgit
程序猿追3 天前
鸿蒙 PC 用 Tauri 做本地查找,怎样让慢请求给新请求让路
华为·状态模式·harmonyos
程序猿追3 天前
鸿蒙 PC 用 Ionic 做巡检目录,缩窄窗口后草稿还在吗
华为·harmonyos
jianqiang.xue3 天前
1颗NPU分时复用:鸿蒙把轻AI塞进了MCU
人工智能·单片机·mcu·嵌入式·harmonyos·鸿蒙·端侧ai