1e41f4b71Sopenharmony_ci# Thermal Detection Customization
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Overview
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci### Introduction
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciBy default, OpenHarmony provides the thermal detection feature. A component, for example, the CPU or battery, generates heat while it is running. In this case, the component reports its temperature in real time through the corresponding temperature sensor. The thermal detection feature detects the temperature of components in real time and provides temperature input for the thermal management module. However, thermal detection on components varies according to product specifications. To address this issue, OpenHarmony provides the thermal detection customization function.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci### Constraints
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ciThe 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.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## How to Develop
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci### Setting Up the Environment
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci**Hardware requirements:**
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciDevelopment board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**Environment requirements:**
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ciFor details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md).
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci### Getting Started with Development
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ciThe following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate thermal detection customization.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci1. Create the `thermal` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568).
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci2. Create a target folder by referring to the [default thermal detection configuration folder](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/interfaces/hdi_service/profile), and install it in `//vendor/hihope/rk3568/thermal`. The content is as follows:
32e41f4b71Sopenharmony_ci     
33e41f4b71Sopenharmony_ci    ```text
34e41f4b71Sopenharmony_ci    profile
35e41f4b71Sopenharmony_ci    ├── BUILD.gn
36e41f4b71Sopenharmony_ci    ├── thermal_hdi_config.xml
37e41f4b71Sopenharmony_ci    ```
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci3. Write the custom `thermal_hdi_config.xml` file by referring to the [thermal_hdi_config.xml](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/thermal_hdi_config.xml) file in the default thermal detection configuration folder. The following table describes the related configuration items.
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci    **Table 1** Configuration items for thermal detection
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci    |Node| Configuration Item| Description| Value Type|
44e41f4b71Sopenharmony_ci    | -------- | -------- | -------- | -------- |
45e41f4b71Sopenharmony_ci    | item | tag | Temperature flag name of an actual or simulated node.| string |
46e41f4b71Sopenharmony_ci    | item | value | Temperature flag value. Value **1** means to obtain the temperature of a simulated node, and the value **0**, means to obtain the temperature of an actual node.| int |
47e41f4b71Sopenharmony_ci    | group | name | Name of the actual or simulated node group.| string |
48e41f4b71Sopenharmony_ci    | group | interval | Polling interval, in ms (default).| int |
49e41f4b71Sopenharmony_ci    | thermal_zone | type | Thermal zone name.| string |
50e41f4b71Sopenharmony_ci    | thermal_zone | path | Path for obtaining the thermal zone temperature of an actual node.| string |
51e41f4b71Sopenharmony_ci    | thermal_node | type | Thermal node name.| string |
52e41f4b71Sopenharmony_ci    | thermal_node | path | Path for obtaining the thermal node temperature of a simulated node.| string |
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci    ```shell
55e41f4b71Sopenharmony_ci    <base>
56e41f4b71Sopenharmony_ci        <item tag="sim_tz" value="0"/>
57e41f4b71Sopenharmony_ci    </base>
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci    <polling>
60e41f4b71Sopenharmony_ci        <group name="actual" interval="30000">
61e41f4b71Sopenharmony_ci            <thermal_zone type="soc-thermal" path="sys/class/thermal/thermal_zone0/temp"/>
62e41f4b71Sopenharmony_ci            <thermal_zone type="gpu-thermal" path="sys/class/thermal/thermal_zone0/temp"/>
63e41f4b71Sopenharmony_ci        </group>
64e41f4b71Sopenharmony_ci        <group name="sim" interval="30000">
65e41f4b71Sopenharmony_ci            <thermal_node type="soc" path="data/service/el0/thermal/sensor/soc/temp"/>
66e41f4b71Sopenharmony_ci            <thermal_node type="cpu" path="data/service/el0/thermal/sensor/cpu/temp"/>
67e41f4b71Sopenharmony_ci            <thermal_node type="ap" path="data/service/el0/thermal/sensor/ap/temp"/>
68e41f4b71Sopenharmony_ci            <thermal_node type="pa" path="data/service/el0/thermal/sensor/pa/temp"/>
69e41f4b71Sopenharmony_ci            <thermal_node type="ambient" path="data/service/el0/thermal/sensor/ambient/temp"/>
70e41f4b71Sopenharmony_ci            <thermal_node type="charger" path="data/service/el0/thermal/sensor/charger/temp"/>
71e41f4b71Sopenharmony_ci            <thermal_node type="battery" path="data/service/el0/thermal/sensor/battery/temp"/>
72e41f4b71Sopenharmony_ci            <thermal_node type="shell" path="data/service/el0/thermal/sensor/shell/temp"/>
73e41f4b71Sopenharmony_ci        </group>
74e41f4b71Sopenharmony_ci    </polling>
75e41f4b71Sopenharmony_ci    ```
76e41f4b71Sopenharmony_ci    For details about the path for obtaining the actual node temperature, see the path for obtaining the thermal zone temperature in [Thermal Log](../subsystems/subsys-thermal_log.md). For details about the path for obtaining the simulated node temperature, see [Default Thermal Detection Configuration](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/thermal_hdi_config.xml).
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci5. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/BUILD.gn) file in the default thermal detection configuration folder to pack the `thermal_hdi_config.xml` file to the `//vendor/etc/thermal_config/hdf` directory. The configuration is as follows:
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci    ```shell
81e41f4b71Sopenharmony_ci    import("//build/ohos.gni")
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci    ohos_prebuilt_etc("thermal_hdf_config") {
84e41f4b71Sopenharmony_ci        source = "thermal_hdi_config.xml"
85e41f4b71Sopenharmony_ci        relative_install_dir = "thermal_config/hdf"
86e41f4b71Sopenharmony_ci        install_images = [ chipset_base_dir ]       # Required configuration for installing the thermal_hdi_config.xml file in the vendor directory.
87e41f4b71Sopenharmony_ci        part_name = "product_rk3568"                # Set part_name to product_rk3568 for subsequent build. You can change it as required.
88e41f4b71Sopenharmony_ci    }
89e41f4b71Sopenharmony_ci    ```
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci6. 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:
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci    ```json
94e41f4b71Sopenharmony_ci    {
95e41f4b71Sopenharmony_ci        "parts": {
96e41f4b71Sopenharmony_ci            "product_rk3568": {
97e41f4b71Sopenharmony_ci                "module_list": [
98e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
99e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
100e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
101e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
102e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/etc:product_etc_conf",
103e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/thermal/profile:thermal_hdf_config", // Add the configuration for building of thermal_hdf_config.
104e41f4b71Sopenharmony_ci                ]
105e41f4b71Sopenharmony_ci            }
106e41f4b71Sopenharmony_ci        },
107e41f4b71Sopenharmony_ci        "subsystem": "product_hihope"
108e41f4b71Sopenharmony_ci    }
109e41f4b71Sopenharmony_ci    ```
110e41f4b71Sopenharmony_ci    In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_hdf_config` is the build target.
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci7. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci    ```shell
115e41f4b71Sopenharmony_ci    ./build.sh --product-name rk3568 --ccache
116e41f4b71Sopenharmony_ci    ```
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci8. Burn the customized version to the DAYU200 development board.
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci### Debugging and Verification
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci1. After startup, run the following command to launch the shell command line:
123e41f4b71Sopenharmony_ci    ```shell
124e41f4b71Sopenharmony_ci    hdc shell
125e41f4b71Sopenharmony_ci    ```
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci2. Obtain the thermal detection result of the thermal zone.
128e41f4b71Sopenharmony_ci    ```shell
129e41f4b71Sopenharmony_ci    hidumper -s 3303 -a -t
130e41f4b71Sopenharmony_ci    ```
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci    The following is the reference thermal detection result of the thermal zone. The value of **Temperature** is in unit of 0.001°C by default.
133e41f4b71Sopenharmony_ci    ```shell
134e41f4b71Sopenharmony_ci    -------------------------------[ability]-------------------------------
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci    ----------------------------------ThermalService---------------------------------
138e41f4b71Sopenharmony_ci    ········· (Only the thermal detection result is displayed here. Other information is omitted.)
139e41f4b71Sopenharmony_ci    Type: gpu-thermal
140e41f4b71Sopenharmony_ci    Temperature: 35555
141e41f4b71Sopenharmony_ci    Type: soc-thermal
142e41f4b71Sopenharmony_ci    Temperature: 35000
143e41f4b71Sopenharmony_ci    ······
144e41f4b71Sopenharmony_ci    ```
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci## Reference
147e41f4b71Sopenharmony_ciDuring development, you can refer to the [default thermal detection configuration](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/thermal_hdi_config.xml).
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ciPacking path: `/vendor/etc/thermal_config/hdf`
150