mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
fix(temperature_snesor): Put clock gate enable/disable in to sar_periph_ctrl together
This commit is contained in:
parent
7a32d72409
commit
73c78c20a6
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user