fix(hal): Wrap LL macros with atomic env in do-while for control safety

- Standardize all LL macros using atomic env variables with `do { ... } while (0)`
- Prevent potential macro misuse in control flow constructs (e.g., if/else)
- Affected targets: esp32, esp32c2, esp32c5, esp32s3, esp32p4, etc.
- Affected modules include: LCD, I2S, TIMER, and others
This commit is contained in:
Yuan Yu
2025-05-22 14:41:19 +08:00
parent 5133b89183
commit 18091976ec
162 changed files with 1742 additions and 500 deletions

View File

@@ -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
*/
@@ -57,7 +57,10 @@ static inline void ledc_ll_enable_bus_clock(bool enable)
/// use a macro to wrap the function, force the caller to use it in a critical section
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
#define ledc_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; ledc_ll_enable_bus_clock(__VA_ARGS__)
#define ledc_ll_enable_bus_clock(...) do { \
(void)__DECLARE_RCC_ATOMIC_ENV; \
ledc_ll_enable_bus_clock(__VA_ARGS__); \
} while(0)
/**
* @brief Reset whole peripheral register to init value defined by HW design
@@ -73,7 +76,10 @@ static inline void ledc_ll_enable_reset_reg(bool enable)
/// use a macro to wrap the function, force the caller to use it in a critical section
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
#define ledc_ll_enable_reset_reg(...) (void)__DECLARE_RCC_ATOMIC_ENV; ledc_ll_enable_reset_reg(__VA_ARGS__)
#define ledc_ll_enable_reset_reg(...) do { \
(void)__DECLARE_RCC_ATOMIC_ENV; \
ledc_ll_enable_reset_reg(__VA_ARGS__); \
} while(0)
/**
* @brief Enable the power for LEDC memory block