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:42:11 +08:00
parent 5133b89183
commit 18091976ec
162 changed files with 1742 additions and 500 deletions
+8 -2
View File
@@ -162,7 +162,10 @@ void i2s_hal_calc_mclk_precise_division(uint32_t sclk, uint32_t mclk, hal_utils_
void _i2s_hal_set_tx_clock(i2s_hal_context_t *hal, const i2s_hal_clock_info_t *clk_info, i2s_clock_src_t clk_src, hal_utils_clk_div_t *ret_mclk_div);
/// 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 i2s_hal_set_tx_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; _i2s_hal_set_tx_clock(__VA_ARGS__)
#define i2s_hal_set_tx_clock(...) do { \
(void)__DECLARE_RCC_ATOMIC_ENV; \
_i2s_hal_set_tx_clock(__VA_ARGS__); \
} while(0)
#else
/**
* @brief Set tx channel clock
@@ -188,7 +191,10 @@ void _i2s_hal_set_rx_clock(i2s_hal_context_t *hal, const i2s_hal_clock_info_t *c
#if SOC_PERIPH_CLK_CTRL_SHARED
/// 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 i2s_hal_set_rx_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; _i2s_hal_set_rx_clock(__VA_ARGS__)
#define i2s_hal_set_rx_clock(...) do { \
(void)__DECLARE_RCC_ATOMIC_ENV; \
_i2s_hal_set_rx_clock(__VA_ARGS__); \
} while(0)
#else
#define i2s_hal_set_rx_clock(...) _i2s_hal_set_rx_clock(__VA_ARGS__)
#endif