mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-18 07:37:54 +00:00
fix(tsens,adc): Fix issue that disable adc will make temperature sensor crash,
Closes https://github.com/espressif/esp-idf/issues/12921
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
|
||||
*/
|
||||
@@ -18,42 +18,6 @@
|
||||
#include "soc/adc_periph.h"
|
||||
|
||||
static const char *TAG = "adc_common";
|
||||
static portMUX_TYPE s_spinlock = portMUX_INITIALIZER_UNLOCKED;
|
||||
extern portMUX_TYPE rtc_spinlock;
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* For those who use APB_SARADC periph
|
||||
*----------------------------------------------------------------------------*/
|
||||
static int s_adc_digi_ctrlr_cnt;
|
||||
|
||||
void adc_apb_periph_claim(void)
|
||||
{
|
||||
portENTER_CRITICAL(&s_spinlock);
|
||||
s_adc_digi_ctrlr_cnt++;
|
||||
if (s_adc_digi_ctrlr_cnt == 1) {
|
||||
//enable ADC digital part
|
||||
periph_module_enable(PERIPH_SARADC_MODULE);
|
||||
//reset ADC digital part
|
||||
periph_module_reset(PERIPH_SARADC_MODULE);
|
||||
}
|
||||
|
||||
portEXIT_CRITICAL(&s_spinlock);
|
||||
}
|
||||
|
||||
void adc_apb_periph_free(void)
|
||||
{
|
||||
portENTER_CRITICAL(&s_spinlock);
|
||||
s_adc_digi_ctrlr_cnt--;
|
||||
if (s_adc_digi_ctrlr_cnt == 0) {
|
||||
periph_module_disable(PERIPH_SARADC_MODULE);
|
||||
} else if (s_adc_digi_ctrlr_cnt < 0) {
|
||||
portEXIT_CRITICAL(&s_spinlock);
|
||||
ESP_LOGE(TAG, "%s called, but `s_adc_digi_ctrlr_cnt == 0`", __func__);
|
||||
abort();
|
||||
}
|
||||
|
||||
portEXIT_CRITICAL(&s_spinlock);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
ADC IOs
|
||||
|
Reference in New Issue
Block a user