From 879713d589b7a9966b4b50591d13aa2cd25582c2 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Wed, 25 Jun 2025 17:29:45 +0800 Subject: [PATCH] change(esp_hw_support): deprecate esp_sleep_get_wakeup_cause with esp_sleep_get_wakeup_causes --- .../touch_sensor_v2/main/test_touch_v2.c | 43 +++++++++---------- .../test_apps/gpio/main/test_gpio.c | 2 +- .../test_apps/uart/main/test_hp_uart_wakeup.c | 9 ++-- components/esp_hw_support/sleep_modes.c | 6 +-- .../rtc_8md256/main/test_rtc_8md256.c | 14 +----- .../rtc_power_modes/main/test_rtc_power.c | 15 +------ .../vad_wakeup/main/test_vad_wakeup.c | 16 +------ .../wakeup_tests/main/src/io_wakeup_cmd.c | 18 ++++---- components/touch_element/touch_element.c | 3 +- .../lp_core_basic_tests/main/test_lp_core.c | 4 +- .../ulp/test_apps/ulp_fsm/main/test_ulp.c | 10 ++--- .../test_apps/ulp_riscv/main/test_ulp_riscv.c | 9 ++-- .../components/cmd_system/cmd_system.c | 33 +++++++------- .../lowpower/vbat/main/vbat_example_main.c | 22 ++++++---- .../deep_sleep/main/esp_ot_sleepy_device.c | 25 +++++------ .../touch_sens_sleep/main/touch_sens_sleep.c | 4 +- .../components/cmd_system/cmd_system_sleep.c | 32 +++++++------- .../deep_sleep/main/deep_sleep_example_main.c | 24 ++++------- .../main/wake_stub_example_main.c | 2 +- .../main/light_sleep_example_main.c | 30 ++++++------- .../gpio/main/lp_core_gpio_example_main.c | 17 +++----- .../main/lp_core_pulse_counter_example_main.c | 11 +++-- .../main/lp_core_gpio_wake_up_example_main.c | 15 +++---- .../ulp/lp_core/lp_i2c/main/lp_i2c_main.c | 14 +++--- .../ulp/lp_core/lp_spi/main/lp_spi_main.c | 14 +++--- .../ulp/lp_core/lp_touch/main/lp_touch_main.c | 6 +-- .../lp_uart/lp_uart_echo/main/lp_uart_main.c | 8 ++-- .../lp_uart/lp_uart_print/main/lp_uart_main.c | 8 ++-- .../ulp/ulp_fsm/ulp/main/ulp_example_main.c | 4 +- .../ulp_adc/main/ulp_adc_example_main.c | 4 +- .../adc/main/ulp_riscv_adc_example_main.c | 10 ++--- .../main/ulp_riscv_ds18b20_example_main.c | 10 ++--- .../gpio/main/ulp_riscv_example_main.c | 8 ++-- .../main/ulp_riscv_gpio_intr_example_main.c | 8 ++-- .../i2c/main/ulp_riscv_rtc_i2c_example_main.c | 24 +++++------ .../interrupts/main/ulp_riscv_example_main.c | 17 +++----- .../touch/main/ulp_riscv_touch_example_main.c | 25 +++++------ .../uart_print/main/ulp_riscv_example_main.c | 16 +++---- 38 files changed, 234 insertions(+), 306 deletions(-) diff --git a/components/driver/test_apps/touch_sensor_v2/main/test_touch_v2.c b/components/driver/test_apps/touch_sensor_v2/main/test_touch_v2.c index 479ffe702f..2f69cc1773 100644 --- a/components/driver/test_apps/touch_sensor_v2/main/test_touch_v2.c +++ b/components/driver/test_apps/touch_sensor_v2/main/test_touch_v2.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -1935,32 +1935,29 @@ static void test_deep_sleep_init(void) gettimeofday(&now, NULL); int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000; printf("RTC_CNTL_SLP_WAKEUP_CAUSE_REG %x\n", REG_READ(RTC_CNTL_SLP_WAKEUP_CAUSE_REG)); - switch (esp_sleep_get_wakeup_cause()) { - case ESP_SLEEP_WAKEUP_EXT1: { - uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status(); - if (wakeup_pin_mask != 0) { - int pin = __builtin_ffsll(wakeup_pin_mask) - 1; - printf("Wake up from GPIO %"PRIu32"\n", pin); - } else { - printf("Wake up from GPIO\n"); - } - break; - } - case ESP_SLEEP_WAKEUP_TIMER: { - printf("Wake up from timer. Time spent in deep sleep: %"PRIu32"ms\n", sleep_time_ms); - break; - } - case ESP_SLEEP_WAKEUP_TOUCHPAD: { - printf("Wake up from touch on pad %"PRIu32"\n", esp_sleep_get_touchpad_wakeup_status()); - break; - } - case ESP_SLEEP_WAKEUP_UNDEFINED: - default: { + + uint32_t wakeup_causes = esp_sleep_get_wakeup_causes(); + if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) { printf("Not a deep sleep reset\n"); ESP_LOGI(TAG, "*********** touch sleep pad wakeup test ********************"); /* Sleep pad should be init once. */ test_touch_sleep_pad_interrupt_wakeup_deep_sleep(touch_list[0]); - } + } else { + if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) { + uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status(); + if (wakeup_pin_mask != 0) { + int pin = __builtin_ffsll(wakeup_pin_mask) - 1; + printf("Wake up from GPIO %"PRIu32"\n", pin); + } else { + printf("Wake up from GPIO\n"); + } + } + if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) { + printf("Wake up from timer. Time spent in deep sleep: %"PRIu32"ms\n", sleep_time_ms); + } + if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD)) { + printf("Wake up from touch on pad %"PRIu32"\n", esp_sleep_get_touchpad_wakeup_status()); + } } vTaskDelay(100 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS); diff --git a/components/esp_driver_gpio/test_apps/gpio/main/test_gpio.c b/components/esp_driver_gpio/test_apps/gpio/main/test_gpio.c index 83921559ba..a8b32b8a87 100644 --- a/components/esp_driver_gpio/test_apps/gpio/main/test_gpio.c +++ b/components/esp_driver_gpio/test_apps/gpio/main/test_gpio.c @@ -880,7 +880,7 @@ TEST_CASE("GPIO_light_sleep_wake_up_test", "[gpio][ignore]") vTaskDelay(1000 / portTICK_PERIOD_MS); esp_light_sleep_start(); printf("Waked up from light sleep\n"); - TEST_ASSERT(esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO); + TEST_ASSERT(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_GPIO)); } #endif diff --git a/components/esp_driver_uart/test_apps/uart/main/test_hp_uart_wakeup.c b/components/esp_driver_uart/test_apps/uart/main/test_hp_uart_wakeup.c index 704e8c60af..a1de927291 100644 --- a/components/esp_driver_uart/test_apps/uart/main/test_hp_uart_wakeup.c +++ b/components/esp_driver_uart/test_apps/uart/main/test_hp_uart_wakeup.c @@ -199,16 +199,13 @@ static void enter_sleep_and_send_respond(void) printf("sleep duration: %lld\n", t_after_us - t_before_us); /* Determine the reason for uart wakeup */ - switch (esp_sleep_get_wakeup_cause()) { - case ESP_SLEEP_WAKEUP_UART: + if (esp_sleep_get_wakeup_causes() & (BIT(ESP_SLEEP_WAKEUP_UART + SLAVE_UART_NUM))) { /* Hang-up for a while to switch and execute the uart task - * Otherwise the chip may fall sleep again before running uart task */ + * Otherwise the chip may fall sleep again before running uart task */ vTaskDelay(1); uart_write_bytes(SLAVE_UART_NUM, "Wakeup OK!", 11); - break; - default: + } else { uart_write_bytes(SLAVE_UART_NUM, "Wakeup failed!", 15); - break; } /* Wait for uart write finish */ diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index abbb21890c..fbd21c9d24 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1855,7 +1855,7 @@ esp_err_t esp_sleep_enable_touchpad_wakeup(void) int esp_sleep_get_touchpad_wakeup_status(void) { - if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_TOUCHPAD) { + if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD))) { return -1; } uint32_t chan_num; @@ -2080,7 +2080,7 @@ static void ext1_wakeup_prepare(void) uint64_t esp_sleep_get_ext1_wakeup_status(void) { - if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_EXT1) { + if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_EXT1))) { return 0; } uint32_t status = rtc_hal_ext1_get_wakeup_status(); @@ -2104,7 +2104,7 @@ uint64_t esp_sleep_get_ext1_wakeup_status(void) #if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP && SOC_DEEP_SLEEP_SUPPORTED uint64_t esp_sleep_get_gpio_wakeup_status(void) { - if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_GPIO) { + if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_GPIO))) { return 0; } return rtc_hal_gpio_get_wakeup_status(); diff --git a/components/esp_hw_support/test_apps/rtc_8md256/main/test_rtc_8md256.c b/components/esp_hw_support/test_apps/rtc_8md256/main/test_rtc_8md256.c index 3831015833..e646897d38 100644 --- a/components/esp_hw_support/test_apps/rtc_8md256/main/test_rtc_8md256.c +++ b/components/esp_hw_support/test_apps/rtc_8md256/main/test_rtc_8md256.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -59,17 +59,7 @@ static void test_lightsleep(bool force_rtc_periph) /* Enter sleep mode */ esp_light_sleep_start(); - /* Determine wake up reason */ - const char* wakeup_reason; - switch (esp_sleep_get_wakeup_cause()) { - case ESP_SLEEP_WAKEUP_TIMER: - wakeup_reason = "timer"; - break; - default: - wakeup_reason = "other"; - break; - } - printf("Returned from light sleep, reason: %s\n", wakeup_reason); + printf("Returned from light sleep, reason: %s\n", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TIMER)) ? "timer" : "other"); vTaskDelay(1000/portTICK_PERIOD_MS); } } diff --git a/components/esp_hw_support/test_apps/rtc_power_modes/main/test_rtc_power.c b/components/esp_hw_support/test_apps/rtc_power_modes/main/test_rtc_power.c index 94003fd63f..ef9004873a 100644 --- a/components/esp_hw_support/test_apps/rtc_power_modes/main/test_rtc_power.c +++ b/components/esp_hw_support/test_apps/rtc_power_modes/main/test_rtc_power.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -91,18 +91,7 @@ static void test_lightsleep(void) /* Enter sleep mode */ esp_light_sleep_start(); - - /* Determine wake up reason */ - const char* wakeup_reason; - switch (esp_sleep_get_wakeup_cause()) { - case ESP_SLEEP_WAKEUP_TIMER: - wakeup_reason = "timer"; - break; - default: - wakeup_reason = "other"; - break; - } - printf("Returned from light sleep, reason: %s\n", wakeup_reason); + printf("Returned from light sleep, reason: %s\n", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TIMER)) ? "timer" : "other"); vTaskDelay(1000/portTICK_PERIOD_MS); } diff --git a/components/esp_hw_support/test_apps/vad_wakeup/main/test_vad_wakeup.c b/components/esp_hw_support/test_apps/vad_wakeup/main/test_vad_wakeup.c index 290d9b6638..0d2ceeb2cb 100644 --- a/components/esp_hw_support/test_apps/vad_wakeup/main/test_vad_wakeup.c +++ b/components/esp_hw_support/test_apps/vad_wakeup/main/test_vad_wakeup.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -142,19 +142,7 @@ static void s_lp_vad_config(void) /* Enter sleep mode */ esp_light_sleep_start(); - /* Determine wake up reason */ - const char* wakeup_reason; - switch (esp_sleep_get_wakeup_cause()) { - case ESP_SLEEP_WAKEUP_VAD: - wakeup_reason = "vad"; - break; - default: - wakeup_reason = "other"; - TEST_ASSERT(false); - break; - } - - ESP_LOGI(TAG, "wakeup, reason: %s", wakeup_reason); + ESP_LOGI(TAG, "wakeup, reason: %s", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_VAD)) ? "vad" : "other"); } TEST_CASE_MULTIPLE_DEVICES("test LP VAD wakeup", "[vad][ignore][manual]", s_hp_i2s_config, s_lp_vad_config); diff --git a/components/esp_hw_support/test_apps/wakeup_tests/main/src/io_wakeup_cmd.c b/components/esp_hw_support/test_apps/wakeup_tests/main/src/io_wakeup_cmd.c index 0f60e176ad..e7e526a6da 100644 --- a/components/esp_hw_support/test_apps/wakeup_tests/main/src/io_wakeup_cmd.c +++ b/components/esp_hw_support/test_apps/wakeup_tests/main/src/io_wakeup_cmd.c @@ -362,8 +362,13 @@ static int process_get_wakeup_cause(int argc, char **argv) return 1; } - switch (esp_sleep_get_wakeup_cause()) { - case ESP_SLEEP_WAKEUP_EXT1: { + uint32_t causes = esp_sleep_get_wakeup_causes(); + if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) { + printf("Wakeup cause err\n"); + return 0; + } + + if (causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) { #if SOC_PM_SUPPORT_EXT1_WAKEUP && SOC_RTCIO_PIN_COUNT > 0 uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status(); if (wakeup_pin_mask != 0) { @@ -374,9 +379,9 @@ static int process_get_wakeup_cause(int argc, char **argv) { printf("Wake up from EXT1 triggered, but unknown wake-up IO\n"); } - break; } - case ESP_SLEEP_WAKEUP_GPIO: { + + if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) { if (esp_reset_reason() == ESP_RST_DEEPSLEEP) { #if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP uint64_t wakeup_pin_mask = esp_sleep_get_gpio_wakeup_status(); @@ -409,11 +414,6 @@ static int process_get_wakeup_cause(int argc, char **argv) gpio_ll_clear_intr_status(&GPIO, 0xFFFFFFFF); gpio_ll_clear_intr_status_high(&GPIO, 0xFFFFFFFF); } - break; - } - default: { - printf("Wakeup cause err\n"); - } } return 0; } diff --git a/components/touch_element/touch_element.c b/components/touch_element/touch_element.c index 43e8ba562a..06580b0bf1 100644 --- a/components/touch_element/touch_element.c +++ b/components/touch_element/touch_element.c @@ -338,8 +338,7 @@ bool te_is_touch_dsleep_wakeup(void) if (reset_reason != RESET_REASON_CORE_DEEP_SLEEP) { return false; } - esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause(); - return wakeup_reason == ESP_SLEEP_WAKEUP_TOUCHPAD; + return !!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD)); } touch_pad_t te_get_sleep_channel(void) diff --git a/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/test_lp_core.c b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/test_lp_core.c index 62ead4122d..232df235f2 100644 --- a/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/test_lp_core.c +++ b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/test_lp_core.c @@ -156,7 +156,7 @@ static void do_ulp_wakeup_deepsleep(lp_core_test_commands_t ulp_cmd) static void check_reset_reason_ulp_wakeup(void) { - TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, esp_sleep_get_wakeup_cause()); + TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)); } static void do_ulp_wakeup_after_short_delay_deepsleep(void) @@ -213,7 +213,7 @@ static void check_reset_reason_and_sleep_duration(void) struct timeval tv_stop = {}; gettimeofday(&tv_stop, NULL); - TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, esp_sleep_get_wakeup_cause()); + TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)); int64_t sleep_duration = (tv_stop.tv_sec - tv_start.tv_sec) * 1000 + (tv_stop.tv_usec - tv_start.tv_usec) / 1000; int64_t expected_sleep_duration_ms = ulp_counter_wakeup_limit * LP_TIMER_TEST_SLEEP_DURATION_US / 1000; diff --git a/components/ulp/test_apps/ulp_fsm/main/test_ulp.c b/components/ulp/test_apps/ulp_fsm/main/test_ulp.c index ee4ae12f88..e25d6a4f83 100644 --- a/components/ulp/test_apps/ulp_fsm/main/test_ulp.c +++ b/components/ulp/test_apps/ulp_fsm/main/test_ulp.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -193,8 +193,8 @@ TEST_CASE("ULP FSM light-sleep wakeup test", "[ulp]") TEST_ASSERT(esp_light_sleep_start() == ESP_OK); /* Wait for wakeup from ULP FSM Coprocessor */ - printf("cause %d\r\n", esp_sleep_get_wakeup_cause()); - TEST_ASSERT(esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_ULP); + printf("causes %lx\r\n", esp_sleep_get_wakeup_causes()); + TEST_ASSERT(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)); } static void ulp_fsm_deepsleep_wakeup_test(void) @@ -239,8 +239,8 @@ static void ulp_fsm_deepsleep_wakeup_test(void) static void check_sleep_reset(void) { TEST_ASSERT_EQUAL(ESP_RST_DEEPSLEEP, esp_reset_reason()); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, cause); + uint32_t causes = esp_sleep_get_wakeup_causes(); + TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), causes & BIT(ESP_SLEEP_WAKEUP_ULP)); } TEST_CASE_MULTIPLE_STAGES("ULP FSM deep-sleep wakeup test", "[deepsleep][reset=DEEPSLEEP_RESET]", diff --git a/components/ulp/test_apps/ulp_riscv/main/test_ulp_riscv.c b/components/ulp/test_apps/ulp_riscv/main/test_ulp_riscv.c index 33db873eb2..c8ee463678 100644 --- a/components/ulp/test_apps/ulp_riscv/main/test_ulp_riscv.c +++ b/components/ulp/test_apps/ulp_riscv/main/test_ulp_riscv.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -196,7 +196,7 @@ TEST_CASE("ULP-RISC-V can be loaded with and run multiple firmwares", "[ulp]") TEST_ASSERT(ulp_riscv_is_running(&ulp_riscv_counter)); } -TEST_CASE("ULP-RISC-V can be reloaded with a good fimware after a crash", "[ulp]") +TEST_CASE("ULP-RISC-V can be reloaded with a good firmware after a crash", "[ulp]") { /* Load ULP RISC-V firmware and start the ULP RISC-V Coprocessor */ load_and_start_ulp_firmware(ulp_main_bin_start, ulp_main_bin_length); @@ -218,8 +218,7 @@ TEST_CASE("ULP-RISC-V can be reloaded with a good fimware after a crash", "[ulp] esp_light_sleep_start(); /* Verify that main CPU wakes up by a COCPU trap signal trigger */ - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - TEST_ASSERT(cause == ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG); + TEST_ASSERT(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG)); printf("Resetting the ULP\n"); ulp_riscv_reset(); @@ -312,7 +311,7 @@ static void do_ulp_wakeup_deepsleep(riscv_test_commands_t ulp_cmd, bool rtc_peri static void check_reset_reason_ulp_wakeup(void) { - TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, esp_sleep_get_wakeup_cause()); + TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)); } static void do_ulp_wakeup_after_long_delay_deepsleep(void) diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c b/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c index d67108acd8..0e5b9f354a 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -313,23 +313,22 @@ static int light_sleep(int argc, char **argv) fflush(stdout); uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM); esp_light_sleep_start(); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - const char *cause_str; - switch (cause) { - case ESP_SLEEP_WAKEUP_GPIO: - cause_str = "GPIO"; - break; - case ESP_SLEEP_WAKEUP_UART: - cause_str = "UART"; - break; - case ESP_SLEEP_WAKEUP_TIMER: - cause_str = "timer"; - break; - default: - cause_str = "unknown"; - printf("%d\n", cause); + + uint32_t causes = esp_sleep_get_wakeup_causes(); + if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) { + ESP_LOGI(TAG, "Woke up from: unknown"); + printf("%lx\n", causes); + return 0; + } + if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) { + ESP_LOGI(TAG, "Woke up from: GPIO"); + } + if (causes & BIT(ESP_SLEEP_WAKEUP_UART)) { + ESP_LOGI(TAG, "Woke up from: UART"); + } + if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) { + ESP_LOGI(TAG, "Woke up from: timer"); } - ESP_LOGI(TAG, "Woke up from: %s", cause_str); return 0; } diff --git a/examples/lowpower/vbat/main/vbat_example_main.c b/examples/lowpower/vbat/main/vbat_example_main.c index bdd3bc2cea..1623b23cb8 100644 --- a/examples/lowpower/vbat/main/vbat_example_main.c +++ b/examples/lowpower/vbat/main/vbat_example_main.c @@ -24,16 +24,20 @@ void app_main(void) ESP_ERROR_CHECK(esp_pm_configure(&pm_config)); #endif - if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT) { -#if CONFIG_ESP_VBAT_USE_RECHARGEABLE_BATTERY - printf("Wake up from VBAT low power\n"); -#else - printf("Wake up from VBAT brownout\n"); -#endif - } else if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TIMER) { - printf("Wake up from Timer\n"); - } else { + uint32_t causes = esp_sleep_get_wakeup_causes(); + if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) { printf("Not a deep sleep reset\n"); + } else { + if (causes & BIT(ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT)) { +#if CONFIG_ESP_VBAT_USE_RECHARGEABLE_BATTERY + printf("Wake up from VBAT low power\n"); +#else + printf("Wake up from VBAT brownout\n"); +#endif + } + if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) { + printf("Wake up from Timer\n"); + } } esp_err_t sleep_result; diff --git a/examples/openthread/ot_sleepy_device/deep_sleep/main/esp_ot_sleepy_device.c b/examples/openthread/ot_sleepy_device/deep_sleep/main/esp_ot_sleepy_device.c index c771140601..cdb7799f04 100644 --- a/examples/openthread/ot_sleepy_device/deep_sleep/main/esp_ot_sleepy_device.c +++ b/examples/openthread/ot_sleepy_device/deep_sleep/main/esp_ot_sleepy_device.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 * @@ -115,20 +115,17 @@ static void ot_deep_sleep_init(void) struct timeval now; gettimeofday(&now, NULL); int sleep_time_ms = (now.tv_sec - s_sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - s_sleep_enter_time.tv_usec) / 1000; - esp_sleep_wakeup_cause_t wake_up_cause = esp_sleep_get_wakeup_cause(); - switch (wake_up_cause) { - case ESP_SLEEP_WAKEUP_TIMER: { - ESP_LOGI(TAG, "Wake up from timer. Time spent in deep sleep and boot: %dms", sleep_time_ms); - break; - } - case ESP_SLEEP_WAKEUP_EXT1: { - ESP_LOGI(TAG, "Wake up from GPIO. Time spent in deep sleep and boot: %dms", sleep_time_ms); - break; - } - case ESP_SLEEP_WAKEUP_UNDEFINED: - default: + + uint32_t wake_up_causes = esp_sleep_get_wakeup_causes(); + if (wake_up_causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) { ESP_LOGI(TAG, "Not a deep sleep reset"); - break; + } else { + if(wake_up_causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) { + ESP_LOGI(TAG, "Wake up from timer. Time spent in deep sleep and boot: %dms", sleep_time_ms); + } + if(wake_up_causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) { + ESP_LOGI(TAG, "Wake up from GPIO. Time spent in deep sleep and boot: %dms", sleep_time_ms); + } } // Set the methods of how to wake up: diff --git a/examples/peripherals/touch_sensor/touch_sens_sleep/main/touch_sens_sleep.c b/examples/peripherals/touch_sensor/touch_sens_sleep/main/touch_sens_sleep.c index 7b2c3aa293..c9db041919 100644 --- a/examples/peripherals/touch_sensor/touch_sens_sleep/main/touch_sens_sleep.c +++ b/examples/peripherals/touch_sensor/touch_sens_sleep/main/touch_sens_sleep.c @@ -156,7 +156,7 @@ void example_prepare_sleep(void) /* Enter the light sleep */ esp_light_sleep_start(); /* Keep executing the code after waking up from the light sleep */ - if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TOUCHPAD) { + if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD)) { ESP_LOGI(TAG, "Wake up by touch\n"); } else { ESP_LOGE(TAG, "Wake up by other source\n"); @@ -180,7 +180,7 @@ void app_main(void) { #if CONFIG_EXAMPLE_TOUCH_DEEP_SLEEP_WAKEUP /* Printing the log if the chip is waken up from deepsleep by the touchpad */ - if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TOUCHPAD) { + if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD)) { ESP_LOGI(TAG, "Wake up by touch\n"); } #endif // CONFIG_EXAMPLE_TOUCH_DEEP_SLEEP_WAKEUP diff --git a/examples/system/console/advanced/components/cmd_system/cmd_system_sleep.c b/examples/system/console/advanced/components/cmd_system/cmd_system_sleep.c index 4dc434b041..1bb4c026d5 100644 --- a/examples/system/console/advanced/components/cmd_system/cmd_system_sleep.c +++ b/examples/system/console/advanced/components/cmd_system/cmd_system_sleep.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -167,24 +167,22 @@ static int light_sleep(int argc, char **argv) fflush(stdout); fsync(fileno(stdout)); esp_light_sleep_start(); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - const char *cause_str; - switch (cause) { - case ESP_SLEEP_WAKEUP_GPIO: - cause_str = "GPIO"; - break; - case ESP_SLEEP_WAKEUP_UART: - cause_str = "UART"; - break; - case ESP_SLEEP_WAKEUP_TIMER: - cause_str = "timer"; - break; - default: - cause_str = "unknown"; - printf("%d\n", cause); + uint32_t causes = esp_sleep_get_wakeup_causes(); + if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) { + ESP_LOGI(TAG, "Woke up from: unknown"); + printf("%lx\n", causes); + return 0; + } + if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) { + ESP_LOGI(TAG, "Woke up from: GPIO"); + } + if (causes & BIT(ESP_SLEEP_WAKEUP_UART)) { + ESP_LOGI(TAG, "Woke up from: UART"); + } + if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) { + ESP_LOGI(TAG, "Woke up from: timer"); } - ESP_LOGI(TAG, "Woke up from: %s", cause_str); return 0; } diff --git a/examples/system/deep_sleep/main/deep_sleep_example_main.c b/examples/system/deep_sleep/main/deep_sleep_example_main.c index 67cea1711c..dcefc2e1d0 100644 --- a/examples/system/deep_sleep/main/deep_sleep_example_main.c +++ b/examples/system/deep_sleep/main/deep_sleep_example_main.c @@ -59,14 +59,15 @@ static void deep_sleep_task(void *args) gettimeofday(&now, NULL); int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000; - switch (esp_sleep_get_wakeup_cause()) { - case ESP_SLEEP_WAKEUP_TIMER: { + uint32_t causes = esp_sleep_get_wakeup_causes(); + if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) { + printf("Not a deep sleep reset\n"); + } else { + if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) { printf("Wake up from timer. Time spent in deep sleep: %dms\n", sleep_time_ms); - break; } - #if CONFIG_EXAMPLE_GPIO_WAKEUP - case ESP_SLEEP_WAKEUP_GPIO: { + if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) { uint64_t wakeup_pin_mask = esp_sleep_get_gpio_wakeup_status(); if (wakeup_pin_mask != 0) { int pin = __builtin_ffsll(wakeup_pin_mask) - 1; @@ -74,19 +75,15 @@ static void deep_sleep_task(void *args) } else { printf("Wake up from GPIO\n"); } - break; } #endif //CONFIG_EXAMPLE_GPIO_WAKEUP - #if CONFIG_EXAMPLE_EXT0_WAKEUP - case ESP_SLEEP_WAKEUP_EXT0: { + if (causes & BIT(ESP_SLEEP_WAKEUP_EXT0)) { printf("Wake up from ext0\n"); - break; } #endif // CONFIG_EXAMPLE_EXT0_WAKEUP - #ifdef CONFIG_EXAMPLE_EXT1_WAKEUP - case ESP_SLEEP_WAKEUP_EXT1: { + if (causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) { uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status(); if (wakeup_pin_mask != 0) { int pin = __builtin_ffsll(wakeup_pin_mask) - 1; @@ -94,13 +91,8 @@ static void deep_sleep_task(void *args) } else { printf("Wake up from GPIO\n"); } - break; } #endif // CONFIG_EXAMPLE_EXT1_WAKEUP - - case ESP_SLEEP_WAKEUP_UNDEFINED: - default: - printf("Not a deep sleep reset\n"); } vTaskDelay(1000 / portTICK_PERIOD_MS); diff --git a/examples/system/deep_sleep_wake_stub/main/wake_stub_example_main.c b/examples/system/deep_sleep_wake_stub/main/wake_stub_example_main.c index 59262477b4..eff7f04ee3 100644 --- a/examples/system/deep_sleep_wake_stub/main/wake_stub_example_main.c +++ b/examples/system/deep_sleep_wake_stub/main/wake_stub_example_main.c @@ -26,7 +26,7 @@ void app_main(void) gettimeofday(&now, NULL); int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000; - if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TIMER) { + if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TIMER)) { printf("Wake up from timer. Time spent in deep sleep: %dms\n", sleep_time_ms); } diff --git a/examples/system/light_sleep/main/light_sleep_example_main.c b/examples/system/light_sleep/main/light_sleep_example_main.c index 8eef13c534..a0f03fd5db 100644 --- a/examples/system/light_sleep/main/light_sleep_example_main.c +++ b/examples/system/light_sleep/main/light_sleep_example_main.c @@ -37,22 +37,18 @@ static void light_sleep_task(void *args) /* Determine wake up reason */ const char* wakeup_reason; - switch (esp_sleep_get_wakeup_cause()) { - case ESP_SLEEP_WAKEUP_TIMER: - wakeup_reason = "timer"; - break; - case ESP_SLEEP_WAKEUP_GPIO: - wakeup_reason = "pin"; - break; - case ESP_SLEEP_WAKEUP_UART: - wakeup_reason = "uart"; - /* Hang-up for a while to switch and execute the uart task - * Otherwise the chip may fall sleep again before running uart task */ - vTaskDelay(1); - break; - default: - wakeup_reason = "other"; - break; + uint32_t wakup_causes = esp_sleep_get_wakeup_causes(); + if (wakup_causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) { + wakeup_reason = "timer"; + } else if (wakup_causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) { + wakeup_reason = "pin"; + } else if (wakup_causes & (BIT(ESP_SLEEP_WAKEUP_UART) | BIT(ESP_SLEEP_WAKEUP_UART1) | BIT(ESP_SLEEP_WAKEUP_UART2))) { + wakeup_reason = "uart"; + /* Hang-up for a while to switch and execute the uart task + * Otherwise the chip may fall sleep again before running uart task */ + vTaskDelay(1); + } else { + wakeup_reason = "other"; } #if CONFIG_NEWLIB_NANO_FORMAT /* printf in newlib-nano does not support %ll format, causing example test fail */ @@ -62,7 +58,7 @@ static void light_sleep_task(void *args) printf("Returned from light sleep, reason: %s, t=%lld ms, slept for %lld ms\n", wakeup_reason, t_after_us / 1000, (t_after_us - t_before_us) / 1000); #endif - if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO) { + if (wakup_causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) { /* Waiting for the gpio inactive, or the chip will continuously trigger wakeup*/ example_wait_gpio_inactive(); } diff --git a/examples/system/ulp/lp_core/gpio/main/lp_core_gpio_example_main.c b/examples/system/ulp/lp_core/gpio/main/lp_core_gpio_example_main.c index e80cdea4a7..c995eeb28f 100644 --- a/examples/system/ulp/lp_core/gpio/main/lp_core_gpio_example_main.c +++ b/examples/system/ulp/lp_core/gpio/main/lp_core_gpio_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -43,18 +43,15 @@ void app_main(void) rtc_gpio_pulldown_dis(WAKEUP_PIN); rtc_gpio_pullup_dis(WAKEUP_PIN); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - /* not a wakeup from ULP, load the firmware */ - if (cause != ESP_SLEEP_WAKEUP_ULP) { - printf("Not a ULP wakeup, initializing it! \n"); - init_ulp_program(); - } - - /* ULP read and detected a change in GPIO_0, prints */ - if (cause == ESP_SLEEP_WAKEUP_ULP) { + if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) { + /* ULP read and detected a change in GPIO_0, prints */ printf("ULP woke up the main CPU! \n"); printf("ULP read changes in GPIO_0 current is: %s \n", (bool)(ulp_gpio_level_previous == 0) ? "Low" : "High" ); + } else { + /* not a wakeup from ULP, load the firmware */ + printf("Not a ULP wakeup, initializing it! \n"); + init_ulp_program(); } /* Go back to sleep, only the ULP will run */ diff --git a/examples/system/ulp/lp_core/gpio_intr_pulse_counter/main/lp_core_pulse_counter_example_main.c b/examples/system/ulp/lp_core/gpio_intr_pulse_counter/main/lp_core_pulse_counter_example_main.c index 65bef47be2..7fa9ea5a61 100644 --- a/examples/system/ulp/lp_core/gpio_intr_pulse_counter/main/lp_core_pulse_counter_example_main.c +++ b/examples/system/ulp/lp_core/gpio_intr_pulse_counter/main/lp_core_pulse_counter_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -47,14 +47,13 @@ void app_main(void) printf("ULP will wake up processor after every %d pulses\n", CONFIG_EXAMPLE_PULSE_COUNT_WAKEUP_LIMIT); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); /* not a wakeup from ULP, load the firmware */ - if (cause != ESP_SLEEP_WAKEUP_ULP) { - printf("Not a ULP wakeup, initializing it! \n"); - init_ulp_program(); - } else { + if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) { printf("ULP woke up the main CPU!\n"); printf("Pulse count: %"PRIu32"\n", ulp_pulse_count); + } else { + printf("Not a ULP wakeup, initializing it! \n"); + init_ulp_program(); } /* Go back to sleep, only the ULP will run */ diff --git a/examples/system/ulp/lp_core/gpio_wakeup/main/lp_core_gpio_wake_up_example_main.c b/examples/system/ulp/lp_core/gpio_wakeup/main/lp_core_gpio_wake_up_example_main.c index 77e23aa6d7..ce1bcdfe57 100644 --- a/examples/system/ulp/lp_core/gpio_wakeup/main/lp_core_gpio_wake_up_example_main.c +++ b/examples/system/ulp/lp_core/gpio_wakeup/main/lp_core_gpio_wake_up_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -48,18 +48,15 @@ void app_main(void) wakeup_gpio_init(); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - /* not a wakeup from ULP, load the firmware */ - if (cause != ESP_SLEEP_WAKEUP_ULP) { + if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) { + /* ULP read and detected a change in WAKEUP_PIN, prints */ + printf("ULP woke up the main CPU! \n"); + } else { + /* not a wakeup from ULP, load the firmware */ printf("Not a ULP wakeup, initializing it! \n"); init_ulp_program(); } - /* ULP read and detected a change in WAKEUP_PIN, prints */ - if (cause == ESP_SLEEP_WAKEUP_ULP) { - printf("ULP woke up the main CPU! \n"); - } - /* Go back to sleep, only the ULP will run */ printf("Entering deep sleep\n\n"); diff --git a/examples/system/ulp/lp_core/lp_i2c/main/lp_i2c_main.c b/examples/system/ulp/lp_core/lp_i2c/main/lp_i2c_main.c index 0e0d57f0ec..890702ecee 100644 --- a/examples/system/ulp/lp_core/lp_i2c/main/lp_i2c_main.c +++ b/examples/system/ulp/lp_core/lp_i2c/main/lp_i2c_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -62,9 +62,12 @@ void app_main(void) */ vTaskDelay(pdMS_TO_TICKS(1000)); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - if (cause != ESP_SLEEP_WAKEUP_ULP) { - printf("Not an LP core wakeup. Cause = %d\n", cause); + uint32_t causes = esp_sleep_get_wakeup_causes(); + if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) { + printf("LP core woke up the main CPU\n"); + printf("Lux = %ld\n", ulp_lux); + } else { + printf("Not an LP core wakeup. Causes = %lx\n", causes); printf("Initializing...\n"); /* Initialize LP_I2C from the main processor */ @@ -72,9 +75,6 @@ void app_main(void) /* Load LP Core binary and start the coprocessor */ lp_core_init(); - } else if (cause == ESP_SLEEP_WAKEUP_ULP) { - printf("LP core woke up the main CPU\n"); - printf("Lux = %ld\n", ulp_lux); } /* Setup wakeup triggers */ diff --git a/examples/system/ulp/lp_core/lp_spi/main/lp_spi_main.c b/examples/system/ulp/lp_core/lp_spi/main/lp_spi_main.c index ba7513f032..9a15e66081 100644 --- a/examples/system/ulp/lp_core/lp_spi/main/lp_spi_main.c +++ b/examples/system/ulp/lp_core/lp_spi/main/lp_spi_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -78,9 +78,12 @@ void app_main(void) */ vTaskDelay(pdMS_TO_TICKS(1000)); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - if (cause != ESP_SLEEP_WAKEUP_ULP) { - printf("Not an LP core wakeup. Cause = %d\n", cause); + uint32_t causes = esp_sleep_get_wakeup_causes(); + if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) { + printf("LP core woke up the main CPU\n"); + printf("Temperature %.2f degree celsius, humidity %.2f%%RH\n", ulp_temperature / 100.0, ulp_humidity / 1024.0); + } else { + printf("Not an LP core wakeup. Causes = %lx\n", causes); printf("Initializing...\n"); /* Initialize LP_SPI from the main processor */ @@ -88,9 +91,6 @@ void app_main(void) /* Load LP Core binary and start the coprocessor */ lp_core_init(); - } else if (cause == ESP_SLEEP_WAKEUP_ULP) { - printf("LP core woke up the main CPU\n"); - printf("Temperature %.2f degree celsius, humidity %.2f%%RH\n", ulp_temperature / 100.0, ulp_humidity / 1024.0); } /* Setup wakeup triggers */ diff --git a/examples/system/ulp/lp_core/lp_touch/main/lp_touch_main.c b/examples/system/ulp/lp_core/lp_touch/main/lp_touch_main.c index 4c23cf67b7..6c4db73859 100644 --- a/examples/system/ulp/lp_core/lp_touch/main/lp_touch_main.c +++ b/examples/system/ulp/lp_core/lp_touch/main/lp_touch_main.c @@ -154,9 +154,9 @@ void app_main(void) */ vTaskDelay(pdMS_TO_TICKS(1000)); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); + uint32_t causes = esp_sleep_get_wakeup_causes(); /* Woke up by LP core, i.e., wake up the main CPU in the LP program */ - if (cause == ESP_SLEEP_WAKEUP_ULP) { + if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) { printf("LP core woke up the main CPU\n"); // We can access the LP core global variable by adding `ulp_` prefix uint32_t touch_data = ulp_touch_data; @@ -169,7 +169,7 @@ void app_main(void) } /* Woke up by other source, like power_on */ else { - printf("Not an LP core wakeup. Cause = %d\n", cause); + printf("Not an LP core wakeup. Causes = %lx\n", causes); printf("Initializing...\n"); /* Initialize Touch sensor from the main processor */ diff --git a/examples/system/ulp/lp_core/lp_uart/lp_uart_echo/main/lp_uart_main.c b/examples/system/ulp/lp_core/lp_uart/lp_uart_echo/main/lp_uart_main.c index f5af38d35a..80347c8d69 100644 --- a/examples/system/ulp/lp_core/lp_uart/lp_uart_echo/main/lp_uart_main.c +++ b/examples/system/ulp/lp_core/lp_uart/lp_uart_echo/main/lp_uart_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -50,9 +50,9 @@ void app_main(void) */ vTaskDelay(pdMS_TO_TICKS(1000)); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - if (cause != ESP_SLEEP_WAKEUP_ULP) { - printf("Not an LP core wakeup. Cause = %d\n", cause); + uint32_t causes = esp_sleep_get_wakeup_causes(); + if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) { + printf("Not an LP core wakeup. Causes = %lx\n", causes); printf("Initializing...\n"); /* Initialize LP_UART */ diff --git a/examples/system/ulp/lp_core/lp_uart/lp_uart_print/main/lp_uart_main.c b/examples/system/ulp/lp_core/lp_uart/lp_uart_print/main/lp_uart_main.c index 08c4fd3997..a144a7e5f3 100644 --- a/examples/system/ulp/lp_core/lp_uart/lp_uart_print/main/lp_uart_main.c +++ b/examples/system/ulp/lp_core/lp_uart/lp_uart_print/main/lp_uart_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -51,9 +51,9 @@ void app_main(void) */ vTaskDelay(pdMS_TO_TICKS(1000)); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - if (cause != ESP_SLEEP_WAKEUP_ULP) { - printf("Not an LP core wakeup. Cause = %d\n", cause); + uint32_t causes = esp_sleep_get_wakeup_causes(); + if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) { + printf("Not an LP core wakeup. Causes = %lx\n", causes); printf("Initializing...\n"); /* Initialize LP_UART */ diff --git a/examples/system/ulp/ulp_fsm/ulp/main/ulp_example_main.c b/examples/system/ulp/ulp_fsm/ulp/main/ulp_example_main.c index 5a9ab22485..7e5a3f51b8 100644 --- a/examples/system/ulp/ulp_fsm/ulp/main/ulp_example_main.c +++ b/examples/system/ulp/ulp_fsm/ulp/main/ulp_example_main.c @@ -42,8 +42,8 @@ void app_main(void) */ vTaskDelay(pdMS_TO_TICKS(1000)); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - if (cause != ESP_SLEEP_WAKEUP_ULP) { + uint32_t causes = esp_sleep_get_wakeup_causes(); + if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) { printf("Not ULP wakeup, initializing ULP\n"); init_ulp_program(); } else { diff --git a/examples/system/ulp/ulp_fsm/ulp_adc/main/ulp_adc_example_main.c b/examples/system/ulp/ulp_fsm/ulp_adc/main/ulp_adc_example_main.c index ed10d2524b..85b7c18b4e 100644 --- a/examples/system/ulp/ulp_fsm/ulp_adc/main/ulp_adc_example_main.c +++ b/examples/system/ulp/ulp_fsm/ulp_adc/main/ulp_adc_example_main.c @@ -51,8 +51,8 @@ void app_main(void) */ vTaskDelay(pdMS_TO_TICKS(1000)); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - if (cause != ESP_SLEEP_WAKEUP_ULP) { + uint32_t causes = esp_sleep_get_wakeup_causes(); + if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) { printf("Not ULP wakeup\n"); init_ulp_program(); } else { diff --git a/examples/system/ulp/ulp_riscv/adc/main/ulp_riscv_adc_example_main.c b/examples/system/ulp/ulp_riscv/adc/main/ulp_riscv_adc_example_main.c index d4a0c39889..ff9880d0f1 100644 --- a/examples/system/ulp/ulp_riscv/adc/main/ulp_riscv_adc_example_main.c +++ b/examples/system/ulp/ulp_riscv/adc/main/ulp_riscv_adc_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -37,16 +37,16 @@ void app_main(void) */ vTaskDelay(pdMS_TO_TICKS(1000)); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); + uint32_t causes = esp_sleep_get_wakeup_causes(); /* not a wakeup from ULP, load the firmware */ - if ((cause != ESP_SLEEP_WAKEUP_ULP) && (cause != ESP_SLEEP_WAKEUP_TIMER)) { - printf("Not a ULP-RISC-V wakeup (cause = %d), initializing it! \n", cause); + if (!(causes & (BIT(ESP_SLEEP_WAKEUP_ULP) | BIT(ESP_SLEEP_WAKEUP_TIMER)))) { + printf("Not a ULP-RISC-V wakeup (causes = %lx), initializing it! \n", causes); init_ulp_program(); } /* ULP Risc-V read and detected a temperature above the limit */ - if (cause == ESP_SLEEP_WAKEUP_ULP) { + if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) { printf("ULP-RISC-V woke up the main CPU\n"); printf("Threshold: high = %"PRIu32"\n", ulp_adc_threshold); printf("Value = %"PRIu32" was above threshold\n", ulp_wakeup_result); diff --git a/examples/system/ulp/ulp_riscv/ds18b20_onewire/main/ulp_riscv_ds18b20_example_main.c b/examples/system/ulp/ulp_riscv/ds18b20_onewire/main/ulp_riscv_ds18b20_example_main.c index f3a397dbf2..4d95abc450 100644 --- a/examples/system/ulp/ulp_riscv/ds18b20_onewire/main/ulp_riscv_ds18b20_example_main.c +++ b/examples/system/ulp/ulp_riscv/ds18b20_onewire/main/ulp_riscv_ds18b20_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -44,15 +44,15 @@ void app_main(void) */ vTaskDelay(pdMS_TO_TICKS(1000)); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); + uint32_t causes = esp_sleep_get_wakeup_causes(); /* not a wakeup from ULP, load the firmware */ - if (cause != ESP_SLEEP_WAKEUP_ULP) { - printf("Not a ULP-RISC-V wakeup (cause = %d), initializing it! \n", cause); + if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) { + printf("Not a ULP-RISC-V wakeup (causes = %lx), initializing it! \n", causes); init_ulp_program(); } /* ULP Risc-V read and detected a temperature above the limit */ - if (cause == ESP_SLEEP_WAKEUP_ULP) { + if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) { printf("ULP-RISC-V woke up the main CPU, temperature is above set limit! \n"); printf("ULP-RISC-V read temperature is %f\n", ulp_temp_reg_val / 16.0); } diff --git a/examples/system/ulp/ulp_riscv/gpio/main/ulp_riscv_example_main.c b/examples/system/ulp/ulp_riscv/gpio/main/ulp_riscv_example_main.c index 13dea70f00..9ef0e3ae59 100644 --- a/examples/system/ulp/ulp_riscv/gpio/main/ulp_riscv_example_main.c +++ b/examples/system/ulp/ulp_riscv/gpio/main/ulp_riscv_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -45,15 +45,15 @@ void app_main(void) rtc_gpio_pullup_dis(GPIO_NUM_0); rtc_gpio_hold_en(GPIO_NUM_0); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); + uint32_t causes = esp_sleep_get_wakeup_causes(); /* not a wakeup from ULP, load the firmware */ - if (cause != ESP_SLEEP_WAKEUP_ULP) { + if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) { printf("Not a ULP-RISC-V wakeup, initializing it! \n"); init_ulp_program(); } /* ULP Risc-V read and detected a change in GPIO_0, prints */ - if (cause == ESP_SLEEP_WAKEUP_ULP) { + if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) { printf("ULP-RISC-V woke up the main CPU! \n"); printf("ULP-RISC-V read changes in GPIO_0 current is: %s \n", (bool)(ulp_gpio_level_previous == 0) ? "Low" : "High" ); diff --git a/examples/system/ulp/ulp_riscv/gpio_interrupt/main/ulp_riscv_gpio_intr_example_main.c b/examples/system/ulp/ulp_riscv/gpio_interrupt/main/ulp_riscv_gpio_intr_example_main.c index cc2569fcfe..98e7cd0a3a 100644 --- a/examples/system/ulp/ulp_riscv/gpio_interrupt/main/ulp_riscv_gpio_intr_example_main.c +++ b/examples/system/ulp/ulp_riscv/gpio_interrupt/main/ulp_riscv_gpio_intr_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -49,15 +49,15 @@ void app_main(void) */ vTaskDelay(pdMS_TO_TICKS(1000)); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); + uint32_t causes = esp_sleep_get_wakeup_causes(); /* not a wakeup from ULP, load the firmware */ - if (cause != ESP_SLEEP_WAKEUP_ULP) { + if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) { printf("Not a ULP-RISC-V wakeup, initializing it! \n"); wakeup_gpio_init(); init_ulp_program(); } - if (cause == ESP_SLEEP_WAKEUP_ULP) { + if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) { printf("ULP-RISC-V woke up the main CPU! \n"); } diff --git a/examples/system/ulp/ulp_riscv/i2c/main/ulp_riscv_rtc_i2c_example_main.c b/examples/system/ulp/ulp_riscv/i2c/main/ulp_riscv_rtc_i2c_example_main.c index 7a08796d60..38cb646bef 100644 --- a/examples/system/ulp/ulp_riscv/i2c/main/ulp_riscv_rtc_i2c_example_main.c +++ b/examples/system/ulp/ulp_riscv/i2c/main/ulp_riscv_rtc_i2c_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -52,7 +52,7 @@ void app_main(void) int32_t pressure = 0; oss_mode_t oss_mode; - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); + uint32_t causes = esp_sleep_get_wakeup_causes(); /* Not a wakeup from ULP * Initialize RTC I2C @@ -61,8 +61,8 @@ void app_main(void) * Load the ULP firmware * Go to deep sleep */ - if (cause != ESP_SLEEP_WAKEUP_ULP) { - printf("Not a ULP-RISC V wakeup (cause = %d)\n", cause); + if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) { + printf("Not a ULP-RISC V wakeup (causes = %lx)\n", causes); /* Initialize RTC I2C */ init_i2c(); @@ -76,7 +76,7 @@ void app_main(void) ulp_riscv_i2c_master_write_to_device(&data_wr, 1); /* Confirm that the sensor is alive - * The BMP180 returns the chip id 0x55 on quering reg addr 0xD0 + * The BMP180 returns the chip id 0x55 on querying reg addr 0xD0 */ ulp_riscv_i2c_master_set_slave_reg_addr(BMP180_SENSOR_REG_ADDR_WHO_AM_I); ulp_riscv_i2c_master_read_from_device(&data_rd, 1); @@ -103,7 +103,7 @@ void app_main(void) /* Calculate real temperature value */ temperature = bmp180_calculate_real_temp((int32_t)ut_data); - printf("Real Temperature = %f deg celcius\n", (float)(temperature/10.0)); + printf("Real Temperature = %f deg celsius\n", (float)(temperature/10.0)); /* Calculate real pressure value */ pressure = bmp180_calculate_real_pressure(up_data, (int32_t)ut_data, oss_mode); @@ -120,7 +120,7 @@ void app_main(void) } /* ULP RISC-V read and detected a temperature or pressure above the limit */ - if (cause == ESP_SLEEP_WAKEUP_ULP) { + if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) { printf("ULP RISC-V woke up the main CPU\n"); /* Pause ULP while we are using the RTC I2C from the main CPU */ @@ -138,7 +138,7 @@ void app_main(void) /* Calculate real temperature and pressure again */ temperature = 0; temperature = bmp180_calculate_real_temp((int32_t)ulp_ut_data); - printf("New Real Temperature = %f deg celcius\n", (float)(temperature/10.0)); + printf("New Real Temperature = %f deg celsius\n", (float)(temperature/10.0)); /* Calculate real pressure value */ pressure = 0; @@ -283,19 +283,19 @@ static void bmp180_read_up_data(int32_t *up_data, oss_mode_t oss_mode) { case OSS_0: cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_0; - wait = 5; // Wait atleast 4.5 msec + wait = 5; // Wait at least 4.5 msec break; case OSS_1: cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_1; - wait = 8; // Wait atleast 7.5 msec + wait = 8; // Wait at least 7.5 msec break; case OSS_2: cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_2; - wait = 14; // Wait atleast 13.5 msec + wait = 14; // Wait at least 13.5 msec break; case OSS_3: cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_3; - wait = 26; // Wait atleast 25.5 msec + wait = 26; // Wait at least 25.5 msec break; } diff --git a/examples/system/ulp/ulp_riscv/interrupts/main/ulp_riscv_example_main.c b/examples/system/ulp/ulp_riscv/interrupts/main/ulp_riscv_example_main.c index 446bb62d97..6926744846 100644 --- a/examples/system/ulp/ulp_riscv/interrupts/main/ulp_riscv_example_main.c +++ b/examples/system/ulp/ulp_riscv/interrupts/main/ulp_riscv_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -26,15 +26,8 @@ static void init_ulp_program(void); void app_main(void) { - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - /* not a wakeup from ULP, load the firmware */ - if (cause != ESP_SLEEP_WAKEUP_ULP) { - printf("Not a ULP RISC-V wakeup, initializing it! \n"); - init_ulp_program(); - } - - /* ULP RISC-V handled an interrupt on GPIO#0 */ - if (cause == ESP_SLEEP_WAKEUP_ULP) { + if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) { + /* ULP RISC-V handled an interrupt on GPIO#0 */ printf("ULP RISC-V woke up the main CPU! \n"); if (ulp_wake_by_sw) { printf("ULP RISC-V SW Interrupt triggered %lu times.\r\n", ulp_sw_int_cnt); @@ -43,6 +36,10 @@ void app_main(void) printf("ULP RISC-V GPIO Interrupt triggered.\r\n"); ulp_wake_by_gpio = 0; } + } else { + /* not a wakeup from ULP, load the firmware */ + printf("Not a ULP RISC-V wakeup, initializing it! \n"); + init_ulp_program(); } /* Go back to sleep, only the ULP RISC-V will run */ diff --git a/examples/system/ulp/ulp_riscv/touch/main/ulp_riscv_touch_example_main.c b/examples/system/ulp/ulp_riscv/touch/main/ulp_riscv_touch_example_main.c index 8be53ec9b8..29b2fdd1af 100644 --- a/examples/system/ulp/ulp_riscv/touch/main/ulp_riscv_touch_example_main.c +++ b/examples/system/ulp/ulp_riscv/touch/main/ulp_riscv_touch_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -83,19 +83,8 @@ void app_main(void) */ vTaskDelay(pdMS_TO_TICKS(1000)); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - /* not a wakeup from ULP, load the firmware */ - if (cause != ESP_SLEEP_WAKEUP_ULP) { - printf("Not a ULP-RISC-V wakeup, initializing ...\n"); - /* Initialize Touch peripheral */ - init_touch_pad(); - - /* Initialize ULP core */ - init_ulp_program(); - } - - /* ULP RISC-V detected a touch input */ - if (cause == ESP_SLEEP_WAKEUP_ULP) { + if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) { + /* ULP RISC-V detected a touch input */ printf("ULP-RISC-V woke up the main CPU! \n"); uint32_t touch_data = ulp_touch_data; for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { @@ -104,6 +93,14 @@ void app_main(void) } } printf("\n"); + } else { + /* not a wakeup from ULP, load the firmware */ + printf("Not a ULP-RISC-V wakeup, initializing ...\n"); + /* Initialize Touch peripheral */ + init_touch_pad(); + + /* Initialize ULP core */ + init_ulp_program(); } /* Go to sleep, only the ULP RISC-V will run */ diff --git a/examples/system/ulp/ulp_riscv/uart_print/main/ulp_riscv_example_main.c b/examples/system/ulp/ulp_riscv/uart_print/main/ulp_riscv_example_main.c index 811421ddbb..4292e387a4 100644 --- a/examples/system/ulp/ulp_riscv/uart_print/main/ulp_riscv_example_main.c +++ b/examples/system/ulp/ulp_riscv/uart_print/main/ulp_riscv_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -33,19 +33,15 @@ void app_main(void) */ vTaskDelay(pdMS_TO_TICKS(1000)); - esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); - /* not a wakeup from ULP, load the firmware */ - if (cause != ESP_SLEEP_WAKEUP_ULP) { + if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) { + /* ULP Risc-V read and detected a change in GPIO_0, prints */ + printf("ULP-RISC-V woke up the main CPU! \n"); + } else { + /* not a wakeup from ULP, load the firmware */ printf("Not a ULP-RISC-V wakeup, initializing it! \n"); init_ulp_program(); } - /* ULP Risc-V read and detected a change in GPIO_0, prints */ - if (cause == ESP_SLEEP_WAKEUP_ULP) { - printf("ULP-RISC-V woke up the main CPU! \n"); - - } - /* Go back to sleep, only the ULP Risc-V will run */ printf("Entering in deep sleep\n\n");