1 前言

嵌入式设备中,对于长时间工作的设备,特别是工控产品,一般会增加一个风扇为cpu主动散热。而风扇一般会选用可调速的,这样程序可以根据cpu温度实时调整风扇速度,以达到高温时能及时降低cpu温度,低温时节约功耗的目的。


2 获取cpu温度

cpu原厂提供的linux内核通常已经带有cpu温度检测驱动,并将温度信息映射到用户文件系统下,用户只需从该虚拟文件读取温度信息即可。cpu温度虚拟文件位于 “/sys/devices/virtual/thermal” 或者 “/sys/class/thermal” 下,命名为 “thermal_zoneX” ,X表示cpu核温度检测节点,如果是多核cpu通常会有多个温度检测节点;使用其中一个即可,因为温度通常差异不大。


rk3399 ubuntu16 下cup核温度节点

root@firefly:/home# ls /sys/devices/virtual/thermal/
cooling_device0  cooling_device1  cooling_device2  thermal_zone0  thermal_zone1
root@firefly:/home# ls /sys/class/thermal/
coolin