esp32: Deactivate wakeup trigger after first wakeup

The timer wakeup function once activated cannot be disabled later using existing api. If user wants to use different wakeup sources after first sleep but it does not work. This change disables timer wakeup trigger in configuration that will be set into appropriate RTC registers in esp_light_sleep_start() function.

Added function esp_sleep_disable_wakeup_source() to deactivate wakeup trigger for selected source.
Updated documentation for this function in sleep_modes.rst file to pass make html.
Updated unit test to check this functionality for light sleep.
The test_sleep.c unit test is updated to add reliability for auto unit testing.

(TW#18952)
Closes https://github.com/espressif/esp-idf/issues/1677
This commit is contained in:
Alex Lisitsyn
2018-03-14 10:54:45 +05:00
parent 77eae33a7e
commit 2d90da0817
5 changed files with 86 additions and 4 deletions

View File

@@ -5,6 +5,9 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define ESP_EXT0_WAKEUP_LEVEL_LOW 0
#define ESP_EXT0_WAKEUP_LEVEL_HIGH 1
TEST_CASE("esp_deepsleep works", "[deepsleep][reset=DEEPSLEEP_RESET]")
{
esp_deep_sleep(2000000);
@@ -33,7 +36,6 @@ TEST_CASE("wake up using timer", "[deepsleep][reset=DEEPSLEEP_RESET]")
esp_deep_sleep_start();
}
TEST_CASE("wake up from light sleep using timer", "[deepsleep]")
{
esp_sleep_enable_timer_wakeup(2000000);
@@ -46,6 +48,44 @@ TEST_CASE("wake up from light sleep using timer", "[deepsleep]")
TEST_ASSERT_INT32_WITHIN(500, 2000, (int) dt);
}
TEST_CASE("wake up disable timer for ext0 wakeup (13 low)", "[deepsleep][ignore]")
{
// Setup timer to wakeup with timeout
esp_sleep_enable_timer_wakeup(2000000);
struct timeval tv_start, tv_stop;
gettimeofday(&tv_start, NULL);
esp_light_sleep_start();
gettimeofday(&tv_stop, NULL);
float dt = (tv_stop.tv_sec - tv_start.tv_sec) * 1e3f +
(tv_stop.tv_usec - tv_start.tv_usec) * 1e-3f;
printf("Timer sleep time = %d\r\n", (int)dt);
TEST_ASSERT_INT32_WITHIN(500, 2000, (int) dt);
// Setup ext0 configuration to wake up
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
ESP_ERROR_CHECK(gpio_pullup_en(GPIO_NUM_13));
ESP_ERROR_CHECK(gpio_pulldown_dis(GPIO_NUM_13));
ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, ESP_EXT0_WAKEUP_LEVEL_LOW));
// Disable timer wakeup trigger to wakeup from ext0 source
// instead of timer wakeup
ESP_ERROR_CHECK(esp_sleep_disable_timer_wakeup());
printf("Waiting low level on GPIO_13\r\n");
gettimeofday(&tv_start, NULL);
esp_light_sleep_start();
gettimeofday(&tv_stop, NULL);
dt = (tv_stop.tv_sec - tv_start.tv_sec) * 1e3f +
(tv_stop.tv_usec - tv_start.tv_usec) * 1e-3f;
printf("Ext0 sleep time = %d\r\n", (int)dt);
// Check error message
esp_err_t err_code = esp_sleep_disable_timer_wakeup();
TEST_ASSERT(err_code == ESP_ERR_INVALID_STATE);
}
#ifndef CONFIG_FREERTOS_UNICORE
TEST_CASE("enter deep sleep on APP CPU and wake up using timer", "[deepsleep][reset=DEEPSLEEP_RESET]")
{
@@ -60,7 +100,7 @@ TEST_CASE("wake up using ext0 (13 high)", "[deepsleep][ignore]")
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
ESP_ERROR_CHECK(gpio_pullup_dis(GPIO_NUM_13));
ESP_ERROR_CHECK(gpio_pulldown_en(GPIO_NUM_13));
ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, 1));
ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, ESP_EXT0_WAKEUP_LEVEL_HIGH));
esp_deep_sleep_start();
}
@@ -69,7 +109,7 @@ TEST_CASE("wake up using ext0 (13 low)", "[deepsleep][ignore]")
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
ESP_ERROR_CHECK(gpio_pullup_en(GPIO_NUM_13));
ESP_ERROR_CHECK(gpio_pulldown_dis(GPIO_NUM_13));
ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, 0));
ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, ESP_EXT0_WAKEUP_LEVEL_LOW));
esp_deep_sleep_start();
}