diff --git a/components/esp_common/include/esp_macros.h b/components/esp_common/include/esp_macros.h index ee0ce4fc40..183c947a44 100644 --- a/components/esp_common/include/esp_macros.h +++ b/components/esp_common/include/esp_macros.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -11,6 +11,7 @@ This header contains various general purpose helper macros used across ESP-IDF */ #include #include "esp_assert.h" +#include "esp_compiler.h" #ifdef __cplusplus extern "C" { @@ -51,7 +52,7 @@ extern "C" { * - __GET_NTH_ARG__() takes args >= N (64) but only expand to Nth one (64th) * - __RSEQ_N__() is reverse sequential to N to add padding to have Nth * position is the same as the number of arguments - * - ##__VA_ARGS__ is used to deal with 0 paramerter (swallows comma) + * - ##__VA_ARGS__ is used to deal with 0 parameter (swallows comma) */ #ifndef __VA_NARG__ # define __VA_NARG__(...) __NARG__(_0, ##__VA_ARGS__, __RSEQ_N__()) @@ -98,6 +99,13 @@ ESP_STATIC_ASSERT(foo(42, 87) == 1, "CHOOSE_MACRO_VA_ARG() result does not match #undef foo_args #undef foo_no_args +#define ESP_INFINITE_LOOP() \ + do { \ + ESP_COMPILER_DIAGNOSTIC_PUSH_IGNORE("-Wanalyzer-infinite-loop") \ + while(1); \ + ESP_COMPILER_DIAGNOSTIC_POP("-Wanalyzer-infinite-loop") \ + } while(1) + #ifdef __cplusplus } #endif diff --git a/components/esp_system/panic.c b/components/esp_system/panic.c index 4abdac0437..35f50785e4 100644 --- a/components/esp_system/panic.c +++ b/components/esp_system/panic.c @@ -6,6 +6,7 @@ #include #include +#include "esp_macros.h" #include "esp_err.h" #include "esp_attr.h" #include "esp_compiler.h" @@ -442,7 +443,7 @@ void esp_panic_handler(panic_info_t *info) disable_all_wdts(); panic_print_str("CPU halted.\r\n"); esp_system_reset_modules_on_exit(); - while (1); + ESP_INFINITE_LOOP(); #endif /* CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT || CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT */ #endif /* CONFIG_ESP_SYSTEM_PANIC_GDBSTUB */ } @@ -467,7 +468,7 @@ void IRAM_ATTR __attribute__((noreturn, no_sanitize_undefined)) panic_abort(cons asm("unimp"); // should be an invalid operation on RISC-V targets #endif - while (1); + ESP_INFINITE_LOOP(); } /* Weak versions of reset reason hint functions. diff --git a/components/esp_system/port/arch/xtensa/debug_helpers.c b/components/esp_system/port/arch/xtensa/debug_helpers.c index adb02ccc3f..ecc12e87f8 100644 --- a/components/esp_system/port/arch/xtensa/debug_helpers.c +++ b/components/esp_system/port/arch/xtensa/debug_helpers.c @@ -65,7 +65,7 @@ esp_err_t IRAM_ATTR esp_backtrace_print_from_frame(int depth, const esp_backtrac } //Initialize stk_frame with first frame of stack - esp_backtrace_frame_t stk_frame = { 0 }; + esp_backtrace_frame_t stk_frame; memcpy(&stk_frame, frame, sizeof(esp_backtrace_frame_t)); print_str("\r\n\r\nBacktrace:", panic); @@ -197,7 +197,7 @@ esp_err_t IRAM_ATTR esp_backtrace_print_all_tasks(int depth) for (UBaseType_t task_idx = 0; task_idx < num_snapshots; task_idx++) { bool cur_running = false; TaskHandle_t task_hdl = (TaskHandle_t) task_snapshots[task_idx].pxTCB; - esp_backtrace_frame_t stk_frame; + esp_backtrace_frame_t stk_frame = {0}; // Check if the task is one of the currently running tasks for (BaseType_t core_id = 0; core_id < configNUMBER_OF_CORES; core_id++) { diff --git a/components/esp_system/port/brownout.c b/components/esp_system/port/brownout.c index b69550ba1d..0f062df377 100644 --- a/components/esp_system/port/brownout.c +++ b/components/esp_system/port/brownout.c @@ -11,6 +11,7 @@ #include "esp_private/system_internal.h" #include "esp_private/rtc_ctrl.h" #include "esp_private/spi_flash_os.h" +#include "esp_macros.h" #include "esp_log.h" #include "esp_cpu.h" #include "soc/soc.h" @@ -67,9 +68,8 @@ IRAM_ATTR static void rtc_brownout_isr_handler(void *arg) } esp_rom_software_reset_system(); - while (true) { - ; - } + + ESP_INFINITE_LOOP(); } #endif // CONFIG_ESP_SYSTEM_BROWNOUT_INTR diff --git a/components/esp_system/port/esp_system_chip.c b/components/esp_system/port/esp_system_chip.c index c382a9c377..864c2e4c23 100644 --- a/components/esp_system/port/esp_system_chip.c +++ b/components/esp_system/port/esp_system_chip.c @@ -5,6 +5,7 @@ */ #include +#include "esp_macros.h" #include "esp_cpu.h" #include "soc/soc.h" #include "soc/soc_caps.h" @@ -61,9 +62,8 @@ void IRAM_ATTR esp_restart_noos_dig(void) #endif // generate core reset esp_rom_software_reset_system(); - while (true) { - ; - } + + ESP_INFINITE_LOOP(); } #endif diff --git a/components/esp_system/port/panic_handler.c b/components/esp_system/port/panic_handler.c index de55b1cd8e..14d0f39711 100644 --- a/components/esp_system/port/panic_handler.c +++ b/components/esp_system/port/panic_handler.c @@ -6,6 +6,8 @@ #include +#include "esp_macros.h" + #include "esp_ipc_isr.h" #include "esp_private/system_internal.h" #include "esp_private/cache_utils.h" @@ -124,7 +126,7 @@ static void frame_to_panic_info(void *frame, panic_info_t *info, bool pseudo_exc FORCE_INLINE_ATTR __attribute__((__noreturn__)) void busy_wait(void) { - while (1) {;} // infinite loop + ESP_INFINITE_LOOP(); } #endif // !CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE diff --git a/components/esp_system/port/soc/esp32/system_internal.c b/components/esp_system/port/soc/esp32/system_internal.c index e0e837e3fa..75cae92511 100644 --- a/components/esp_system/port/soc/esp32/system_internal.c +++ b/components/esp_system/port/soc/esp32/system_internal.c @@ -1,10 +1,11 @@ /* - * SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include +#include "esp_macros.h" #include "esp_system.h" #include "esp_private/system_internal.h" #include "esp_attr.h" @@ -140,7 +141,6 @@ void IRAM_ATTR esp_restart_noos(void) esp_cpu_unstall(0); esp_rom_software_reset_cpu(1); } - while (true) { - ; - } + + ESP_INFINITE_LOOP(); } diff --git a/components/esp_system/port/soc/esp32c2/system_internal.c b/components/esp_system/port/soc/esp32c2/system_internal.c index c9ef82971c..afbd36dbe4 100644 --- a/components/esp_system/port/soc/esp32c2/system_internal.c +++ b/components/esp_system/port/soc/esp32c2/system_internal.c @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include #include "sdkconfig.h" +#include "esp_macros.h" #include "esp_system.h" #include "esp_private/system_internal.h" #include "esp_attr.h" @@ -95,7 +96,5 @@ void IRAM_ATTR esp_restart_noos(void) // Reset CPU esp_rom_software_reset_cpu(0); - while (true) { - ; - } + ESP_INFINITE_LOOP(); } diff --git a/components/esp_system/port/soc/esp32c3/system_internal.c b/components/esp_system/port/soc/esp32c3/system_internal.c index 15273a9b93..9364215d07 100644 --- a/components/esp_system/port/soc/esp32c3/system_internal.c +++ b/components/esp_system/port/soc/esp32c3/system_internal.c @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include #include "sdkconfig.h" +#include "esp_macros.h" #include "esp_system.h" #include "esp_private/system_internal.h" #include "esp_attr.h" @@ -107,7 +108,6 @@ void IRAM_ATTR esp_restart_noos(void) // Reset CPU esp_rom_software_reset_cpu(0); - while (true) { - ; - } + + ESP_INFINITE_LOOP(); } diff --git a/components/esp_system/port/soc/esp32c5/system_internal.c b/components/esp_system/port/soc/esp32c5/system_internal.c index 7c0d9875ff..b00e12cc3f 100644 --- a/components/esp_system/port/soc/esp32c5/system_internal.c +++ b/components/esp_system/port/soc/esp32c5/system_internal.c @@ -6,6 +6,7 @@ #include #include "sdkconfig.h" +#include "esp_macros.h" #include "esp_system.h" #include "esp_private/system_internal.h" #include "esp_attr.h" @@ -113,7 +114,6 @@ void IRAM_ATTR esp_restart_noos(void) // Reset PRO CPU esp_rom_software_reset_cpu(0); - while (true) { - ; - } + + ESP_INFINITE_LOOP(); } diff --git a/components/esp_system/port/soc/esp32c6/system_internal.c b/components/esp_system/port/soc/esp32c6/system_internal.c index 20ef9f373f..4f1d9f85e9 100644 --- a/components/esp_system/port/soc/esp32c6/system_internal.c +++ b/components/esp_system/port/soc/esp32c6/system_internal.c @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include #include "sdkconfig.h" +#include "esp_macros.h" #include "esp_system.h" #include "esp_private/system_internal.h" #include "esp_attr.h" @@ -112,7 +113,6 @@ void IRAM_ATTR esp_restart_noos(void) // Reset PRO CPU esp_rom_software_reset_cpu(0); - while (true) { - ; - } + + ESP_INFINITE_LOOP(); } diff --git a/components/esp_system/port/soc/esp32h2/system_internal.c b/components/esp_system/port/soc/esp32h2/system_internal.c index 9763d434b8..feceaa713b 100644 --- a/components/esp_system/port/soc/esp32h2/system_internal.c +++ b/components/esp_system/port/soc/esp32h2/system_internal.c @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include #include "sdkconfig.h" +#include "esp_macros.h" #include "esp_system.h" #include "esp_private/system_internal.h" #include "esp_attr.h" @@ -114,7 +115,5 @@ void IRAM_ATTR esp_restart_noos(void) // Reset CPU esp_rom_software_reset_cpu(0); - while (true) { - ; - } + ESP_INFINITE_LOOP(); } diff --git a/components/esp_system/port/soc/esp32p4/system_internal.c b/components/esp_system/port/soc/esp32p4/system_internal.c index 547f291810..79f5d23011 100644 --- a/components/esp_system/port/soc/esp32p4/system_internal.c +++ b/components/esp_system/port/soc/esp32p4/system_internal.c @@ -6,6 +6,7 @@ #include #include "sdkconfig.h" +#include "esp_macros.h" #include "esp_system.h" #include "esp_private/system_internal.h" #include "esp_attr.h" @@ -164,7 +165,5 @@ void IRAM_ATTR esp_restart_noos(void) } #endif - while (true) { - ; - } + ESP_INFINITE_LOOP(); } diff --git a/components/esp_system/port/soc/esp32s2/system_internal.c b/components/esp_system/port/soc/esp32s2/system_internal.c index 2a8d985d39..3de3bafdf1 100644 --- a/components/esp_system/port/soc/esp32s2/system_internal.c +++ b/components/esp_system/port/soc/esp32s2/system_internal.c @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include #include "sdkconfig.h" +#include "esp_macros.h" #include "esp_system.h" #include "esp_private/system_internal.h" #include "esp_attr.h" @@ -114,7 +115,6 @@ void IRAM_ATTR esp_restart_noos(void) // Reset CPUs esp_rom_software_reset_cpu(0); - while (true) { - ; - } + + ESP_INFINITE_LOOP(); } diff --git a/components/esp_system/port/soc/esp32s3/system_internal.c b/components/esp_system/port/soc/esp32s3/system_internal.c index 3450f4a6ce..ebdaccbcb2 100644 --- a/components/esp_system/port/soc/esp32s3/system_internal.c +++ b/components/esp_system/port/soc/esp32s3/system_internal.c @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include +#include "esp_macros.h" #include "sdkconfig.h" #include "esp_system.h" #include "esp_private/system_internal.h" @@ -155,7 +156,6 @@ void IRAM_ATTR esp_restart_noos(void) esp_rom_software_reset_cpu(1); } #endif - while (true) { - ; - } + + ESP_INFINITE_LOOP(); } diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c index f242a2db77..f0d62fa930 100644 --- a/components/esp_system/startup.c +++ b/components/esp_system/startup.c @@ -10,6 +10,7 @@ #include "esp_attr.h" #include "esp_err.h" #include "esp_compiler.h" +#include "esp_macros.h" #include "esp_system.h" #include "esp_log.h" @@ -213,5 +214,6 @@ static void start_cpu0_default(void) #endif esp_startup_start_app(); - while (1); + + ESP_INFINITE_LOOP(); }