![]() |
RT-Thread RTOS
An open source embedded real-time operating system
|
RT-Thread thermal management ties temperature sensors (thermal zones) to cooling devices (fan, DVFS, …) using trip points and governors. Temperatures are in millidegrees Celsius (m°C).
| Piece | Path |
|---|---|
| API | components/drivers/include/drivers/thermal.h |
| Core + OFW | components/drivers/thermal/thermal.c, thermal_dm.c |
| Kconfig | **RT_USING_THERMAL** (requires **RT_USING_DM**, **RT_USING_OFW** for DT maps) |
Cooling device details: Thermal cooling devices.
Governor: Built-in **dumb** governor is registered at **INIT_CORE_EXPORT**. **rt_thermal_cooling_device_register** attaches **dumb** unless **rt_thermal_cooling_device_change_governor** selects another.
| Option | Role |
|---|---|
**RT_USING_THERMAL** | Core **thermal.c** + **thermal_dm.c** |
**RT_THERMAL_SCMI** | Sensor zones via SCMI (thermal-scmi.c, needs SCMI firmware protocol) |
**RT_THERMAL_COOL_PWM_FAN** | thermal-cool-pwm-fan.c |
**RT_THERMAL_COOL_GPIO_FAN** | thermal-cool-gpio-fan.c |
**RT_THERMAL_COOL_DVFS** | thermal-cool-dvfs.c (needs **RT_USING_DVFS**) |
**SOC_DM_THERMAL_DIR** | BSP sensor drivers |
**SOC_DM_THERMAL_COOL_DIR** | BSP cooling drivers |
| Requirement | Detail |
|---|---|
**get_temp** | Mandatory; called from **rt_thermal_zone_device_update** |
**parent.ofw_node** | Sensor node referenced from **/thermal-zones/.../thermal-sensors** |
| Trips | From DT under zone, or pre-filled **zdev->trips** before register |
| Polling | **rt_work** resubmits every **polling_delay** / **passive_delay** (from DT, ms → ticks) |
Linux-style layout under **/thermal-zones**:
| Zone property | Effect |
|---|---|
**thermal-sensors** | Phandle + optional index → matches sensor **ofw_node** and **zone_id** |
**polling-delay** / **polling-delay-passive** | Work reschedule interval |
**sustainable-power**, **coefficients** | **rt_thermal_zone_params** |
Child trips | **temperature**, **hysteresis**, **type** (active / passive / hot / critical) |
**cooling-maps** | **trip**, **cooling-device** (#cooling-cells: min/max level), **contribution** |
**cooling-device** phandle resolves to a registered **rt_thermal_cooling_device** by matching **cdev->parent.ofw_node**. Register cooling devices before the zone that references them (or ensure cooling nodes are probed first).
**rt_thermal_cooling_device_register** requires **get_max_level**, **get_cur_level**, **set_cur_level**. **bind/unbind** optional (forwarded by **thermal_bind** in thermal_dm.c).
**rt_thermal_zone_device_update(zdev, msg)**:
get_temp**.temperature < current**, handles type:PASSIVE** / default → **cooling = true**, **rt_thermal_cooling_device_kick**CRITICAL** → **ops->critical** or cool; may **rt_hw_cpu_reset** if still over limitHOT** → **ops->hot** if presenttuning** adjusts levels per cooling-map cell; **set_cur_level** applied.msg** bitmask (RT_THERMAL_MSG_TRIP_VIOLATED, RT_THERMAL_MSG_EVENT_TEMP_SAMPLE, …).Call **update** from the zone poller (automatic after register) or manually for testing.
| Driver | Binding | Role |
|---|---|---|
**thermal-scmi.c** | **RT_SCMI_DRIVER_EXPORT**, protocol sensor "thermal" | One zone per SCMI temperature sensor |
**thermal-cool-pwm-fan.c** | **compatible = "pwm-fan"** | PWM + optional regulator — Thermal cooling devices |
**thermal-cool-gpio-fan.c** | GPIO + speed table | Discrete fan speeds |
**thermal-cool-dvfs.c** | DVFS OPP levels as cooling steps | Throttle CPU/GPU via Clock framework (CLK) / DVFS |
BSP sensors (e.g. board thermal IC) typically **rt_thermal_zone_device_register** in platform **probe** after filling trips in code or relying entirely on **thermal_ofw_setup**.
| API | Role |
|---|---|
rt_thermal_zone_device_register / unregister | Zone lifecycle + OFW parse + start poller |
rt_thermal_zone_device_update | Sample temp, trips, cooling, notifiers |
rt_thermal_zone_set_trip / get_trip | Runtime trip change |
rt_thermal_zone_notifier_register | Event callback |
rt_thermal_cooling_device_register / unregister | Cooling device |
rt_thermal_cooling_device_kick | Re-run governor for a zone |
rt_thermal_cooling_governor_register | Custom governor |
rt_thermal_cooling_device_change_governor | Per-device governor selection |
Constants: **RT_THERMAL_TEMP_INVALID** (−274000), **RT_THERMAL_NO_LIMIT**.
get_temp** (85 °C → 85000).get_temp cost**: slow buses (I2C) in every poll — cache or shorten **polling-delay** thoughtfully.cdev** by OFW node; probe cooling before zone register.cooling-maps** → log/events only, no fan/DVFS change.hysteresis** cause level oscillation.update** uses **zdev->mutex** when not in ISR.components/drivers/include/drivers/thermal.hcomponents/drivers/thermal/thermal.c