mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
fix(tsens): 300us delay in phy cause extra power consumption
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -15,6 +15,7 @@
|
|||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "esp_private/spi_common_internal.h"
|
#include "esp_private/spi_common_internal.h"
|
||||||
#include "esp_private/periph_ctrl.h"
|
#include "esp_private/periph_ctrl.h"
|
||||||
|
#include "esp_private/adc_share_hw_ctrl.h"
|
||||||
#include "hal/spi_ll.h"
|
#include "hal/spi_ll.h"
|
||||||
#include "hal/dac_ll.h"
|
#include "hal/dac_ll.h"
|
||||||
#include "hal/adc_ll.h"
|
#include "hal/adc_ll.h"
|
||||||
@ -141,7 +142,7 @@ esp_err_t dac_dma_periph_init(uint32_t freq_hz, bool is_alternate, bool is_apll)
|
|||||||
esp_err_t ret = ESP_OK;
|
esp_err_t ret = ESP_OK;
|
||||||
/* Acquire DMA peripheral */
|
/* Acquire DMA peripheral */
|
||||||
ESP_RETURN_ON_FALSE(spicommon_periph_claim(DAC_DMA_PERIPH_SPI_HOST, "dac_dma"), ESP_ERR_NOT_FOUND, TAG, "Failed to acquire DAC DMA peripheral");
|
ESP_RETURN_ON_FALSE(spicommon_periph_claim(DAC_DMA_PERIPH_SPI_HOST, "dac_dma"), ESP_ERR_NOT_FOUND, TAG, "Failed to acquire DAC DMA peripheral");
|
||||||
periph_module_enable(PERIPH_SARADC_MODULE);
|
adc_apb_periph_claim();
|
||||||
/* Allocate DAC DMA peripheral object */
|
/* Allocate DAC DMA peripheral object */
|
||||||
s_ddp = (dac_dma_periph_spi_t *)heap_caps_calloc(1, sizeof(dac_dma_periph_spi_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
s_ddp = (dac_dma_periph_spi_t *)heap_caps_calloc(1, sizeof(dac_dma_periph_spi_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||||
ESP_GOTO_ON_FALSE(s_ddp, ESP_ERR_NO_MEM, err, TAG, "No memory for DAC DMA object");
|
ESP_GOTO_ON_FALSE(s_ddp, ESP_ERR_NO_MEM, err, TAG, "No memory for DAC DMA object");
|
||||||
@ -173,7 +174,7 @@ esp_err_t dac_dma_periph_deinit(void)
|
|||||||
}
|
}
|
||||||
ESP_RETURN_ON_FALSE(spicommon_periph_free(DAC_DMA_PERIPH_SPI_HOST), ESP_FAIL, TAG, "Failed to release DAC DMA peripheral");
|
ESP_RETURN_ON_FALSE(spicommon_periph_free(DAC_DMA_PERIPH_SPI_HOST), ESP_FAIL, TAG, "Failed to release DAC DMA peripheral");
|
||||||
spi_ll_disable_intr(s_ddp->periph_dev, SPI_LL_INTR_OUT_EOF | SPI_LL_INTR_OUT_TOTAL_EOF);
|
spi_ll_disable_intr(s_ddp->periph_dev, SPI_LL_INTR_OUT_EOF | SPI_LL_INTR_OUT_TOTAL_EOF);
|
||||||
periph_module_disable(PERIPH_SARADC_MODULE);
|
adc_apb_periph_free();
|
||||||
if (s_ddp) {
|
if (s_ddp) {
|
||||||
if (s_ddp->use_apll) {
|
if (s_ddp->use_apll) {
|
||||||
periph_rtc_apll_release();
|
periph_rtc_apll_release();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -175,6 +175,11 @@ esp_err_t temperature_sensor_enable(temperature_sensor_handle_t tsens)
|
|||||||
|
|
||||||
temperature_sensor_ll_clk_sel(tsens->clk_src);
|
temperature_sensor_ll_clk_sel(tsens->clk_src);
|
||||||
temperature_sensor_power_acquire();
|
temperature_sensor_power_acquire();
|
||||||
|
// After enabling/reseting the temperature sensor,
|
||||||
|
// the output value gradually approaches the true temperature
|
||||||
|
// value as the measurement time increases. 300us is recommended.
|
||||||
|
esp_rom_delay_us(300);
|
||||||
|
|
||||||
tsens->fsm = TEMP_SENSOR_FSM_ENABLE;
|
tsens->fsm = TEMP_SENSOR_FSM_ENABLE;
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
@ -226,7 +231,6 @@ esp_err_t temperature_sensor_get_celsius(temperature_sensor_handle_t tsens, floa
|
|||||||
bool range_changed;
|
bool range_changed;
|
||||||
int16_t tsens_out = temp_sensor_get_raw_value(&range_changed);
|
int16_t tsens_out = temp_sensor_get_raw_value(&range_changed);
|
||||||
*out_celsius = parse_temp_sensor_raw_value(tsens_out);
|
*out_celsius = parse_temp_sensor_raw_value(tsens_out);
|
||||||
|
|
||||||
if (*out_celsius < TEMPERATURE_SENSOR_LL_MEASURE_MIN || *out_celsius > TEMPERATURE_SENSOR_LL_MEASURE_MAX) {
|
if (*out_celsius < TEMPERATURE_SENSOR_LL_MEASURE_MIN || *out_celsius > TEMPERATURE_SENSOR_LL_MEASURE_MAX) {
|
||||||
ESP_LOGE(TAG, "Exceeding temperature measure range.");
|
ESP_LOGE(TAG, "Exceeding temperature measure range.");
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
@ -10,5 +10,4 @@ set(srcs "test_app_main.c"
|
|||||||
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
|
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
|
||||||
# the component can be registered as WHOLE_ARCHIVE
|
# the component can be registered as WHOLE_ARCHIVE
|
||||||
idf_component_register(SRCS ${srcs}
|
idf_component_register(SRCS ${srcs}
|
||||||
esp_driver_tsens
|
|
||||||
WHOLE_ARCHIVE)
|
WHOLE_ARCHIVE)
|
||||||
|
@ -38,20 +38,14 @@ void temperature_sensor_power_acquire(void)
|
|||||||
portENTER_CRITICAL(&rtc_spinlock);
|
portENTER_CRITICAL(&rtc_spinlock);
|
||||||
s_temperature_sensor_power_cnt++;
|
s_temperature_sensor_power_cnt++;
|
||||||
if (s_temperature_sensor_power_cnt == 1) {
|
if (s_temperature_sensor_power_cnt == 1) {
|
||||||
|
adc_apb_periph_claim();
|
||||||
periph_module_enable(PERIPH_TEMPSENSOR_MODULE);
|
periph_module_enable(PERIPH_TEMPSENSOR_MODULE);
|
||||||
periph_module_reset(PERIPH_TEMPSENSOR_MODULE);
|
periph_module_reset(PERIPH_TEMPSENSOR_MODULE);
|
||||||
regi2c_saradc_enable();
|
regi2c_saradc_enable();
|
||||||
temperature_sensor_ll_clk_enable(true);
|
temperature_sensor_ll_clk_enable(true);
|
||||||
#if !SOC_TEMPERATURE_SENSOR_IS_INDEPENDENT_FROM_ADC
|
|
||||||
adc_apb_periph_claim();
|
|
||||||
#endif
|
|
||||||
temperature_sensor_ll_enable(true);
|
temperature_sensor_ll_enable(true);
|
||||||
}
|
}
|
||||||
portEXIT_CRITICAL(&rtc_spinlock);
|
portEXIT_CRITICAL(&rtc_spinlock);
|
||||||
// After enabling/reseting the temperature sensor,
|
|
||||||
// the output value gradually approaches the true temperature
|
|
||||||
// value as the measurement time increases. 300us is recommended.
|
|
||||||
esp_rom_delay_us(300);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void temperature_sensor_power_release(void)
|
void temperature_sensor_power_release(void)
|
||||||
@ -66,11 +60,9 @@ void temperature_sensor_power_release(void)
|
|||||||
} else if (s_temperature_sensor_power_cnt == 0) {
|
} else if (s_temperature_sensor_power_cnt == 0) {
|
||||||
temperature_sensor_ll_clk_enable(false);
|
temperature_sensor_ll_clk_enable(false);
|
||||||
temperature_sensor_ll_enable(false);
|
temperature_sensor_ll_enable(false);
|
||||||
#if !SOC_TEMPERATURE_SENSOR_IS_INDEPENDENT_FROM_ADC
|
|
||||||
adc_apb_periph_free();
|
|
||||||
#endif
|
|
||||||
regi2c_saradc_disable();
|
regi2c_saradc_disable();
|
||||||
periph_module_disable(PERIPH_TEMPSENSOR_MODULE);
|
periph_module_disable(PERIPH_TEMPSENSOR_MODULE);
|
||||||
|
adc_apb_periph_free();
|
||||||
}
|
}
|
||||||
portEXIT_CRITICAL(&rtc_spinlock);
|
portEXIT_CRITICAL(&rtc_spinlock);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user