Skip to content

Commit

Permalink
Merge branch 'bugfix/temp_clk_gate' into 'master'
Browse files Browse the repository at this point in the history
fix(temperature_snesor): Put clock gate enable/disable in to sar_periph_ctrl together

Closes WIFIBUG-110

See merge request espressif/esp-idf!25992
  • Loading branch information
mythbuster5 committed Sep 22, 2023
2 parents 0f3ce62 + 3265bab commit c16b76f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 0 additions & 4 deletions components/driver/deprecated/rtc_temperature_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,14 @@ 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;
}

esp_err_t temp_sensor_stop(void)
{
regi2c_saradc_disable();
temperature_sensor_power_release();
tsens_hw_state = TSENS_HW_STATE_CONFIGURED;
return ESP_OK;
Expand Down
6 changes: 0 additions & 6 deletions components/driver/temperature_sensor/temperature_sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions components/esp_hw_support/sar_periph_ctrl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit c16b76f

Please sign in to comment.