温度传感器

支持的芯片[ RTL8720E ][ RTL8710E ][ RTL8726E ][ RTL8713E ][ RTL8730E ][ RTL8721F ]

概述

芯片内部集成了一个温度传感器(thermal sensor),可用于检测和监控芯片内部的实时温度。其主要特性包括:

  • 测量范围:-40°C ~ 125°C

  • 精确度:±1°C(典型值),±3°C(最差值)

  • 提供低温警告、高温警告和超温保护功能

  • 提供温度传感器使能和超温保护使能的写入访问控制

  • 可配置的启动间隔时间

  • 记录历史高低温

温度保护

温度保护机制是温度传感器的重要特性,具体实现如下:

  • 当温度超过限定的高温阈值时,向 CPU 发送中断,CPU 可以降低频率。

  • 当温度低于限定的低温阈值时,向 CPU 发送中断,CPU 可以提高频率。

  • 当温度超过限定的超温保护阈值时,硬件将自动关闭电源以进行超温保护。

备注

  • SDK 默认不会根据温度传感器检测到的温度自动调整 CPU 的频率。如果用户需要使用此功能,请调用相关 API,并根据实际应用和散热条件配置温度阈值。

  • 超温保护关闭电源后,芯片会定时自动重启,并且重启日志中会提示 BOOT REASON: THM.

低功耗模式

芯片进入深度睡眠模式或 power-gating 睡眠模式后,温度传感器所在电源域处于断电状态,无法工作。

芯片进入 clock-gating 睡眠模式后,SDK 默认关闭温度传感器,同样使其无法工作。

备注

  • 芯片一旦进入深度睡眠模式或 power-gating 睡眠模式后,温度传感器记录的历史高低温将丢失。

  • 芯片退出 clock-gating 睡眠模式后, SDK 默认重新打开温度传感器。

使用步骤

使用温度传感器获取当前温度的步骤如下:

  1. 设置默认参数。

    之后,可以根据需要在 TM_InitStruct 结构体中修改温度阈值、采样率等参数。

    TM_StructInit(TM_InitTypeDef *TM_InitStruct);
    
  2. 初始化温度传感器模块。

    TM_Init(TM_InitTypeDef *TM_InitStruct);
    
  3. 配置中断并注册中断回调函数。

    InterruptRegister((IRQ_FUN)TMIrqHandler, TmIrqNum[CPUID], NULL, 10);
    InterruptEn(TmIrqNum[CPUID], 10);
    
  4. 启用温度传感器。

    TM_Cmd(ENABLE);
    
  5. 启用温度传感器中断。

    TM_INTConfig(TM_BIT_IMR_TM_HIGH_WT | TM_BIT_IMR_TM_LOW_WT, ENABLE);
    

Raw API

THERMAL Exported Types

struct TM_InitTypeDef

Thermal Init Structure Definition.

Public Members

u8 TM_DownSampRate

Specifies thermal decimation filter down sample rate. This parameter can be a value of TM Down Sample Rate

u8 TM_AdcClkDiv

Specifies thermal ADC clock divider. This parameter can be a value of TM ADC CLK Divider

u16 TM_HighProtectThreshold

Specifies thermal high protection threshold. When the measured temperature is greater than or equal to this value, HW power down protection is triggered. This parameter only between 0x046 and 0x08C is valid.

u16 TM_HighWarnThreshold

Specifies thermal high warning threshold. The high warning interrupt is generated when the measured temperature is greater than or equal to this value, and less than TM_HighProtectThreshold, and tm_highcmp_wt_en=1, imr_tm_high_wt=1.

u16 TM_LowWarnThreshold

Specifies thermal low warning threshold. The low warning interrupt is generated when the measured temperature is less than or equal to this value, and tm_lowcmp_wt_en=1, imr_tm_low_wt=1.

u8 TM_TimePeriod

Specifies timer period between HW power down and restart. When the measured temperature is greater than or equal to TM_HighProtectThreshold, HW auto power down, the system will auto restart after this value time period

THERMAL Exported Constants

TM ADC CLK Divider

/* ADC clock divider: divide source clock by 256. */
#define TM_ADC_CLK_DIV_256 ((u8)0x00)

/* ADC clock divider: divide source clock by 128. */
#define TM_ADC_CLK_DIV_128 ((u8)0x01)

/* Checks if parameter is a valid ADC clock divider. */
#define IS_TM_ADC_CLK_DIV (((div) == TM_ADC_CLK_DIV_256) || \
    ((div) == TM_ADC_CLK_DIV_128))

TM Decimal Out

/* Extracts decimal part (bits[9:0]) from raw temperature output. */
#define TEMP_DECIMAL_OUT ((u32)((x) & 0x000003FF))

TM Down Sample Rate

/* Down sample rate: 128 (decimation filter OSR = 128). */
#define TM_DSR_128 ((u8)0x00)

/* Down sample rate: 256 (decimation filter OSR = 256). */
#define TM_DSR_256 ((u8)0x01)

/* Down sample rate: 512 (decimation filter OSR = 512). */
#define TM_DSR_512 ((u8)0x02)

/* Down sample rate: 1024 (decimation filter OSR = 1024). */
#define TM_DSR_1024 ((u8)0x03)

/* Checks if parameter is a valid down sample rate. */
#define IS_TM_DOWN_SAMPLE_RATE (((sel) == TM_DSR_128) || \
    ((sel) == TM_DSR_256) || \
    ((sel) == TM_DSR_512) || \
    ((sel) == TM_DSR_1024))

TM Programme Password

/* Password value required to program thermal meter registers. */
#define TM_PROG_PWR (0x69)

TM Temp Define

/* Minimum encoded value for a positive temperature reading. */
#define TM_POSITIVE_MIN ((u32)0x00000)

