From 3265bab95f4d358b5393b22f10200911654a2666 Mon Sep 17 00:00:00 2001 From: Cao Sen Miao Date: Fri, 15 Sep 2023 19:49:24 +0800 Subject: [PATCH] fix(temperature_snesor): Put clock gate enable/disable in to sar_periph_ctrl together --- components/driver/deprecated/rtc_temperature_legacy.c | 4 ---- .../driver/temperature_sensor/temperature_sensor.c | 6 ------ components/esp_hw_support/sar_periph_ctrl_common.c | 9 +++++++++ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/components/driver/deprecated/rtc_temperature_legacy.c b/components/driver/deprecated/rtc_temperature_legacy.c index 1e162c127e..97e700fa80 100644 --- a/components/driver/deprecated/rtc_temperature_legacy.c +++ b/components/driver/deprecated/rtc_temperature_legacy.c @@ -94,10 +94,7 @@ esp_err_t temp_sensor_start(void) ESP_LOGE(TAG, "Is already running or not be configured"); err = ESP_ERR_INVALID_STATE; } - regi2c_saradc_enable(); - periph_module_enable(PERIPH_TEMPSENSOR_MODULE); temperature_sensor_power_acquire(); - temperature_sensor_ll_clk_enable(true); temperature_sensor_ll_clk_sel(TEMPERATURE_SENSOR_CLK_SRC_DEFAULT); tsens_hw_state = TSENS_HW_STATE_STARTED; return err; @@ -105,7 +102,6 @@ esp_err_t temp_sensor_start(void) esp_err_t temp_sensor_stop(void) { - regi2c_saradc_disable(); temperature_sensor_power_release(); tsens_hw_state = TSENS_HW_STATE_CONFIGURED; return ESP_OK; diff --git a/components/driver/temperature_sensor/temperature_sensor.c b/components/driver/temperature_sensor/temperature_sensor.c index 1720b9b92c..51d5e59e1d 100644 --- a/components/driver/temperature_sensor/temperature_sensor.c +++ b/components/driver/temperature_sensor/temperature_sensor.c @@ -104,8 +104,6 @@ esp_err_t temperature_sensor_install(const temperature_sensor_config_t *tsens_co ESP_GOTO_ON_FALSE(tsens != NULL, ESP_ERR_NO_MEM, err, TAG, "no mem for temp sensor"); tsens->clk_src = tsens_config->clk_src; - periph_module_enable(PERIPH_TEMPSENSOR_MODULE); - periph_module_reset(PERIPH_TEMPSENSOR_MODULE); ESP_GOTO_ON_ERROR(temperature_sensor_attribute_table_sort(), err, TAG, "Table sort failed"); ESP_GOTO_ON_ERROR(temperature_sensor_choose_best_range(tsens, tsens_config), err, TAG, "Cannot select the correct range"); @@ -114,7 +112,6 @@ esp_err_t temperature_sensor_install(const temperature_sensor_config_t *tsens_co tsens->tsens_attribute->range_max, tsens->tsens_attribute->error_max); - regi2c_saradc_enable(); temperature_sensor_ll_set_range(tsens->tsens_attribute->reg_val); tsens->fsm = TEMP_SENSOR_FSM_INIT; @@ -134,7 +131,6 @@ esp_err_t temperature_sensor_uninstall(temperature_sensor_handle_t tsens) free(s_tsens_attribute_copy); } s_tsens_attribute_copy = NULL; - regi2c_saradc_disable(); #if SOC_TEMPERATURE_SENSOR_INTR_SUPPORT temperature_sensor_ll_enable_intr(false); @@ -143,7 +139,6 @@ esp_err_t temperature_sensor_uninstall(temperature_sensor_handle_t tsens) } #endif // SOC_TEMPERATURE_SENSOR_INTR_SUPPORT - periph_module_disable(PERIPH_TEMPSENSOR_MODULE); free(tsens); return ESP_OK; } @@ -178,7 +173,6 @@ esp_err_t temperature_sensor_enable(temperature_sensor_handle_t tsens) temperature_sensor_ll_sample_enable(true); #endif // SOC_TEMPERATURE_SENSOR_INTR_SUPPORT - temperature_sensor_ll_clk_enable(true); temperature_sensor_ll_clk_sel(tsens->clk_src); temperature_sensor_power_acquire(); tsens->fsm = TEMP_SENSOR_FSM_ENABLE; diff --git a/components/esp_hw_support/sar_periph_ctrl_common.c b/components/esp_hw_support/sar_periph_ctrl_common.c index b8776b39e6..1173a82cef 100644 --- a/components/esp_hw_support/sar_periph_ctrl_common.c +++ b/components/esp_hw_support/sar_periph_ctrl_common.c @@ -13,6 +13,8 @@ #if SOC_TEMP_SENSOR_SUPPORTED #include "hal/temperature_sensor_ll.h" #include "soc/temperature_sensor_periph.h" +#include "soc/periph_defs.h" +#include "esp_private/periph_ctrl.h" extern __attribute__((unused)) portMUX_TYPE rtc_spinlock; @@ -35,6 +37,10 @@ void temperature_sensor_power_acquire(void) portENTER_CRITICAL(&rtc_spinlock); s_temperature_sensor_power_cnt++; if (s_temperature_sensor_power_cnt == 1) { + periph_module_enable(PERIPH_TEMPSENSOR_MODULE); + periph_module_reset(PERIPH_TEMPSENSOR_MODULE); + regi2c_saradc_enable(); + temperature_sensor_ll_clk_enable(true); temperature_sensor_ll_enable(true); } portEXIT_CRITICAL(&rtc_spinlock); @@ -50,7 +56,10 @@ void temperature_sensor_power_release(void) ESP_LOGE(TAG_TSENS, "%s called, but s_temperature_sensor_power_cnt == 0", __func__); abort(); } else if (s_temperature_sensor_power_cnt == 0) { + temperature_sensor_ll_clk_enable(false); temperature_sensor_ll_enable(false); + regi2c_saradc_disable(); + periph_module_disable(PERIPH_TEMPSENSOR_MODULE); } portEXIT_CRITICAL(&rtc_spinlock); }