mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 20:41:14 +00:00
esp32: Deactivate wakeup trigger after first wakeup
The files updated according to code review discussions. In the sleep_modes.c removed immidiate disable of ULP mode and leave just trigger deactivation. The esp_sleep.h is updated to have the same defines for source as esp_sleep_wakeup_cause_t. Updated documentation in sleep_modes.rst file to include cross references. Some minor changes in test_sleep.c unit test. (TW#18952) Closes https://github.com/espressif/esp-idf/issues/1677
This commit is contained in:
@@ -5,25 +5,13 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#include "soc/rtc.h" // for wakeup trigger defines
|
||||
#include "soc/rtc_cntl_reg.h" // for read rtc registers directly (cause)
|
||||
#include "soc/soc.h"
|
||||
#include "soc/soc.h" // for direct register read macros
|
||||
|
||||
#define ESP_EXT0_WAKEUP_LEVEL_LOW 0
|
||||
#define ESP_EXT0_WAKEUP_LEVEL_HIGH 1
|
||||
|
||||
// These are flags for wakeup cause to get it directly from RTC
|
||||
#define RTC_EXT0_TRIG_EN BIT(0) //!< EXT0 GPIO wakeup
|
||||
#define RTC_EXT1_TRIG_EN BIT(1) //!< EXT1 GPIO wakeup
|
||||
#define RTC_GPIO_TRIG_EN BIT(2) //!< GPIO wakeup (light sleep only)
|
||||
#define RTC_TIMER_TRIG_EN BIT(3) //!< Timer wakeup
|
||||
#define RTC_SDIO_TRIG_EN BIT(4) //!< SDIO wakeup (light sleep only)
|
||||
#define RTC_MAC_TRIG_EN BIT(5) //!< MAC wakeup (light sleep only)
|
||||
#define RTC_UART0_TRIG_EN BIT(6) //!< UART0 wakeup (light sleep only)
|
||||
#define RTC_UART1_TRIG_EN BIT(7) //!< UART1 wakeup (light sleep only)
|
||||
#define RTC_TOUCH_TRIG_EN BIT(8) //!< Touch wakeup
|
||||
#define RTC_ULP_TRIG_EN BIT(9) //!< ULP wakeup
|
||||
#define RTC_BT_TRIG_EN BIT(10) //!< BT wakeup (light sleep only)
|
||||
|
||||
static struct timeval tv_start, tv_stop;
|
||||
|
||||
TEST_CASE("esp_deepsleep works", "[deepsleep][reset=DEEPSLEEP_RESET]")
|
||||
@@ -129,7 +117,7 @@ TEST_CASE("wake up using ext1 when RTC_PERIPH is on (13 low)", "[deepsleep][igno
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
static float get_time(void)
|
||||
static float get_time_ms(void)
|
||||
{
|
||||
gettimeofday(&tv_stop, NULL);
|
||||
|
||||
@@ -146,7 +134,7 @@ static uint32_t get_cause()
|
||||
}
|
||||
|
||||
// This test case verifies deactivation of trigger for wake up sources
|
||||
TEST_CASE("disable source behavior", "[deepsleep][ignore]")
|
||||
TEST_CASE("disable source trigger behavior", "[deepsleep]")
|
||||
{
|
||||
float dt = 0;
|
||||
|
||||
@@ -166,23 +154,23 @@ TEST_CASE("disable source behavior", "[deepsleep][ignore]")
|
||||
gettimeofday(&tv_start, NULL);
|
||||
esp_light_sleep_start();
|
||||
|
||||
dt = get_time();
|
||||
dt = get_time_ms();
|
||||
printf("Ext0 sleep time = %d \n", (int) dt);
|
||||
|
||||
// Check wakeup from Ext0 using time measurement because wakeup cause is
|
||||
// not available in light sleep mode
|
||||
TEST_ASSERT_INT32_WITHIN(297, 300, (int) dt);
|
||||
TEST_ASSERT_INT32_WITHIN(299, 300, (int) dt);
|
||||
|
||||
TEST_ASSERT((get_cause() & RTC_EXT0_TRIG_EN) != 0);
|
||||
|
||||
// Disable Ext0 source. Timer source should be triggered
|
||||
ESP_ERROR_CHECK(esp_sleep_disable_wakeup_source(ESP_SLEEP_SOURCE_EXT0));
|
||||
printf("Disable ext0 source leave timer active.\n");
|
||||
ESP_ERROR_CHECK(esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_EXT0));
|
||||
printf("Disable ext0 trigger and leave timer active.\n");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
esp_light_sleep_start();
|
||||
|
||||
dt = get_time();
|
||||
dt = get_time_ms();
|
||||
printf("Timer sleep time = %d \n", (int) dt);
|
||||
|
||||
TEST_ASSERT_INT32_WITHIN(500, 2000, (int) dt);
|
||||
@@ -191,7 +179,7 @@ TEST_CASE("disable source behavior", "[deepsleep][ignore]")
|
||||
TEST_ASSERT((get_cause() & RTC_TIMER_TRIG_EN) != 0);
|
||||
|
||||
// Disable timer source.
|
||||
ESP_ERROR_CHECK(esp_sleep_disable_wakeup_source(ESP_SLEEP_SOURCE_TIMER));
|
||||
ESP_ERROR_CHECK(esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER));
|
||||
|
||||
// Setup ext0 configuration to wake up immediately
|
||||
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
|
||||
@@ -199,19 +187,20 @@ TEST_CASE("disable source behavior", "[deepsleep][ignore]")
|
||||
ESP_ERROR_CHECK(gpio_pulldown_dis(GPIO_NUM_13));
|
||||
ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, ESP_EXT0_WAKEUP_LEVEL_HIGH));
|
||||
|
||||
printf("Disable timer and wake up from ext0 source.\n");
|
||||
printf("Disable timer trigger to wake up from ext0 source.\n");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
esp_light_sleep_start();
|
||||
|
||||
dt = get_time();
|
||||
dt = get_time_ms();
|
||||
printf("Ext0 sleep time = %d \n", (int) dt);
|
||||
|
||||
TEST_ASSERT_INT32_WITHIN(198, 200, (int) dt);
|
||||
TEST_ASSERT_INT32_WITHIN(199, 200, (int) dt);
|
||||
TEST_ASSERT((get_cause() & RTC_EXT0_TRIG_EN) != 0);
|
||||
|
||||
// Check error message when source is already disabled
|
||||
esp_err_t err_code = esp_sleep_disable_wakeup_source(ESP_SLEEP_SOURCE_TIMER);
|
||||
esp_err_t err_code = esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
|
||||
TEST_ASSERT(err_code == ESP_ERR_INVALID_STATE);
|
||||
printf("Test case completed successfully.");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user