mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 19:13:21 +00:00
Merge branch 'bugfix/fix_temp_sensor_affect_by_adc_v5.2' into 'release/v5.2'
Bugfix/fix temp sensor affect by adc v5.2 See merge request espressif/esp-idf!47031
This commit is contained in:
@@ -349,7 +349,7 @@ esp_err_t adc_continuous_start(adc_continuous_handle_t handle)
|
|||||||
ESP_RETURN_ON_FALSE(handle->fsm == ADC_FSM_INIT, ESP_ERR_INVALID_STATE, ADC_TAG, "ADC continuous mode isn't in the init state, it's started already");
|
ESP_RETURN_ON_FALSE(handle->fsm == ADC_FSM_INIT, ESP_ERR_INVALID_STATE, ADC_TAG, "ADC continuous mode isn't in the init state, it's started already");
|
||||||
|
|
||||||
//reset ADC digital part to reset ADC sampling EOF counter
|
//reset ADC digital part to reset ADC sampling EOF counter
|
||||||
periph_module_reset(PERIPH_SARADC_MODULE);
|
sar_periph_ctrl_adc_reset();
|
||||||
|
|
||||||
if (handle->pm_lock) {
|
if (handle->pm_lock) {
|
||||||
ESP_RETURN_ON_ERROR(esp_pm_lock_acquire(handle->pm_lock), ADC_TAG, "acquire pm_lock failed");
|
ESP_RETURN_ON_ERROR(esp_pm_lock_acquire(handle->pm_lock), ADC_TAG, "acquire pm_lock failed");
|
||||||
@@ -427,7 +427,7 @@ esp_err_t adc_continuous_stop(adc_continuous_handle_t handle)
|
|||||||
adc_hal_digi_stop(&handle->hal);
|
adc_hal_digi_stop(&handle->hal);
|
||||||
|
|
||||||
#if ADC_LL_WORKAROUND_CLEAR_EOF_COUNTER
|
#if ADC_LL_WORKAROUND_CLEAR_EOF_COUNTER
|
||||||
periph_module_reset(PERIPH_SARADC_MODULE);
|
sar_periph_ctrl_adc_reset();
|
||||||
adc_hal_digi_clr_eof();
|
adc_hal_digi_clr_eof();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "soc/adc_periph.h"
|
#include "soc/adc_periph.h"
|
||||||
#include "esp_adc/adc_oneshot.h"
|
#include "esp_adc/adc_oneshot.h"
|
||||||
|
#include "esp_adc/adc_continuous.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "driver/rtc_io.h"
|
#include "driver/rtc_io.h"
|
||||||
#include "driver/temperature_sensor.h"
|
#include "driver/temperature_sensor.h"
|
||||||
@@ -23,61 +24,142 @@
|
|||||||
|
|
||||||
static const char *TAG = "adc_tsens";
|
static const char *TAG = "adc_tsens";
|
||||||
|
|
||||||
#define EXAMPLE_ADC1_CHAN0 ADC_CHANNEL_2
|
#define TEST_ADC1_CHAN0 ADC_CHANNEL_2
|
||||||
#define EXAMPLE_ADC1_CHAN1 ADC_CHANNEL_4
|
#define TEST_ADC_ATTEN ADC_ATTEN_DB_12
|
||||||
#define EXAMPLE_ADC_ATTEN ADC_ATTEN_DB_12
|
|
||||||
|
|
||||||
static int adc_raw[2][10];
|
static int adc_raw;
|
||||||
|
static float tsens_value;
|
||||||
|
|
||||||
TEST_CASE("Test temperature sensor cannot be influenced by ADC", "[adc]")
|
static void temp_sensor_test(temperature_sensor_handle_t temp_sensor)
|
||||||
|
{
|
||||||
|
int cnt = 2;
|
||||||
|
while (cnt--) {
|
||||||
|
TEST_ESP_OK(temperature_sensor_get_celsius(temp_sensor, &tsens_value));
|
||||||
|
ESP_LOGI(TAG, "Temperature value %.02f ℃", tsens_value);
|
||||||
|
TEST_ASSERT_GREATER_THAN(0, tsens_value);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void adc_oneshot_test(adc_oneshot_unit_handle_t adc_handle)
|
||||||
|
{
|
||||||
|
test_adc_set_io_level(ADC_UNIT_1, TEST_ADC1_CHAN0, 0);
|
||||||
|
TEST_ESP_OK(adc_oneshot_read(adc_handle, TEST_ADC1_CHAN0, &adc_raw));
|
||||||
|
ESP_LOGI(TAG, "low raw data: %d", adc_raw);
|
||||||
|
TEST_ASSERT_INT_WITHIN(ADC_TEST_LOW_THRESH, ADC_TEST_LOW_VAL, adc_raw);
|
||||||
|
|
||||||
|
test_adc_set_io_level(ADC_UNIT_1, TEST_ADC1_CHAN0, 1);
|
||||||
|
TEST_ESP_OK(adc_oneshot_read(adc_handle, TEST_ADC1_CHAN0, &adc_raw));
|
||||||
|
ESP_LOGI(TAG, "high raw data: %d", adc_raw);
|
||||||
|
TEST_ASSERT_INT_WITHIN(ADC_TEST_HIGH_THRESH, ADC_TEST_HIGH_VAL, adc_raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Test temperature sensor work with ADC oneshot", "[adc]")
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Install temperature sensor, expected temp ranger range: 10~50 ℃");
|
ESP_LOGI(TAG, "Install temperature sensor, expected temp ranger range: 10~50 ℃");
|
||||||
temperature_sensor_handle_t temp_sensor = NULL;
|
temperature_sensor_handle_t temp_sensor = NULL;
|
||||||
temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(-10, 80);
|
temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(10, 50);
|
||||||
TEST_ESP_OK(temperature_sensor_install(&temp_sensor_config, &temp_sensor));
|
TEST_ESP_OK(temperature_sensor_install(&temp_sensor_config, &temp_sensor));
|
||||||
int cnt = 2;
|
TEST_ESP_OK(temperature_sensor_enable(temp_sensor));
|
||||||
float tsens_value;
|
|
||||||
while (cnt--) {
|
|
||||||
temperature_sensor_enable(temp_sensor);
|
|
||||||
TEST_ESP_OK(temperature_sensor_get_celsius(temp_sensor, &tsens_value));
|
|
||||||
ESP_LOGI(TAG, "Temperature value %.02f ℃", tsens_value);
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
|
||||||
TEST_ESP_OK(temperature_sensor_disable(temp_sensor));
|
|
||||||
}
|
|
||||||
|
|
||||||
adc_oneshot_unit_handle_t adc1_handle;
|
temp_sensor_test(temp_sensor);
|
||||||
|
|
||||||
|
//ADC oneshot work after temperature sensor
|
||||||
|
adc_oneshot_unit_handle_t adc_handle;
|
||||||
adc_oneshot_unit_init_cfg_t init_config1 = {
|
adc_oneshot_unit_init_cfg_t init_config1 = {
|
||||||
.unit_id = ADC_UNIT_1,
|
.unit_id = ADC_UNIT_1,
|
||||||
};
|
};
|
||||||
TEST_ESP_OK(adc_oneshot_new_unit(&init_config1, &adc1_handle));
|
TEST_ESP_OK(adc_oneshot_new_unit(&init_config1, &adc_handle));
|
||||||
|
|
||||||
//-------------ADC1 Config---------------//
|
|
||||||
adc_oneshot_chan_cfg_t config = {
|
adc_oneshot_chan_cfg_t config = {
|
||||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||||
.atten = EXAMPLE_ADC_ATTEN,
|
.atten = TEST_ADC_ATTEN,
|
||||||
};
|
};
|
||||||
TEST_ESP_OK(adc_oneshot_config_channel(adc1_handle, EXAMPLE_ADC1_CHAN0, &config));
|
TEST_ESP_OK(adc_oneshot_config_channel(adc_handle, TEST_ADC1_CHAN0, &config));
|
||||||
TEST_ESP_OK(adc_oneshot_config_channel(adc1_handle, EXAMPLE_ADC1_CHAN1, &config));
|
adc_oneshot_test(adc_handle);
|
||||||
|
TEST_ESP_OK(adc_oneshot_del_unit(adc_handle));
|
||||||
|
|
||||||
cnt = 2;
|
//Temperature sensor work after ADC oneshot
|
||||||
while (cnt--) {
|
temp_sensor_test(temp_sensor);
|
||||||
TEST_ESP_OK(adc_oneshot_read(adc1_handle, EXAMPLE_ADC1_CHAN0, &adc_raw[0][0]));
|
TEST_ESP_OK(temperature_sensor_disable(temp_sensor));
|
||||||
ESP_LOGI(TAG, "ADC%d Channel[%d] Raw Data: %d", ADC_UNIT_1 + 1, EXAMPLE_ADC1_CHAN0, adc_raw[0][0]);
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_ESP_OK(adc_oneshot_del_unit(adc1_handle));
|
|
||||||
|
|
||||||
cnt = 2;
|
|
||||||
while (cnt--) {
|
|
||||||
temperature_sensor_enable(temp_sensor);
|
|
||||||
TEST_ESP_OK(temperature_sensor_get_celsius(temp_sensor, &tsens_value));
|
|
||||||
ESP_LOGI(TAG, "Temperature value %.02f ℃", tsens_value);
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
|
||||||
TEST_ESP_OK(temperature_sensor_disable(temp_sensor));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_ESP_OK(temperature_sensor_uninstall(temp_sensor));
|
TEST_ESP_OK(temperature_sensor_uninstall(temp_sensor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SOC_ADC_DMA_SUPPORTED
|
||||||
|
#if (SOC_ADC_DIGI_RESULT_BYTES == 2)
|
||||||
|
#define ADC_DRIVER_TEST_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE1
|
||||||
|
#define ADC_DRIVER_TEST_GET_CHANNEL(p_data) ((p_data)->type1.channel)
|
||||||
|
#else
|
||||||
|
#define ADC_DRIVER_TEST_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
|
||||||
|
#define ADC_DRIVER_TEST_GET_CHANNEL(p_data) ((p_data)->type2.channel)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define TEST_ADC_BUF_SIZE 256
|
||||||
|
|
||||||
|
TEST_CASE("Test temperature sensor work with ADC continuous", "[adc]")
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Install temperature sensor, expected temp ranger range: 10~50 ℃");
|
||||||
|
temperature_sensor_handle_t temp_sensor = NULL;
|
||||||
|
temperature_sensor_config_t temp_sensor_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(10, 50);
|
||||||
|
TEST_ESP_OK(temperature_sensor_install(&temp_sensor_config, &temp_sensor));
|
||||||
|
TEST_ESP_OK(temperature_sensor_enable(temp_sensor));
|
||||||
|
|
||||||
|
temp_sensor_test(temp_sensor);
|
||||||
|
|
||||||
|
adc_continuous_handle_t handle = NULL;
|
||||||
|
adc_continuous_handle_cfg_t adc_config = {
|
||||||
|
.max_store_buf_size = TEST_ADC_BUF_SIZE,
|
||||||
|
.conv_frame_size = TEST_ADC_BUF_SIZE,
|
||||||
|
};
|
||||||
|
TEST_ESP_OK(adc_continuous_new_handle(&adc_config, &handle));
|
||||||
|
|
||||||
|
adc_continuous_config_t dig_cfg = {
|
||||||
|
.sample_freq_hz = 50 * 1000,
|
||||||
|
.conv_mode = ADC_CONV_SINGLE_UNIT_1,
|
||||||
|
.format = ADC_DRIVER_TEST_OUTPUT_TYPE,
|
||||||
|
};
|
||||||
|
adc_digi_pattern_config_t adc_pattern[SOC_ADC_PATT_LEN_MAX] = {0};
|
||||||
|
adc_pattern[0].atten = ADC_ATTEN_DB_12;
|
||||||
|
adc_pattern[0].channel = TEST_ADC1_CHAN0;
|
||||||
|
adc_pattern[0].unit = ADC_UNIT_1;
|
||||||
|
adc_pattern[0].bit_width = SOC_ADC_DIGI_MAX_BITWIDTH;
|
||||||
|
dig_cfg.adc_pattern = adc_pattern;
|
||||||
|
dig_cfg.pattern_num = 1;
|
||||||
|
TEST_ESP_OK(adc_continuous_config(handle, &dig_cfg));
|
||||||
|
|
||||||
|
uint8_t* result = malloc(TEST_ADC_BUF_SIZE);
|
||||||
|
TEST_ASSERT(result);
|
||||||
|
|
||||||
|
uint32_t ret_num = 0;
|
||||||
|
TEST_ESP_OK(adc_continuous_start(handle));
|
||||||
|
|
||||||
|
temp_sensor_test(temp_sensor);
|
||||||
|
|
||||||
|
//ADC continuous work after temperature sensor
|
||||||
|
TEST_ESP_OK(adc_continuous_read(handle, result, TEST_ADC_BUF_SIZE, &ret_num, ADC_MAX_DELAY));
|
||||||
|
TEST_ASSERT_EQUAL(TEST_ADC_BUF_SIZE, ret_num);
|
||||||
|
for (int i = 0; i < ret_num; i += SOC_ADC_DIGI_RESULT_BYTES) {
|
||||||
|
adc_digi_output_data_t *p = (void*)&result[i];
|
||||||
|
uint32_t chan_num = ADC_DRIVER_TEST_GET_CHANNEL(p);
|
||||||
|
TEST_ASSERT(chan_num < SOC_ADC_CHANNEL_NUM(ADC_UNIT_1));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Temperature sensor work after ADC continuous read
|
||||||
|
temp_sensor_test(temp_sensor);
|
||||||
|
|
||||||
|
TEST_ESP_OK(adc_continuous_stop(handle));
|
||||||
|
|
||||||
|
//Temperature sensor work after ADC continuous stop
|
||||||
|
temp_sensor_test(temp_sensor);
|
||||||
|
|
||||||
|
//Temperature sensor work after ADC continuous deinit
|
||||||
|
temp_sensor_test(temp_sensor);
|
||||||
|
|
||||||
|
TEST_ESP_OK(temperature_sensor_disable(temp_sensor));
|
||||||
|
TEST_ESP_OK(temperature_sensor_uninstall(temp_sensor));
|
||||||
|
TEST_ESP_OK(adc_continuous_deinit(handle));
|
||||||
|
free(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SOC_ADC_DMA_SUPPORTED
|
||||||
|
#endif // SOC_TEMP_SENSOR_SUPPORTED && SOC_ADC_SUPPORTED
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ void adc_apb_periph_claim(void)
|
|||||||
//enable ADC digital part
|
//enable ADC digital part
|
||||||
periph_module_enable(PERIPH_SARADC_MODULE);
|
periph_module_enable(PERIPH_SARADC_MODULE);
|
||||||
//reset ADC digital part
|
//reset ADC digital part
|
||||||
periph_module_reset(PERIPH_SARADC_MODULE);
|
sar_periph_ctrl_adc_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
portEXIT_CRITICAL(&s_spinlock);
|
portEXIT_CRITICAL(&s_spinlock);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -102,6 +102,34 @@ void sar_periph_ctrl_power_enable(void);
|
|||||||
*/
|
*/
|
||||||
void sar_periph_ctrl_power_disable(void);
|
void sar_periph_ctrl_power_disable(void);
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* ADC Reset
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @note For chips that temperature sensor uses part of ADC registers,
|
||||||
|
* ADC reset will reset these temperature sensor registers.
|
||||||
|
* So we need to backup and restore these temperature sensor registers when ADC reset.
|
||||||
|
* And in case temperature sensor result error during ADC reset,
|
||||||
|
* we need to acquire a lock to prevent temperature sensor readings during ADC reset.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Acquire ADC reset lock
|
||||||
|
*/
|
||||||
|
void adc_reset_lock_acquire(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Release ADC reset lock
|
||||||
|
*/
|
||||||
|
void adc_reset_lock_release(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reset ADC module
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void sar_periph_ctrl_adc_reset(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -18,7 +18,11 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "esp_private/sar_periph_ctrl.h"
|
#include "esp_private/sar_periph_ctrl.h"
|
||||||
|
#include "esp_private/critical_section.h"
|
||||||
|
#include "esp_private/adc_share_hw_ctrl.h"
|
||||||
|
#include "esp_private/periph_ctrl.h"
|
||||||
#include "hal/sar_ctrl_ll.h"
|
#include "hal/sar_ctrl_ll.h"
|
||||||
|
#include "hal/adc_ll.h"
|
||||||
|
|
||||||
static const char *TAG = "sar_periph_ctrl";
|
static const char *TAG = "sar_periph_ctrl";
|
||||||
extern portMUX_TYPE rtc_spinlock;
|
extern portMUX_TYPE rtc_spinlock;
|
||||||
@@ -115,3 +119,21 @@ void sar_periph_ctrl_adc_continuous_power_release(void)
|
|||||||
{
|
{
|
||||||
s_sar_power_release();
|
s_sar_power_release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* ADC Reset
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void sar_periph_ctrl_adc_reset(void)
|
||||||
|
{
|
||||||
|
periph_module_reset(PERIPH_SARADC_MODULE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_acquire(void)
|
||||||
|
{
|
||||||
|
// Empty implementation
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_release(void)
|
||||||
|
{
|
||||||
|
// Empty implementation
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -19,6 +19,9 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "esp_private/sar_periph_ctrl.h"
|
#include "esp_private/sar_periph_ctrl.h"
|
||||||
|
#include "esp_private/critical_section.h"
|
||||||
|
#include "esp_private/adc_share_hw_ctrl.h"
|
||||||
|
#include "esp_private/periph_ctrl.h"
|
||||||
#include "hal/sar_ctrl_ll.h"
|
#include "hal/sar_ctrl_ll.h"
|
||||||
#include "hal/adc_ll.h"
|
#include "hal/adc_ll.h"
|
||||||
|
|
||||||
@@ -128,3 +131,21 @@ void sar_periph_ctrl_adc_continuous_power_release(void)
|
|||||||
{
|
{
|
||||||
abort(); //c2 not supported, should never reach here
|
abort(); //c2 not supported, should never reach here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* ADC Reset
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void sar_periph_ctrl_adc_reset(void)
|
||||||
|
{
|
||||||
|
periph_module_reset(PERIPH_SARADC_MODULE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_acquire(void)
|
||||||
|
{
|
||||||
|
// Empty implementation
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_release(void)
|
||||||
|
{
|
||||||
|
// Empty implementation
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -15,15 +15,21 @@
|
|||||||
* - Temp Sensor
|
* - Temp Sensor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/lock.h>
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "esp_private/sar_periph_ctrl.h"
|
#include "esp_private/sar_periph_ctrl.h"
|
||||||
|
#include "esp_private/critical_section.h"
|
||||||
|
#include "esp_private/adc_share_hw_ctrl.h"
|
||||||
|
#include "esp_private/periph_ctrl.h"
|
||||||
#include "hal/sar_ctrl_ll.h"
|
#include "hal/sar_ctrl_ll.h"
|
||||||
#include "hal/adc_ll.h"
|
#include "hal/adc_ll.h"
|
||||||
|
#include "hal/temperature_sensor_ll.h"
|
||||||
|
|
||||||
static const char *TAG = "sar_periph_ctrl";
|
static const char *TAG = "sar_periph_ctrl";
|
||||||
extern portMUX_TYPE rtc_spinlock;
|
extern portMUX_TYPE rtc_spinlock;
|
||||||
|
static _lock_t adc_reset_lock;
|
||||||
|
|
||||||
|
|
||||||
void sar_periph_ctrl_init(void)
|
void sar_periph_ctrl_init(void)
|
||||||
@@ -128,3 +134,33 @@ void sar_periph_ctrl_adc_continuous_power_release(void)
|
|||||||
{
|
{
|
||||||
s_sar_adc_power_release();
|
s_sar_adc_power_release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* ADC Reset
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void sar_periph_ctrl_adc_reset(void)
|
||||||
|
{
|
||||||
|
// Acquire ADC reset lock to prevent temperature sensor readings during ADC reset
|
||||||
|
adc_reset_lock_acquire();
|
||||||
|
|
||||||
|
// Save temperature sensor related register values before ADC reset
|
||||||
|
tsens_ll_reg_values_t saved_tsens_regs = {};
|
||||||
|
tsens_ll_backup_registers(&saved_tsens_regs);
|
||||||
|
periph_module_reset(PERIPH_SARADC_MODULE);
|
||||||
|
// Restore temperature sensor related register values after ADC reset
|
||||||
|
periph_module_reset(PERIPH_TEMPSENSOR_MODULE);
|
||||||
|
tsens_ll_restore_registers(&saved_tsens_regs);
|
||||||
|
|
||||||
|
// Release ADC reset lock after ADC reset is complete
|
||||||
|
adc_reset_lock_release();
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_acquire(void)
|
||||||
|
{
|
||||||
|
_lock_acquire(&adc_reset_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_release(void)
|
||||||
|
{
|
||||||
|
_lock_release(&adc_reset_lock);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -19,11 +19,16 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "esp_private/sar_periph_ctrl.h"
|
#include "esp_private/sar_periph_ctrl.h"
|
||||||
#include "esp_private/esp_modem_clock.h"
|
#include "esp_private/esp_modem_clock.h"
|
||||||
|
#include "esp_private/critical_section.h"
|
||||||
|
#include "esp_private/adc_share_hw_ctrl.h"
|
||||||
|
#include "esp_private/periph_ctrl.h"
|
||||||
#include "hal/sar_ctrl_ll.h"
|
#include "hal/sar_ctrl_ll.h"
|
||||||
|
#include "hal/adc_ll.h"
|
||||||
|
#include "hal/temperature_sensor_ll.h"
|
||||||
|
|
||||||
static const char *TAG = "sar_periph_ctrl";
|
static const char *TAG = "sar_periph_ctrl";
|
||||||
extern portMUX_TYPE rtc_spinlock;
|
extern portMUX_TYPE rtc_spinlock;
|
||||||
|
static _lock_t adc_reset_lock;
|
||||||
|
|
||||||
void sar_periph_ctrl_init(void)
|
void sar_periph_ctrl_init(void)
|
||||||
{
|
{
|
||||||
@@ -117,3 +122,33 @@ void sar_periph_ctrl_adc_continuous_power_release(void)
|
|||||||
{
|
{
|
||||||
s_sar_power_release();
|
s_sar_power_release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* ADC Reset
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void sar_periph_ctrl_adc_reset(void)
|
||||||
|
{
|
||||||
|
// Acquire ADC reset lock to prevent temperature sensor readings during ADC reset
|
||||||
|
adc_reset_lock_acquire();
|
||||||
|
|
||||||
|
// Save temperature sensor related register values before ADC reset
|
||||||
|
tsens_ll_reg_values_t saved_tsens_regs = {};
|
||||||
|
tsens_ll_backup_registers(&saved_tsens_regs);
|
||||||
|
periph_module_reset(PERIPH_SARADC_MODULE);
|
||||||
|
// Restore temperature sensor related register values after ADC reset
|
||||||
|
periph_module_reset(PERIPH_TEMPSENSOR_MODULE);
|
||||||
|
tsens_ll_restore_registers(&saved_tsens_regs);
|
||||||
|
|
||||||
|
// Release ADC reset lock after ADC reset is complete
|
||||||
|
adc_reset_lock_release();
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_acquire(void)
|
||||||
|
{
|
||||||
|
_lock_acquire(&adc_reset_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_release(void)
|
||||||
|
{
|
||||||
|
_lock_release(&adc_reset_lock);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -18,10 +18,16 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "esp_private/sar_periph_ctrl.h"
|
#include "esp_private/sar_periph_ctrl.h"
|
||||||
#include "esp_private/esp_modem_clock.h"
|
#include "esp_private/esp_modem_clock.h"
|
||||||
|
#include "esp_private/critical_section.h"
|
||||||
|
#include "esp_private/adc_share_hw_ctrl.h"
|
||||||
#include "hal/sar_ctrl_ll.h"
|
#include "hal/sar_ctrl_ll.h"
|
||||||
|
#include "hal/adc_ll.h"
|
||||||
|
#include "hal/temperature_sensor_ll.h"
|
||||||
|
#include "esp_private/periph_ctrl.h"
|
||||||
|
|
||||||
static const char *TAG = "sar_periph_ctrl";
|
static const char *TAG = "sar_periph_ctrl";
|
||||||
extern portMUX_TYPE rtc_spinlock;
|
extern portMUX_TYPE rtc_spinlock;
|
||||||
|
static _lock_t adc_reset_lock;
|
||||||
|
|
||||||
|
|
||||||
void sar_periph_ctrl_init(void)
|
void sar_periph_ctrl_init(void)
|
||||||
@@ -116,3 +122,34 @@ void sar_periph_ctrl_adc_continuous_power_release(void)
|
|||||||
{
|
{
|
||||||
s_sar_power_release();
|
s_sar_power_release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* ADC Reset
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void sar_periph_ctrl_adc_reset(void)
|
||||||
|
{
|
||||||
|
// Acquire ADC reset lock to prevent temperature sensor readings during ADC reset
|
||||||
|
adc_reset_lock_acquire();
|
||||||
|
|
||||||
|
// Save temperature sensor related register values before ADC reset
|
||||||
|
tsens_ll_reg_values_t saved_tsens_regs = {};
|
||||||
|
tsens_ll_backup_registers(&saved_tsens_regs);
|
||||||
|
periph_module_reset(PERIPH_SARADC_MODULE);
|
||||||
|
// Restore temperature sensor related register values after ADC reset
|
||||||
|
periph_module_reset(PERIPH_TEMPSENSOR_MODULE);
|
||||||
|
tsens_ll_restore_registers(&saved_tsens_regs);
|
||||||
|
|
||||||
|
// Release ADC reset lock after ADC reset is complete
|
||||||
|
adc_reset_lock_release();
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_acquire(void)
|
||||||
|
{
|
||||||
|
_lock_acquire(&adc_reset_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_release(void)
|
||||||
|
{
|
||||||
|
_lock_release(&adc_reset_lock);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -19,6 +19,10 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "esp_private/sar_periph_ctrl.h"
|
#include "esp_private/sar_periph_ctrl.h"
|
||||||
|
#include "esp_private/regi2c_ctrl.h"
|
||||||
|
#include "esp_private/critical_section.h"
|
||||||
|
#include "esp_private/adc_share_hw_ctrl.h"
|
||||||
|
#include "esp_private/periph_ctrl.h"
|
||||||
#include "hal/sar_ctrl_ll.h"
|
#include "hal/sar_ctrl_ll.h"
|
||||||
#include "hal/adc_ll.h"
|
#include "hal/adc_ll.h"
|
||||||
|
|
||||||
@@ -52,34 +56,48 @@ void sar_periph_ctrl_power_disable(void)
|
|||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* PWDET Power
|
* PWDET Power
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
static int s_pwdet_power_on_cnt;
|
static int s_sar_power_on_cnt;
|
||||||
|
|
||||||
void sar_periph_ctrl_pwdet_power_acquire(void)
|
void s_sar_power_acquire(void)
|
||||||
{
|
{
|
||||||
portENTER_CRITICAL_SAFE(&rtc_spinlock);
|
portENTER_CRITICAL_SAFE(&rtc_spinlock);
|
||||||
s_pwdet_power_on_cnt++;
|
s_sar_power_on_cnt++;
|
||||||
if (s_pwdet_power_on_cnt == 1) {
|
if (s_sar_power_on_cnt == 1) {
|
||||||
sar_ctrl_ll_set_power_mode_from_pwdet(SAR_CTRL_LL_POWER_ON);
|
sar_ctrl_ll_set_power_mode_from_pwdet(SAR_CTRL_LL_POWER_ON);
|
||||||
|
regi2c_saradc_enable();
|
||||||
}
|
}
|
||||||
portEXIT_CRITICAL_SAFE(&rtc_spinlock);
|
portEXIT_CRITICAL_SAFE(&rtc_spinlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void s_sar_power_release(void)
|
||||||
|
{
|
||||||
|
portENTER_CRITICAL_SAFE(&rtc_spinlock);
|
||||||
|
s_sar_power_on_cnt--;
|
||||||
|
/* Sanity check */
|
||||||
|
if (s_sar_power_on_cnt < 0) {
|
||||||
|
portEXIT_CRITICAL(&rtc_spinlock);
|
||||||
|
ESP_LOGE(TAG, "%s called, but s_sar_power_on_cnt == 0", __func__);
|
||||||
|
abort();
|
||||||
|
} else if (s_sar_power_on_cnt == 0) {
|
||||||
|
sar_ctrl_ll_set_power_mode_from_pwdet(SAR_CTRL_LL_POWER_FSM);
|
||||||
|
}
|
||||||
|
regi2c_saradc_disable();
|
||||||
|
portEXIT_CRITICAL_SAFE(&rtc_spinlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* PWDET Power
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void sar_periph_ctrl_pwdet_power_acquire(void)
|
||||||
|
{
|
||||||
|
s_sar_power_acquire();
|
||||||
|
}
|
||||||
|
|
||||||
void sar_periph_ctrl_pwdet_power_release(void)
|
void sar_periph_ctrl_pwdet_power_release(void)
|
||||||
{
|
{
|
||||||
portENTER_CRITICAL_SAFE(&rtc_spinlock);
|
s_sar_power_release();
|
||||||
s_pwdet_power_on_cnt--;
|
|
||||||
/* Sanity check */
|
|
||||||
if (s_pwdet_power_on_cnt < 0) {
|
|
||||||
portEXIT_CRITICAL(&rtc_spinlock);
|
|
||||||
ESP_LOGE(TAG, "%s called, but s_pwdet_power_on_cnt == 0", __func__);
|
|
||||||
abort();
|
|
||||||
} else if (s_pwdet_power_on_cnt == 0) {
|
|
||||||
sar_ctrl_ll_set_power_mode_from_pwdet(SAR_CTRL_LL_POWER_FSM);
|
|
||||||
}
|
|
||||||
portEXIT_CRITICAL_SAFE(&rtc_spinlock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* ADC Power
|
* ADC Power
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
@@ -102,3 +120,21 @@ void sar_periph_ctrl_adc_continuous_power_release(void)
|
|||||||
{
|
{
|
||||||
adc_ll_digi_set_power_manage(ADC_LL_POWER_BY_FSM);
|
adc_ll_digi_set_power_manage(ADC_LL_POWER_BY_FSM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* ADC Reset
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void sar_periph_ctrl_adc_reset(void)
|
||||||
|
{
|
||||||
|
periph_module_reset(PERIPH_SARADC_MODULE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_acquire(void)
|
||||||
|
{
|
||||||
|
// Empty implementation
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_release(void)
|
||||||
|
{
|
||||||
|
// Empty implementation
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -19,6 +19,10 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "esp_private/sar_periph_ctrl.h"
|
#include "esp_private/sar_periph_ctrl.h"
|
||||||
|
#include "esp_private/regi2c_ctrl.h"
|
||||||
|
#include "esp_private/critical_section.h"
|
||||||
|
#include "esp_private/adc_share_hw_ctrl.h"
|
||||||
|
#include "esp_private/periph_ctrl.h"
|
||||||
#include "hal/sar_ctrl_ll.h"
|
#include "hal/sar_ctrl_ll.h"
|
||||||
#include "hal/adc_ll.h"
|
#include "hal/adc_ll.h"
|
||||||
|
|
||||||
@@ -51,7 +55,7 @@ void sar_periph_ctrl_power_disable(void)
|
|||||||
/**
|
/**
|
||||||
* This gets incremented when s_sar_power_acquire() is called,
|
* This gets incremented when s_sar_power_acquire() is called,
|
||||||
* and decremented when s_sar_power_release() is called.
|
* and decremented when s_sar_power_release() is called.
|
||||||
* PWDET is powered down when the value reaches zero.
|
* PWDET and REG_I2C are powered down when the value reaches zero.
|
||||||
* Should be modified within critical section.
|
* Should be modified within critical section.
|
||||||
*/
|
*/
|
||||||
static int s_sar_power_on_cnt;
|
static int s_sar_power_on_cnt;
|
||||||
@@ -59,6 +63,7 @@ static int s_sar_power_on_cnt;
|
|||||||
static void s_sar_power_acquire(void)
|
static void s_sar_power_acquire(void)
|
||||||
{
|
{
|
||||||
portENTER_CRITICAL_SAFE(&rtc_spinlock);
|
portENTER_CRITICAL_SAFE(&rtc_spinlock);
|
||||||
|
regi2c_saradc_enable();
|
||||||
s_sar_power_on_cnt++;
|
s_sar_power_on_cnt++;
|
||||||
if (s_sar_power_on_cnt == 1) {
|
if (s_sar_power_on_cnt == 1) {
|
||||||
sar_ctrl_ll_set_power_mode(SAR_CTRL_LL_POWER_ON);
|
sar_ctrl_ll_set_power_mode(SAR_CTRL_LL_POWER_ON);
|
||||||
@@ -77,6 +82,7 @@ static void s_sar_power_release(void)
|
|||||||
} else if (s_sar_power_on_cnt == 0) {
|
} else if (s_sar_power_on_cnt == 0) {
|
||||||
sar_ctrl_ll_set_power_mode(SAR_CTRL_LL_POWER_FSM);
|
sar_ctrl_ll_set_power_mode(SAR_CTRL_LL_POWER_FSM);
|
||||||
}
|
}
|
||||||
|
regi2c_saradc_disable();
|
||||||
portEXIT_CRITICAL_SAFE(&rtc_spinlock);
|
portEXIT_CRITICAL_SAFE(&rtc_spinlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,3 +123,21 @@ void sar_periph_ctrl_adc_continuous_power_release(void)
|
|||||||
{
|
{
|
||||||
s_sar_power_release();
|
s_sar_power_release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* ADC Reset
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void sar_periph_ctrl_adc_reset(void)
|
||||||
|
{
|
||||||
|
periph_module_reset(PERIPH_SARADC_MODULE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_acquire(void)
|
||||||
|
{
|
||||||
|
// Empty implementation
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_reset_lock_release(void)
|
||||||
|
{
|
||||||
|
// Empty implementation
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2020-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -133,6 +133,36 @@ static inline void temperature_sensor_ll_set_clk_div(uint8_t clk_div)
|
|||||||
HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.apb_tsens_ctrl, tsens_clk_div, clk_div);
|
HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.apb_tsens_ctrl, tsens_clk_div, clk_div);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Structure for temperature sensor related register values
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint32_t tsens_ctrl; // Temperature sensor control register (APB_SARADC_APB_TSENS_CTRL_REG)
|
||||||
|
uint32_t tsens_ctrl2; // Temperature sensor control register 2 (APB_SARADC_THRES1_HIGH_INT_ST_M)
|
||||||
|
} tsens_ll_reg_values_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read temperature sensor related ADC register values for backup
|
||||||
|
*
|
||||||
|
* @param reg_values Output parameter, pointer to structure for storing register values
|
||||||
|
*/
|
||||||
|
static inline void tsens_ll_backup_registers(tsens_ll_reg_values_t *reg_values)
|
||||||
|
{
|
||||||
|
reg_values->tsens_ctrl = APB_SARADC.apb_tsens_ctrl.val;
|
||||||
|
reg_values->tsens_ctrl2 = APB_SARADC.apb_tsens_ctrl2.val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Restore temperature sensor related ADC register values from backup
|
||||||
|
*
|
||||||
|
* @param reg_values Input parameter, pointer to structure containing register values to restore
|
||||||
|
*/
|
||||||
|
static inline void tsens_ll_restore_registers(const tsens_ll_reg_values_t *reg_values)
|
||||||
|
{
|
||||||
|
APB_SARADC.apb_tsens_ctrl.val = reg_values->tsens_ctrl;
|
||||||
|
APB_SARADC.apb_tsens_ctrl2.val = reg_values->tsens_ctrl2;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -232,6 +232,60 @@ static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate)
|
|||||||
HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.tsens_sample, saradc_tsens_sample_rate, rate);
|
HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.tsens_sample, saradc_tsens_sample_rate, rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Structure for temperature sensor related register values
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint32_t tsens_ctrl; // Temperature sensor control register (APB_SARADC_APB_TSENS_CTRL_REG)
|
||||||
|
uint32_t tsens_ctrl2; // Temperature sensor control register 2 (APB_SARADC_TSENS_CTRL2_REG)
|
||||||
|
uint32_t tsens_wake; // Temperature sensor wake register (APB_TSENS_WAKE_REG)
|
||||||
|
uint32_t tsens_sample; // Temperature sensor sample register (APB_TSENS_SAMPLE_REG)
|
||||||
|
uint32_t cali; // ADC calibration register
|
||||||
|
uint32_t clkm_conf; // ADC clock configuration register
|
||||||
|
uint32_t int_ena; // ADC interrupt enable register
|
||||||
|
uint32_t int_raw; // ADC interrupt raw status register
|
||||||
|
uint32_t int_st; // ADC interrupt status register
|
||||||
|
uint32_t int_clr; // ADC interrupt clear register
|
||||||
|
} tsens_ll_reg_values_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read temperature sensor related ADC register values for backup
|
||||||
|
*
|
||||||
|
* @param reg_values Output parameter, pointer to structure for storing register values
|
||||||
|
*/
|
||||||
|
static inline void tsens_ll_backup_registers(tsens_ll_reg_values_t *reg_values)
|
||||||
|
{
|
||||||
|
reg_values->tsens_ctrl = APB_SARADC.saradc_apb_tsens_ctrl.val;
|
||||||
|
reg_values->tsens_ctrl2 = APB_SARADC.saradc_tsens_ctrl2.val;
|
||||||
|
reg_values->tsens_wake = APB_SARADC.tsens_wake.val;
|
||||||
|
reg_values->tsens_sample = APB_SARADC.tsens_sample.val;
|
||||||
|
reg_values->cali = APB_SARADC.saradc_cali.val;
|
||||||
|
reg_values->clkm_conf = APB_SARADC.saradc_clkm_conf.val;
|
||||||
|
reg_values->int_ena = APB_SARADC.saradc_int_ena.val;
|
||||||
|
reg_values->int_raw = APB_SARADC.saradc_int_raw.val;
|
||||||
|
reg_values->int_st = APB_SARADC.saradc_int_st.val;
|
||||||
|
reg_values->int_clr = APB_SARADC.saradc_int_clr.val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Restore temperature sensor related ADC register values from backup
|
||||||
|
*
|
||||||
|
* @param reg_values Input parameter, pointer to structure containing register values to restore
|
||||||
|
*/
|
||||||
|
static inline void tsens_ll_restore_registers(const tsens_ll_reg_values_t *reg_values)
|
||||||
|
{
|
||||||
|
APB_SARADC.saradc_apb_tsens_ctrl.val = reg_values->tsens_ctrl;
|
||||||
|
APB_SARADC.saradc_tsens_ctrl2.val = reg_values->tsens_ctrl2;
|
||||||
|
APB_SARADC.tsens_wake.val = reg_values->tsens_wake;
|
||||||
|
APB_SARADC.tsens_sample.val = reg_values->tsens_sample;
|
||||||
|
APB_SARADC.saradc_cali.val = reg_values->cali;
|
||||||
|
APB_SARADC.saradc_clkm_conf.val = reg_values->clkm_conf;
|
||||||
|
APB_SARADC.saradc_int_ena.val = reg_values->int_ena;
|
||||||
|
APB_SARADC.saradc_int_raw.val = reg_values->int_raw;
|
||||||
|
APB_SARADC.saradc_int_st.val = reg_values->int_st;
|
||||||
|
APB_SARADC.saradc_int_clr.val = reg_values->int_clr;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -232,6 +232,42 @@ static inline void temperature_sensor_ll_set_sample_rate(uint16_t rate)
|
|||||||
HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.tsens_sample, saradc_tsens_sample_rate, rate);
|
HAL_FORCE_MODIFY_U32_REG_FIELD(APB_SARADC.tsens_sample, saradc_tsens_sample_rate, rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Structure for temperature sensor related register values
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint32_t tsens_ctrl; // Temperature sensor control register (APB_SARADC_APB_TSENS_CTRL_REG)
|
||||||
|
uint32_t tsens_ctrl2; // Temperature sensor control register 2 (APB_SARADC_TSENS_CTRL2_REG)
|
||||||
|
uint32_t tsens_wake; // Temperature sensor wake register (APB_TSENS_WAKE_REG)
|
||||||
|
uint32_t tsens_sample; // Temperature sensor sample register (APB_TSENS_SAMPLE_REG)
|
||||||
|
} tsens_ll_reg_values_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read temperature sensor related ADC register values for backup
|
||||||
|
*
|
||||||
|
* @param reg_values Output parameter, pointer to structure for storing register values
|
||||||
|
*/
|
||||||
|
static inline void tsens_ll_backup_registers(tsens_ll_reg_values_t *reg_values)
|
||||||
|
{
|
||||||
|
reg_values->tsens_ctrl = APB_SARADC.saradc_apb_tsens_ctrl.val;
|
||||||
|
reg_values->tsens_ctrl2 = APB_SARADC.saradc_tsens_ctrl2.val;
|
||||||
|
reg_values->tsens_wake = APB_SARADC.tsens_wake.val;
|
||||||
|
reg_values->tsens_sample = APB_SARADC.tsens_sample.val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Restore temperature sensor related ADC register values from backup
|
||||||
|
*
|
||||||
|
* @param reg_values Input parameter, pointer to structure containing register values to restore
|
||||||
|
*/
|
||||||
|
static inline void tsens_ll_restore_registers(const tsens_ll_reg_values_t *reg_values)
|
||||||
|
{
|
||||||
|
APB_SARADC.saradc_apb_tsens_ctrl.val = reg_values->tsens_ctrl;
|
||||||
|
APB_SARADC.saradc_tsens_ctrl2.val = reg_values->tsens_ctrl2;
|
||||||
|
APB_SARADC.tsens_wake.val = reg_values->tsens_wake;
|
||||||
|
APB_SARADC.tsens_sample.val = reg_values->tsens_sample;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user