From afbea0a04c1ee3a3e82000512b7ccd8a2b2ff16c Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Mon, 5 Sep 2022 16:29:32 +0200 Subject: [PATCH] ulp: Updated ULP docs and ulp_fsm example for wakeup when SoC is not in sleep mode. This commit updates the ULP documentation and the ulp_fsm example with the scenario when a wakeup is triggered from the ULP coproc when the main CPU is not in sleep mode. Closes https://github.com/espressif/esp-idf/issues/8341 Closes https://github.com/espressif/esp-idf/issues/5254 --- .../api-reference/system/ulp_instruction_set.rst | 12 +++++++++++- examples/system/ulp_fsm/ulp/main/ulp/wake_up.S | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/en/api-reference/system/ulp_instruction_set.rst b/docs/en/api-reference/system/ulp_instruction_set.rst index a064bbfc88..5eda0c98c1 100644 --- a/docs/en/api-reference/system/ulp_instruction_set.rst +++ b/docs/en/api-reference/system/ulp_instruction_set.rst @@ -979,7 +979,8 @@ The detailed description of all instructions is presented below: - If the SoC is not in deep sleep mode, and ULP interrupt bit (RTC_CNTL_ULP_CP_INT_ENA) is set in RTC_CNTL_INT_ENA_REG register, RTC interrupt will be triggered. - Note that before using WAKE instruction, ULP program may needs to wait until RTC controller is ready to wake up the main CPU. This is indicated using RTC_CNTL_RDY_FOR_WAKEUP bit of RTC_CNTL_LOW_POWER_ST_REG register. If WAKE instruction is executed while RTC_CNTL_RDY_FOR_WAKEUP is zero, it has no effect (wake up does not occur). +.. note:: + Note that before using WAKE instruction, ULP program may need to wait until RTC controller is ready to wake up the main CPU. This is indicated using RTC_CNTL_RDY_FOR_WAKEUP bit of RTC_CNTL_LOW_POWER_ST_REG register. If WAKE instruction is executed while RTC_CNTL_RDY_FOR_WAKEUP is zero, it has no effect (wake up does not occur). If the WAKE instruction is intended to be used while the main CPU is not in sleep mode then the RTC_CNTL_MAIN_STATE_IN_IDLE (bit 27) of RTC_CNTL_LOW_POWER_ST_REG can be used to check whether main CPU is in normal mode or sleep mode. **Examples**:: @@ -993,6 +994,15 @@ The detailed description of all instructions is presented below: // After these instructions, SoC will wake up, // and ULP will not run again until started by the main program. + 1: check_wakeup: // Read RTC_CNTL_RDY_FOR_WAKEUP and RTC_CNTL_MAIN_STATE_IN_IDLE bit + READ_RTC_REG(RTC_CNTL_LOW_POWER_ST_REG, 27, 0) + MOVE r1, r0 // Copy result in to r1 + READ_RTC_FIELD(RTC_CNTL_LOW_POWER_ST_REG, RTC_CNTL_RDY_FOR_WAKEUP) + OR r0, r0, r1 + JUMP check_wakeup, eq // Retry until either of the bit are set + WAKE // Trigger wake up + HALT // Stop the ULP program + .. only:: esp32 diff --git a/examples/system/ulp_fsm/ulp/main/ulp/wake_up.S b/examples/system/ulp_fsm/ulp/main/ulp/wake_up.S index 34b80b4118..1ccc94a9f4 100644 --- a/examples/system/ulp_fsm/ulp/main/ulp/wake_up.S +++ b/examples/system/ulp_fsm/ulp/main/ulp/wake_up.S @@ -1,14 +1,28 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ /* ULP assembly files are passed through C preprocessor first, so include directives and C macros may be used in these files */ #include "soc/rtc_cntl_reg.h" #include "soc/soc_ulp.h" +#include "sdkconfig.h" .global wake_up wake_up: + /* Check if the system is in sleep mode */ +#if CONFIG_IDF_TARGET_ESP32 + READ_RTC_REG(RTC_CNTL_LOW_POWER_ST_REG, 27, 0) +#else + READ_RTC_FIELD(RTC_CNTL_LOW_POWER_ST_REG, RTC_CNTL_MAIN_STATE_IN_IDLE) +#endif + move r1, r0 /* Check if the system can be woken up */ READ_RTC_FIELD(RTC_CNTL_LOW_POWER_ST_REG, RTC_CNTL_RDY_FOR_WAKEUP) - and r0, r0, 1 + /* If the system is in normal mode or if the system is in sleep mode with ready for wakeup set, we can signal the main CPU to wakeup */ + or r0, r0, r1 jump wake_up, eq /* Wake up the SoC, end program */