/* Maximum encoded value for a positive temperature reading. */
#define TM_POSITIVE_MAX ((u32)0x3FFFF)

/* Minimum encoded value for a negative temperature reading. */
#define TM_NEGATIVE_MIN ((u32)0x40000)

/* Maximum encoded value for a negative temperature reading. */
#define TM_NEGATIVE_MAX ((u32)0x7FFFF)

/* Encoded value indicating an invalid/unavailable temperature result. */
#define TM_INVALID_VALUE ((u32)0x80000)

/* Checks if raw temperature value represents a positive temperature. */
#define TM_IS_POSITIVE (((x) >= TM_POSITIVE_MIN) && ((x) <= TM_POSITIVE_MAX))

/* Checks if raw temperature value represents a negative temperature. */
#define TM_IS_NEGATIVE (((x) >= TM_NEGATIVE_MIN) && ((x) <= TM_NEGATIVE_MAX))

TM Calibration Value

RTL8720E:

Not supported.

THERMAL Exported Functions

void TM_Cmd(u32 NewState)

Enable or disable the thermal peripheral.

参数:
  • NewState -- New state of the thermal peripheral. This parameter can be ENABLE or DISABLE.

float TM_GetCdegree(u32 Data)

Get Celsius Degree.

参数:
  • Data -- TM_RESULT(Binary complement form)

返回:

Temperature value of float type.

float TM_GetFdegree(u32 Data)

Get Fahrenheit Degree.

参数:
  • Data -- TM_RESULT(Binary complement form)

返回:

Temperature value of float type.

u32 TM_GetISR(void)

Get thermal interrupt status.

返回:

Current interrupt status, with each bit defined in TM_INTR_STS.

u32 TM_GetMaxTemp(void)

Get thermal max temperature result.

返回:

The measured max temperature:

  • TM_INVALID_VALUE: invalid value

  • [0, TM_INVALID_VALUE): measured max temperature

u32 TM_GetMinTemp(void)

Get thermal min temperature result.

返回:

The measured min temperature:

  • TM_INVALID_VALUE: invalid value

  • [0, TM_INVALID_VALUE): measured min temperature

u32 TM_GetPowOnTemp(void)

Get thermal power on temperature result.

返回:

The measured power on temperature:

  • TM_INVALID_VALUE: invalid value

  • [0, TM_INVALID_VALUE): measured power on temperature

u32 TM_GetTempResult(void)

Get thermal temperature result.

返回:

The measured temperature:

  • TM_INVALID_VALUE: invalid value

  • [0, TM_INVALID_VALUE): measured temperature

void TM_HighPtConfig(u16 TM_HighPtThre, u32 NewState)

Configure over-temp protect threshold for comparison with TEMP_OUT.

参数:
  • TM_HighPtThre -- When TEMP_OUT > TM_HighPtThre, an AON reset is triggered.

  • NewState -- New state of the thermal over-temp protect comparison. This parameter can be ENABLE or DISABLE.

void TM_HighWtConfig(u16 TM_HighWtThre, u32 NewState)

Configure over-temp warning threshold for comparison with TEMP_OUT.

参数:
  • TM_HighWtThre -- When TM_HighWtThre <= TEMP_OUT < TM_HighPtThre, the ISR_TM_HIGH interrupt flag is set.

  • NewState -- New state of the thermal over-temp warning comparison. This parameter can be ENABLE or DISABLE.

备注

Only values greater than 0 are supported.

void TM_INTClear(void)

Clear all the thermal interrupt pending bits.

void TM_INTClearPendingBits(u32 TM_IT)

Clear the thermal interrupt pending bits.

参数:
  • TM_IT -- Specifies the pending bit to clear. This parameter can be one or combinations of bits in TM_INTR_STS.

void TM_INTConfig(u32 TM_IT, u32 NewState)

Enable or disable the thermal interrupt bits.

参数:
  • TM_IT -- Specifies the thermal interrupt to be configured. This parameter can be one or combinations of bits in TM_INTR_CTRL.

  • NewState -- ENABLE or DISABLE.

void TM_Init(TM_InitTypeDef *TM_InitStruct)

Initialize the thermal according to the specified parameters in TM_InitStruct.

参数:
  • TM_InitStruct -- Pointer to a TM_InitTypeDef structure that contains the configuration information for the thermal peripheral.

void TM_LowWtConfig(u16 TM_LowWtThre, u32 NewState)

Configure low-temp warning threshold for comparison with TEMP_OUT.

参数:
  • TM_LowWtThre -- When TEMP_OUT <= TM_LowWtThre, the ISR_TM_LOW interrupt flag is set.

  • NewState -- New state of the thermal low-temp warning comparison. This parameter can be ENABLE or DISABLE.

void TM_MaxTempClr(void)

Clear the max temperature recorded by thermal.

void TM_MinTempClr(void)

Clear the min temperature recorded by thermal.

int TM_PollDataValid(void)

Confirm whether thermal data is valid.

返回:

Thermal data valid status:

  • RTK_SUCCESS: thermal data is valid

  • RTK_FAIL: thermal data is invalid

void TM_PwrProgCmd(u32 NewState)

Enable or disable the specified thermal fields to be programmed.

参数:
  • NewState --

    ENABLE or DISABLE.

    • ENABLE: Fill TM_PWR field with right password 0x69.

    • DISABLE: Fill TM_PWR field with wrong password 0x0.

void TM_StructInit(TM_InitTypeDef *TM_InitStruct)

Initialize the parameters in the TM_InitStruct with default values.

参数:
  • TM_InitStruct -- Pointer to a TM_InitTypeDef structure that contains the configuration information for the thermal peripheral.