1# Thermal Level Customization
2
3## Overview
4
5### Introduction
6
7By default, OpenHarmony provides the thermal level feature. Different hardware devices generate different amounts of heat and can tolerate different maximum temperatures. Therefore, for different components, the thermal level standard needs to be defined based on their temperatures to clearly indicate the thermal status and provide input for thermal control. However, the thermal level of components at different temperatures varies according to product specifications. To address this issue, OpenHarmony provides the thermal level customization function.
8
9### Constraints
10
11The configuration path for battery level customization is subject to the [configuration policy](https://gitee.com/openharmony/customization_config_policy). In this development guide, `/vendor` is used as an example of the configuration path. During actual development, you need to modify the customization path based on the product configuration policy.
12
13## How to Develop
14
15### Setting Up the Environment
16
17**Hardware requirements:**
18
19Development board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.
20
21**Environment requirements:**
22
23For details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md).
24
25### Getting Started with Development
26
27The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate thermal level customization.
28
291. Create the `thermal` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568).
30
312. Create a target folder by referring to the [default thermal level configuration folder](https://gitee.com/openharmony/powermgr_thermal_manager/tree/master/services/native/profile), and install it in `//vendor/hihope/rk3568/thermal`. The content is as follows:
32
33    ```text
34    profile
35    ├── BUILD.gn
36    ├── thermal_service_config.xml
37    ```
38
393. Write the custom `thermal_service_config.xml` file by referring to the [thermal_service_config.xml](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml) file in the default thermal level configuration folder. The following tables describe the related configuration items.
40
41    **Table 1** Description of the base configuration
42    | Configuration Item| Description| Parameter| Parameter Description| Type| Value Range|
43    | -------- | -------- | -------- | -------- | -------- | -------- |
44    | tag="history_temp_count" | Name of the tag indicating the number of historical temperature reporting times.| value | Number of historical temperature reporting times.| int | >0 |
45    | tag="temperature_query_enum" | Tag name of the device list for obtaining the temperature.| value | Device list for obtaining the temperature.| enum | soc, battery, shell, cpu, charger, ambient, ap, and pa|
46
47
48    **Table 2** Description of the sensor_cluster configuration
49
50    | Configuration Item | Description | Data Type | Value Range |
51    | -------- | -------- | -------- | -------- |
52    | name | Sensor cluster name | string | None |
53    | sensor | Sensors in the cluster | string | soc, battery, shell, cpu, charger, ambient, ap, and pa |
54    | aux_sensor | Auxiliary sensors in the cluster | string | soc, battery, shell, cpu, charger, ambient, ap, and pa |
55
56    **Table 3** Description of the item configuration
57
58    | Configuration Item | Description | Data Type | Value Range |
59    | -------- | -------- | -------- | -------- |
60    | level | Thermal level defined for each sensor cluster | int | >0 |
61    | threshold | Temperature threshold for each sensor in the cluster to reach the corresponding thermal level. The value is in unit of 0.001°C by default and can be changed as needed. | int | Product-specific |
62    | threshold_clr | Temperature threshold for each sensor in the cluster to roll back to the previous thermal level. | int | Product-specific |
63    | temp_rise_rate | Temperature rise frequency. | double | Product-specific |
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. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/BUILD.gn) file in the default thermal level configuration folder to pack the `thermal_service_config.xml` file to the `/vendor/etc/thermal_config` directory. The configuration is as follows:
83
84    ```shell
85    import("//build/ohos.gni")                      # Reference 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 ]       # Required configuration for installing the thermal_service_config.xml file in the vendor directory.
91        part_name = "product_rk3568"                # Set part_name to product_rk3568 for subsequent build. You can change it as required.
92    }
93    ```
94
955. Add the build target to `module_list` in [ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build) in the `/vendor/hihope/rk3568` directory. For example:
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", // Add the configuration for building of thermal_service_config.
108                ]
109            }
110        },
111        "subsystem": "product_hihope"
112    }
113    ```
114    In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_service_config` is the build target.
115
1166. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
117
118    ```shell
119    ./build.sh --product-name rk3568 --ccache
120    ```
121
1227. Burn the customized version to the DAYU200 development board.
123
124### Debugging and Verification
125
1261. After startup, run the following command to launch the shell command line:
127    ```shell
128    hdc shell
129    ```
130
1312. Go to the `data/service/el0/thermal/sensor/soc/` directory.
132    ```shell
133    cd data/service/el0/thermal/sensor/soc
134    ```
135
1363. Change the SOC temperature.
137    ```shell
138    echo 42000 > temp
139    ```
140
1414. Obtain the current thermal level information.
142    ```shell
143    hidumper -s 3303 -a -l
144    ```
145
146    The following is the reference thermal level information after customization:
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## Reference
160During development, you can refer to the [default thermal level configuration](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml).
161
162Packing path: `/vendor/etc/thermal_config/hdf`
163