mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
fix(adc): fix ESP32-P4 ADC2 oneshot error and refactor apb claim macor
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "hal/adc_hal.h"
|
||||
#include "hal/adc_hal_common.h"
|
||||
#include "soc/adc_periph.h"
|
||||
#include "hal/adc_ll.h"
|
||||
|
||||
static const char *TAG = "adc_common";
|
||||
|
||||
@@ -56,9 +57,12 @@ esp_err_t adc_channel_to_io(adc_unit_t unit_id, adc_channel_t channel, int * con
|
||||
---------------------------------------------------------------*/
|
||||
static __attribute__((constructor)) void adc_hw_calibration(void)
|
||||
{
|
||||
adc_apb_periph_claim();
|
||||
//Calculate all ICode
|
||||
for (int i = 0; i < SOC_ADC_PERIPH_NUM; i++) {
|
||||
if (ADC_LL_NEED_APB_PERIPH_CLAIM(i)) {
|
||||
adc_apb_periph_claim();
|
||||
}
|
||||
|
||||
adc_hal_calibration_init(i);
|
||||
for (int j = 0; j < SOC_ADC_ATTEN_NUM; j++) {
|
||||
/**
|
||||
@@ -73,7 +77,9 @@ static __attribute__((constructor)) void adc_hw_calibration(void)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (ADC_LL_NEED_APB_PERIPH_CLAIM(i)) {
|
||||
adc_apb_periph_free();
|
||||
}
|
||||
}
|
||||
adc_apb_periph_free();
|
||||
}
|
||||
#endif //#if SOC_ADC_CALIBRATION_V1_SUPPORTED
|
||||
|
||||
@@ -144,15 +144,15 @@ esp_err_t adc_oneshot_new_unit(const adc_oneshot_unit_init_cfg_t *init_config, a
|
||||
|
||||
adc_oneshot_hal_init(&(unit->hal), &config);
|
||||
|
||||
#if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
|
||||
//To enable the APB_SARADC periph if needed
|
||||
_lock_acquire(&s_ctx.mutex);
|
||||
s_ctx.apb_periph_ref_cnts++;
|
||||
if (s_ctx.apb_periph_ref_cnts == 1) {
|
||||
adc_apb_periph_claim();
|
||||
if (ADC_LL_NEED_APB_PERIPH_CLAIM(unit->unit_id)) {
|
||||
//To enable the APB_SARADC periph if needed
|
||||
_lock_acquire(&s_ctx.mutex);
|
||||
s_ctx.apb_periph_ref_cnts++;
|
||||
if (s_ctx.apb_periph_ref_cnts == 1) {
|
||||
adc_apb_periph_claim();
|
||||
}
|
||||
_lock_release(&s_ctx.mutex);
|
||||
}
|
||||
_lock_release(&s_ctx.mutex);
|
||||
#endif
|
||||
|
||||
if (init_config->ulp_mode == ADC_ULP_MODE_DISABLE) {
|
||||
sar_periph_ctrl_adc_oneshot_power_acquire();
|
||||
@@ -277,9 +277,6 @@ esp_err_t adc_oneshot_del_unit(adc_oneshot_unit_handle_t handle)
|
||||
s_ctx.units[handle->unit_id] = NULL;
|
||||
_lock_release(&s_ctx.mutex);
|
||||
|
||||
ESP_LOGD(TAG, "adc unit%"PRId32" is deleted", handle->unit_id);
|
||||
free(handle);
|
||||
|
||||
if (ulp_mode == ADC_ULP_MODE_DISABLE) {
|
||||
sar_periph_ctrl_adc_oneshot_power_release();
|
||||
} else {
|
||||
@@ -288,16 +285,19 @@ esp_err_t adc_oneshot_del_unit(adc_oneshot_unit_handle_t handle)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
|
||||
//To free the APB_SARADC periph if needed
|
||||
_lock_acquire(&s_ctx.mutex);
|
||||
s_ctx.apb_periph_ref_cnts--;
|
||||
assert(s_ctx.apb_periph_ref_cnts >= 0);
|
||||
if (s_ctx.apb_periph_ref_cnts == 0) {
|
||||
adc_apb_periph_free();
|
||||
if (ADC_LL_NEED_APB_PERIPH_CLAIM(handle->unit_id)) {
|
||||
//To free the APB_SARADC periph if needed
|
||||
_lock_acquire(&s_ctx.mutex);
|
||||
s_ctx.apb_periph_ref_cnts--;
|
||||
assert(s_ctx.apb_periph_ref_cnts >= 0);
|
||||
if (s_ctx.apb_periph_ref_cnts == 0) {
|
||||
adc_apb_periph_free();
|
||||
}
|
||||
_lock_release(&s_ctx.mutex);
|
||||
}
|
||||
_lock_release(&s_ctx.mutex);
|
||||
#endif
|
||||
|
||||
ESP_LOGD(TAG, "adc unit%"PRId32" is deleted", handle->unit_id);
|
||||
free(handle);
|
||||
|
||||
#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP
|
||||
//TODO: IDF-8475: Depends to SLEEP_RETENTION_MODULE_CLOCK_MODEM retention module after ADC retention supported.
|
||||
|
||||
Reference in New Issue
Block a user