1# 热等级定制开发指导 2 3## 概述 4 5### 简介 6 7OpenHarmony默认提供了热等级的特性。不同的硬件设备发热量和所能承受的最大温度都不相同,因此需要根据不同器件的温度,来定义系统的热等级标准,从而清晰的表明当前设备的发热状态,给热策略提供输入。但是器件在不同温度下对应的热等级在不同的产品上规格是不同的,产品希望根据产品的设计规格来定制此特性。OpenHarmony提供了热等级的定制方式,产品定制开发者可根据产品的设计规格来定制这些特性。 8 9### 约束与限制 10 11产品定制的配置路径,需要根据[配置策略](https://gitee.com/openharmony/customization_config_policy)决定。本开发指导中的定制路径以`/vendor`进行举例,请开发者根据具体的产品配置策略,修改定制路径。 12 13## 开发指导 14 15### 搭建环境 16 17设备要求: 18 19标准系统开发板,如DAYU200/Hi3516DV300开源套件。 20 21环境要求: 22 23Linux调测环境,相关要求和配置可参考《[快速入门](../quick-start/quickstart-overview.md)》。 24 25### 开发步骤 26 27本文以[DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568)为例介绍热等级的定制方法。 28 291. 在产品目录[(/vendor/hihope/rk3568)](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568)下创建thermal文件夹。 30 312. 参考[默认热等级的配置文件夹](https://gitee.com/openharmony/powermgr_thermal_manager/tree/master/services/native/profile)创建目标文件夹,并安装到`//vendor/hihope/rk3568/thermal`,文件格式如下: 32 33 ```text 34 profile 35 ├── BUILD.gn 36 ├── thermal_service_config.xml 37 ``` 38 393. 参考[默认热等级的配置文件夹中的thermal_service_config.xml](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml)编写定制的thermal_service_config.xml。包含热等级配置说明及定制后的热等级配置如下: 40 41 **表1** base配置说明 42 | 配置项 | 配置项描述 | 配置项参数 | 配置项参数描述 | 参数类型 | 参数取值范围 | 43 | -------- | -------- | -------- | -------- | -------- | -------- | 44 | tag="history_temp_count" | 历史上报温度次数标签的名称 | value | 历史上报温度次数 | int | >0 | 45 | tag="temperature_query_enum" | 获取温度的设备列表的标签名称 | value | 要获取温度的设备列表 | enum | soc,battery,shell,cpu,charger,ambient,ap,pa | 46 47 48 **表2** sensor_cluster配置说明 49 50 | 配置项名称 | 配置项描述 | 数据类型 | 取值范围 | 51 | -------- | -------- | -------- | -------- | 52 | name | 传感器集合名称 | string | 无 | 53 | sensor | 集合内的传感器 | string | soc,battery,shell,cpu,charger,ambient,ap,pa | 54 | aux_sensor | 集合内的辅助传感器 | string | soc,battery,shell,cpu,charger,ambient,ap,pa | 55 56 **表3** item配置说明 57 58 | 配置项名称 | 配置项描述 | 数据类型 | 取值范围 | 59 | -------- | -------- | -------- | -------- | 60 | level | 各传感器集合下定义的热等级 | int | >0 | 61 | threshold | 集合内每个传感器达到对应热等级的温度阈值(默认单位0.001摄氏度,开发者可定制) | int | 根据产品定制 | 62 | threshold_clr | 集合内每个传感器回退到上一热等级的温度阈值 | int | 根据产品定制 | 63 | temp_rise_rate | 温度升高频率 | double | 根据产品定制 | 64 65 ```shell 66 <thermal version="0.01" product="lya"> 67 <base> 68 <item tag="history_temp_count" value="10"/> 69 <item tag="temperature_query_enum" value="soc,battery,shell,cpu,charger,ambient,ap,pa"/> 70 </base> 71 72 <level> 73 <sensor_cluster name="base_safe" sensor="battery,charger,cpu,soc"> 74 <item level="1" threshold="42000,40000,30000,40000" threshold_clr="38000,36000,28000,38000"/> 75 <item level="2" threshold="43000,41000,32000,42000" threshold_clr="41000,39000,30000,40000"/> 76 <item level="3" threshold="46000,44000,34000,44000" threshold_clr="44000,42000,32000,42000"/> 77 <item level="4" threshold="48000,46000,36000,46000" threshold_clr="46000,44000,34000,44000"/> 78 </sensor_cluster> 79 </level> 80 ``` 81 824. 参考[默认热等级配置文件夹中的BUILD.gn](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/BUILD.gn)编写BUILD.gn文件,将thermal_service_config.xml打包到`/vendor/etc/thermal_config`目录下 83 84 ```shell 85 import("//build/ohos.gni") # 引用build/ohos.gni 86 87 ohos_prebuilt_etc("thermal_service_config") { 88 source = "thermal_service_config.xml" 89 relative_install_dir = "thermal_config" 90 install_images = [ chipset_base_dir ] # 安装到vendor目录下的必要配置 91 part_name = "product_rk3568" # part_name暂定为product_rk3568,以实现后续编译,产品定制根据需要自行修改 92 } 93 ``` 94 955. 将编译目标添加到[ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build)的"module_list"中,例如: 96 97 ```json 98 { 99 "parts": { 100 "product_rk3568": { 101 "module_list": [ 102 "//vendor/hihope/rk3568/default_app_config:default_app_config", 103 "//vendor/hihope/rk3568/image_conf:custom_image_conf", 104 "//vendor/hihope/rk3568/preinstall-config:preinstall-config", 105 "//vendor/hihope/rk3568/resourceschedule:resourceschedule", 106 "//vendor/hihope/rk3568/etc:product_etc_conf", 107 "//vendor/hihope/rk3568/thermal/profile:thermal_service_config", // 添加thermal_service_config的编译 108 ] 109 } 110 }, 111 "subsystem": "product_hihope" 112 } 113 ``` 114 “//vendor/hihope/rk3568/thermal/”为文件夹路径,“profile”为创建的文件夹名字,“thermal_service_config”为编译目标。 115 1166. 参考《[快速入门](../quick-start/quickstart-overview.md)》编译定制版本,编译命令如下: 117 118 ```shell 119 ./build.sh --product-name rk3568 --ccache 120 ``` 121 1227. 将定制版本烧录到DAYU200开发板中。 123 124### 调测验证 125 1261. 开机后,进入shell命令行: 127 ```shell 128 hdc shell 129 ``` 130 1312. 进入`data/service/el0/thermal/sensor/soc/`路径: 132 ```shell 133 cd data/service/el0/thermal/sensor/soc 134 ``` 135 1363. 修改soc的温度: 137 ```shell 138 echo 42000 > temp 139 ``` 140 1414. 获取当前热等级信息: 142 ```shell 143 hidumper -s 3303 -a -l 144 ``` 145 146 成功获取热等级信息如下: 147 ```shell 148 -------------------------------[ability]------------------------------- 149 150 151 ----------------------------------ThermalService--------------------------------- 152 name: base_safe level: 2 153 name: cold_safe level: 0 154 name: high_safe level: 0 155 name: warm_5G level: 0 156 name: warm_safe level: 1 157 ``` 158 159## 参考 160开发过程中可参考的配置文件路径:[默认热等级源码路径](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml) 161 162打包路径:`/vendor/etc/thermal_config/hdf` 163 164