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
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;
}