1# Thermal Control Customization
2
3## Overview
4
5### Introduction
6
7By default, OpenHarmony provides the thermal control feature. If a device becomes overheated during usage, thermal control measures need to be taken for the device. For example, if the battery temperature is too high during charging, then thermal control needs to be applied to the charging device. However, thermal control varies according to product specifications. To address this issue, OpenHarmony provides the thermal control 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/blob/master/rk3568) as an example to illustrate thermal control customization.
28
291. Create the `thermal` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568).
30
312. Create a target folder by referring to the [default thermal control configuration folder](https://gitee.com/openharmony/powermgr_thermal_manager/blob/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 control configuration folder. The following table describes the related configuration items.
40
41    **Table 1** Configuration items for thermal control
42
43    | Configuration Item| Description| Parameter| Parameter Description| Data Type|Value Range|
44    | -------- | -------- | -------- | -------- | -------- | -------- |
45    | name="airplane" | Airplane mode control| N/A| N/A| N/A| N/A|
46    | name="cpu_big" | Big-core CPU control (big-core CPU frequency)| N/A| N/A| N/A| N/A|
47    | name="cpu_med" | Medium-core CPU control (medium-core CPU frequency)| N/A| N/A| N/A| N/A|
48    | name="cpu_lit" | Small-core CPU control (small-core CPU frequency)| N/A| N/A| N/A| N/A|
49    | name="gpu" | GPU control (GPU frequency)| N/A| N/A| N/A| N/A|
50    | name="boost" | SOCPERF thermal level control| event | - **1**: event sending enabled<br>-**0**: event sending disabled| int | 0 or 1|
51    | name="isolate" | CPU frequency increase control| event | - **1**: event sending enabled<br>-**0**: event sending disabled| int | 0 or 1|
52    | name="lcd" | LCD control (screen brightness)| N/A| N/A| N/A| N/A|
53    | name="volume" | Sound control (volume)| uid | User ID| int | Product-specific|
54    | name="current_xxx" | Charging current control (charging current during fast charging and slow charging)| protocol<br>param | Set **protocol** to **current** and **param** to a supported charging protocol, that is, fast charging (**sc**) or slow charging (**buck**).| string |protocol="current" param="sc" |
55    | name="current_xxx" | Charging current control | event | - **1**: event sending enabled<br>-**0**: event sending disabled| int | 0 or 1|
56    | name="voltage_xxx" | Charging voltage control (charging voltage during fast charging and slow charging)| protocol<br>param | Set **protocol** to **voltage** and **param** to a charging protocol, that is, fast charging (**sc**) or slow charging (**buck**).| string | protocol="voltage" param="buck" |
57    | name="voltage_xxx" | Charging voltage control | event | - **1**: event sending enabled<br>-**0**: event sending disabled| int | 0 or 1|
58    | name="process_ctrl" | Process control (survival status of foreground and background processes)| param | Set **param** to any string.| string | N/A|
59    | name="process_ctrl" | Process control (survival status of foreground and background processes)| event | - **1**: event sending enabled<br>-**0**: event sending disabled<br>If this parameter is not set, the value is defaulted to **0**.| int | 0 or 1|
60    | name="shut_down" | Shutdown control (device shutdown)| event | - **1**: event sending enabled<br>-**0**: event sending disabled| int | 0 or 1|
61    | name="thermallevel" | Thermal level control (thermal level reporting)| event | - **1**: event sending enabled<br>-**0**: event sending disabled| int | 0 or 1|
62    | name="popup" | Pop-up window control (pop-up window display)| N/A| N/A| N/A| N/A|
63    | name="xxx" | Node thermal control action| protocol<br>param | Set **protocol** to **node**.<br>Set **param** to the node path and rollback value, which are separated by a|backslash (\).| string | N/A|
64
65    ```shell
66    <action>
67        <item name="airplane"/>
68        <item name="cpu_big"/>
69        <item name="cpu_med"/>
70        <item name="cpu_lit"/>
71        <item name="gpu"/>
72        <item name="boost" event="1"/>
73        <item name="isolate" event="1"/>
74        <item name="lcd"/>
75        <item name="volume" uid="2001,2002"/>
76        <item name="current_sc" protocol="current" param="sc" event="1"/>
77        <item name="voltage_buck" protocol="voltage" param="buck" event="1"/>
78        <item name="process_ctrl" param="32,64,128,256" event=""/>
79        <item name="shut_down" event="0"/>
80        <item name="thermallevel" event="1"/>
81        <item name="popup"/>
82        <item name="(action_name)" protocol="node" param="/sys/class/thermal/xxx"/>
83        <item name="test"/>
84    </action>
85    ```
86
874. 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 control configuration folder to pack the `thermal_service_config.xml` file to the `/vendor/etc/thermal_config` directory. The configuration is as follows:
88
89    ```shell
90    import("//build/ohos.gni")                      # Reference build/ohos.gni.
91
92    ohos_prebuilt_etc("thermal_service_config") {
93        source = "thermal_service_config.xml"
94        relative_install_dir = "thermal_config"
95        install_images = [ chipset_base_dir ]       # Required configuration for installing the thermal_service_config.xml file in the vendor directory.
96        part_name = "product_rk3568"                # Set part_name to product_rk3568 for subsequent build. You can change it as required.
97    }
98    ```
99
1005. Add the build target to `module_list` in [ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build). For example:
101
102    ```json
103    {
104        "parts": {
105            "product_rk3568": {
106                "module_list": [
107                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
108                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
109                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
110                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
111                    "//vendor/hihope/rk3568/etc:product_etc_conf",
112                    "//vendor/hihope/rk3568/thermal/profile:thermal_service_config", // Add the configuration for building of thermal_service_config.
113                ]
114            }
115        },
116        "subsystem": "product_hihope"
117    }
118    ```
119    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.
120
1216. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
122
123    ```shell
124    ./build.sh --product-name rk3568 --ccache
125    ```
126
1277. Burn the customized version to the DAYU200 development board.
128
129### Debugging and Verification
130
1311. After startup, run the following command to launch the shell command line:
132    ```shell
133    hdc shell
134    ```
135
1362. Obtain the current thermal control information.
137    ```shell
138    hidumper -s 3303 -a -a
139    ```
140
141    The following is the reference thermal control result after customization:
142    ```shell
143    -------------------------------[ability]-------------------------------
144
145
146    ----------------------------------ThermalService---------------------------------
147    name: airplane	strict: 0	enableEvent: 0
148    name: cpu_big	strict: 0	enableEvent: 0
149    name: cpu_med	strict: 0	enableEvent: 0
150    name: cpu_lit	strict: 0	enableEvent: 0
151    name: gpu	strict: 0	enableEvent: 0
152    name: boost	strict: 0	enableEvent: 1
153    name: isolate	strict: 0	enableEvent: 1
154    name: lcd	strict: 0	enableEvent: 0
155    name: volume	uid: 2001,2002	strict: 0	enableEvent: 0
156    name: current_sc    params: sc	protocol: current	strict: 0	enableEvent: 1
157    name: current_buck    params: buck	protocol: current	strict: 0	enableEvent: 1
158    name: voltage_sc   params: sc	protocol: voltage	strict: 0	enableEvent: 1
159    name: voltage_buck   params: buck	protocol: voltage	strict: 0	enableEvent: 1
160    name: process_ctrl  params: 32,64,128,256	strict: 0	enableEvent: 0
161    name: shut_down	strict: 0	enableEvent: 0
162    name: thermallevel	strict: 0	enableEvent: 1
163    name: popup	strict: 0	enableEvent: 0
164    name: test	strict: 0	enableEvent: 0
165    ```
166
167## Reference
168During development, you can refer to the [default thermal control configuration](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml).
169
170Packing path: `/vendor/etc/thermal_config/hdf`
171
172<!--no_check-->