Files
mr-liang2504 cfa4a56b11 Signed-off-by: mr-liang2504 <liangzhicheng10@huawei.com>
Co-Authored-By: Agent

Signed-off-by: mr-liang2504 <liangzhicheng10@huawei.com>
Change-Id: Ie24e29785e1d14e7318e7ffd1718e8c964811b6c
2026-08-11 20:04:27 +08:00
..
2025-12-25 20:06:15 +08:00
2022-06-29 11:29:07 +08:00
2026-04-13 16:27:40 +08:00
2026-04-13 16:27:40 +08:00
2025-05-16 11:38:19 +08:00
2025-05-16 11:38:19 +08:00

Thermal

Introduction

This repository contains the Thermal module HDI (Hardware Driver Interface) definitions and implementations, providing temperature management driver capability interfaces for upper-layer system services. The Thermal HDI interfaces mainly include:

  • Thermal Zone: Responsible for obtaining thermal zone temperature information.
  • Thermal Mitigation: Responsible for thermal mitigation strategy management, including CPU frequency adjustment, GPU frequency adjustment, battery current limit, etc.
  • CPU Isolation: Responsible for CPU core isolation management.
  • Callback: Responsible for thermal event callback notifications.

Directory

The source code directory structure is as follows:

/drivers/peripheral/thermal
├── etc                      # Thermal module configuration files
├── interfaces              # Thermal module driver capability interfaces for upper-layer services
│   └── hdi_service          # HDI layer framework code
│       ├── include          # Header files
│       ├── profile          # Configuration files
│       └── src              # HDI layer source code
├── test                     # Thermal module test code
│   ├── unittest             # Unit tests
│   └── fuzztest             # Fuzz tests
└── utils                    # Utility code

Interface Description

The Thermal driver module provides interfaces to upper-layer system services through the HDI layer, with main functions including: obtaining thermal zone information, setting thermal mitigation strategies, CPU isolation, etc. The provided interfaces are shown in Table1 Thermal HDI Interface List:

Table 1 Thermal HDI Interface List

Header File

Interface Name

Function Description

v1_1/ithermal_interface.h

int32_t SetCpuFreq(int32_t freq);

Set CPU frequency

int32_t SetGpuFreq(int32_t freq);

Set GPU frequency

int32_t SetBatteryCurrent(int32_t current);

Set battery current

int32_t GetThermalZoneInfo(HdfThermalCallbackInfo& event);

Get thermal zone info

int32_t IsolateCpu(int32_t num);

Isolate CPU core

int32_t Register(const sptr& callbackObj);

Register thermal callback

int32_t Unregister();

Unregister thermal callback

int32_t RegisterFanCallback(const sptr& callbackObj);

Register fan callback

int32_t UnregisterFanCallback();

Unregister fan callback

Usage Instructions

The core function of this repository is to provide temperature management driver capability interfaces for upper-layer system services. The provided driver capability interfaces are unified as HDI interface layer.

The following sample code demonstrates how to use the Thermal HDI interface:

#include "v1_1/ithermal_interface.h"
#include "thermal_hdi_client.h"

using namespace OHOS::HDI::Thermal::V1_1;

class ThermalCallbackImpl : public IThermalCallback {
public:
    int32_t OnThermalCallback(HdfThermalCallbackInfo& event) override
    {
        HDF_LOGI("ThermalCallback: zoneId=%{public}d, temp=%{public}d", 
                 event.zoneId, event.temperature);
        return 0;
    }
};

static int32_t ThermalHdiSample(void)
{
    int32_t ret;
    sptr<IThermalInterface> g_thermalInterface = ThermalHdiClient::GetInstance();

    if (g_thermalInterface == nullptr) {
        HDF_LOGE("get thermal interface failed");
        return HDF_FAILURE;
    }

    // Register thermal callback
    sptr<IThermalCallback> callback = new (std::nothrow) ThermalCallbackImpl();
    ret = g_thermalInterface->Register(callback);
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("register thermal callback failed");
        return ret;
    }

    // Set CPU frequency
    ret = g_thermalInterface->SetCpuFreq(2000000);
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("set cpu freq failed");
        return ret;
    }

    // Set GPU frequency
    ret = g_thermalInterface->SetGpuFreq(800000);
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("set gpu freq failed");
        return ret;
    }

    // Set battery current
    ret = g_thermalInterface->SetBatteryCurrent(1000);
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("set battery current failed");
        return ret;
    }

    // Isolate CPU core
    ret = g_thermalInterface->IsolateCpu(4);
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("isolate cpu failed");
        return ret;
    }

    // Get thermal zone info
    HdfThermalCallbackInfo event;
    ret = g_thermalInterface->GetThermalZoneInfo(event);
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("get thermal zone info failed");
        return ret;
    }

    // Unregister thermal callback
    ret = g_thermalInterface->Unregister();
    if (ret != HDF_SUCCESS) {
        HDF_LOGE("unregister thermal callback failed");
        return ret;
    }

    return HDF_SUCCESS;
}

Driver Subsystem

drivers_framework

drivers_adapter

drivers_interface

drivers_peripheral