Merge branch 'bugfix/temp_clk_gate_v4.3' into 'release/v4.3'

fix(temperature_snesor): Put clock gate enable/disable in to sar_periph_ctrl together (backport v4.3)

See merge request espressif/esp-idf!27759
This commit is contained in:
Jiang Jiang Jian 2023-12-14 19:42:01 +08:00
commit eb0f7d0648
4 changed files with 17 additions and 13 deletions

View File

@ -55,9 +55,6 @@ static float s_deltaT = NAN; // unused number
esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens)
{
REG_SET_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_TSENS_CLK_EN);
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD);
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU);
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, dac_offset[tsens.dac_offset].set_val);
APB_SARADC.apb_tsens_ctrl.tsens_clk_div = tsens.clk_div;
APB_SARADC.apb_tsens_ctrl2.tsens_xpd_wait = TSENS_XPD_WAIT_DEFAULT;
@ -87,8 +84,6 @@ esp_err_t temp_sensor_get_config(temp_sensor_config_t *tsens)
esp_err_t temp_sensor_start(void)
{
REG_SET_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_TSENS_CLK_EN);
APB_SARADC.apb_tsens_ctrl2.tsens_clk_sel = 1;
temperature_sensor_power_acquire();
return ESP_OK;
}
@ -96,7 +91,6 @@ esp_err_t temp_sensor_start(void)
esp_err_t temp_sensor_stop(void)
{
temperature_sensor_power_release();
APB_SARADC.apb_tsens_ctrl2.tsens_clk_sel = 0;
return ESP_OK;
}

View File

@ -58,10 +58,6 @@ static float s_deltaT = NAN; // Unused number
esp_err_t temp_sensor_set_config(temp_sensor_config_t tsens)
{
CLEAR_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PD_M);
SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M);
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, I2C_SAR_M);
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_SAR_CFG2_M);
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_TSENS_DAC, dac_offset[tsens.dac_offset].set_val);
SENS.sar_tctrl.tsens_clk_div = tsens.clk_div;
SENS.sar_tctrl2.tsens_xpd_wait = TSENS_XPD_WAIT_DEFAULT;
@ -101,14 +97,12 @@ esp_err_t temp_sensor_start(void)
TSENS_CHECK(rtc_tsens_mux != NULL, ESP_ERR_NO_MEM);
temperature_sensor_power_acquire();
SENS.sar_tctrl.tsens_dump_out = 0;
SENS.sar_tctrl2.tsens_clkgate_en = 1;
return ESP_OK;
}
esp_err_t temp_sensor_stop(void)
{
temperature_sensor_power_release();
SENS.sar_tctrl2.tsens_clkgate_en = 0;
if (rtc_tsens_mux != NULL) {
vSemaphoreDelete(rtc_tsens_mux);
rtc_tsens_mux = NULL;

View File

@ -13,6 +13,9 @@
#include "private_include/regi2c_saradc.h"
#include "driver/temp_sensor.h"
#include "regi2c_ctrl.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/apb_saradc_struct.h"
#include "soc/system_reg.h"
extern __attribute__((unused)) portMUX_TYPE rtc_spinlock;
@ -36,6 +39,10 @@ void temperature_sensor_power_acquire(void)
s_temperature_sensor_power_cnt++;
if (s_temperature_sensor_power_cnt == 1) {
APB_SARADC.apb_tsens_ctrl.tsens_pu = true;
REG_SET_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_TSENS_CLK_EN);
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, ANA_I2C_SAR_FORCE_PD);
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_I2C_SAR_FORCE_PU);
APB_SARADC.apb_tsens_ctrl2.tsens_clk_sel = 1;
}
portEXIT_CRITICAL(&rtc_spinlock);
}
@ -51,6 +58,8 @@ void temperature_sensor_power_release(void)
abort();
} else if (s_temperature_sensor_power_cnt == 0) {
APB_SARADC.apb_tsens_ctrl.tsens_pu = false;
REG_CLR_BIT(SYSTEM_PERIP_CLK_EN1_REG, SYSTEM_TSENS_CLK_EN);
APB_SARADC.apb_tsens_ctrl2.tsens_clk_sel = 0;
}
portEXIT_CRITICAL(&rtc_spinlock);
}

View File

@ -23,7 +23,9 @@ extern __attribute__((unused)) portMUX_TYPE rtc_spinlock;
-----------------------------------------Temperature Sensor---------------------------------------------------
------------------------------------------------------------------------------------------------------------*/
static const char *TAG_TSENS = "temperature_sensor";
#include "regi2c_ctrl.h"
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#define INT_NOT_USED 999999
static int s_record_min = INT_NOT_USED;
@ -40,6 +42,10 @@ void temperature_sensor_power_acquire(void)
SENS.sar_tctrl.tsens_power_up_force = true;
SENS.sar_tctrl2.tsens_xpd_force = true;
SENS.sar_tctrl.tsens_power_up = true;
SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M);
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, I2C_SAR_M);
SET_PERI_REG_MASK(ANA_CONFIG2_REG, ANA_SAR_CFG2_M);
SENS.sar_tctrl2.tsens_clkgate_en = 1;
}
portEXIT_CRITICAL(&rtc_spinlock);
}
@ -57,6 +63,7 @@ void temperature_sensor_power_release(void)
SENS.sar_tctrl.tsens_power_up_force = false;
SENS.sar_tctrl2.tsens_xpd_force = false;
SENS.sar_tctrl.tsens_power_up = false;
SENS.sar_tctrl2.tsens_clkgate_en = 0;
}
portEXIT_CRITICAL(&rtc_spinlock);
}