fix(hal): fix the issue of dual-core contention for RTC_CNTL regs

This commit is contained in:
hebinglin
2026-03-02 12:22:15 +08:00
parent b291d5c0e9
commit 1d2ffd5941
23 changed files with 258 additions and 57 deletions
+20 -5
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -22,6 +22,7 @@
#include "hal/gpio_hal.h"
#include "esp_private/esp_gpio_reserve.h"
#include "esp_private/io_mux.h"
#include "esp_private/periph_ctrl.h"
#if (SOC_RTCIO_PIN_COUNT > 0)
#include "hal/rtc_io_hal.h"
@@ -37,6 +38,12 @@ static const char *GPIO_TAG = "gpio";
#define SOC_GPIO_SUPPORT_RTC_INDEPENDENT 0
#endif
#if SOC_RTC_CNTL_NEEDS_ATOMIC_ACCESS
#define RTC_CNTL_ATOMIC() PERIPH_RCC_ATOMIC()
#else
#define RTC_CNTL_ATOMIC()
#endif
typedef struct {
gpio_isr_t fn; /*!< isr function */
void *args; /*!< isr function args */
@@ -761,14 +768,18 @@ esp_err_t gpio_hold_dis(gpio_num_t gpio_num)
void gpio_deep_sleep_hold_en(void)
{
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
gpio_hal_deep_sleep_hold_en(gpio_context.gpio_hal);
RTC_CNTL_ATOMIC() {
gpio_hal_deep_sleep_hold_en(gpio_context.gpio_hal);
}
portEXIT_CRITICAL(&gpio_context.gpio_spinlock);
}
void gpio_deep_sleep_hold_dis(void)
{
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
gpio_hal_deep_sleep_hold_dis(gpio_context.gpio_hal);
RTC_CNTL_ATOMIC() {
gpio_hal_deep_sleep_hold_dis(gpio_context.gpio_hal);
}
portEXIT_CRITICAL(&gpio_context.gpio_spinlock);
}
#endif //!SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP
@@ -780,7 +791,9 @@ esp_err_t IRAM_ATTR gpio_force_hold_all()
rtc_gpio_force_hold_en_all();
#endif
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
gpio_hal_force_hold_all();
RTC_CNTL_ATOMIC() {
gpio_hal_force_hold_all();
}
portEXIT_CRITICAL(&gpio_context.gpio_spinlock);
return ESP_OK;
}
@@ -788,7 +801,9 @@ esp_err_t IRAM_ATTR gpio_force_hold_all()
esp_err_t IRAM_ATTR gpio_force_unhold_all()
{
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
gpio_hal_force_unhold_all();
RTC_CNTL_ATOMIC() {
gpio_hal_force_unhold_all();
}
portEXIT_CRITICAL(&gpio_context.gpio_spinlock);
#if SOC_RTCIO_HOLD_SUPPORTED
rtc_gpio_force_hold_dis_all();