2016-12-08 09:22:10 -05:00
|
|
|
#include "unity.h"
|
2017-04-21 00:32:50 -04:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include "esp_sleep.h"
|
2016-12-08 09:22:10 -05:00
|
|
|
#include "driver/rtc_io.h"
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
|
2016-12-14 03:38:45 -05:00
|
|
|
TEST_CASE("esp_deepsleep works", "[deepsleep][ignore]")
|
2016-12-08 09:22:10 -05:00
|
|
|
{
|
|
|
|
esp_deep_sleep(2000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void deep_sleep_task(void* arg)
|
|
|
|
{
|
|
|
|
esp_deep_sleep_start();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_deep_sleep_from_app_cpu()
|
|
|
|
{
|
|
|
|
xTaskCreatePinnedToCore(&deep_sleep_task, "ds", 2048, NULL, 5, NULL, 1);
|
|
|
|
|
|
|
|
// keep running some non-IRAM code
|
|
|
|
vTaskSuspendAll();
|
|
|
|
while(true) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 00:32:50 -04:00
|
|
|
TEST_CASE("wake up from deep sleep using timer", "[deepsleep][ignore]")
|
2016-12-08 09:22:10 -05:00
|
|
|
{
|
2017-04-21 00:32:50 -04:00
|
|
|
esp_sleep_enable_timer_wakeup(2000000);
|
2016-12-08 09:22:10 -05:00
|
|
|
esp_deep_sleep_start();
|
|
|
|
}
|
|
|
|
|
2017-04-21 00:32:50 -04:00
|
|
|
TEST_CASE("wake up from light sleep using timer", "[deepsleep]")
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
TEST_ASSERT_INT32_WITHIN(500, 2000, (int) dt);
|
|
|
|
}
|
|
|
|
|
2016-12-14 03:38:45 -05:00
|
|
|
TEST_CASE("enter deep sleep on APP CPU and wake up using timer", "[deepsleep][ignore]")
|
2016-12-08 09:22:10 -05:00
|
|
|
{
|
2017-04-21 00:32:50 -04:00
|
|
|
esp_sleep_enable_timer_wakeup(2000000);
|
2016-12-08 09:22:10 -05:00
|
|
|
do_deep_sleep_from_app_cpu();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-14 03:38:45 -05:00
|
|
|
TEST_CASE("wake up using ext0 (13 high)", "[deepsleep][ignore]")
|
2016-12-08 09:22:10 -05:00
|
|
|
{
|
|
|
|
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));
|
2017-04-21 00:32:50 -04:00
|
|
|
ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, 1));
|
2016-12-08 09:22:10 -05:00
|
|
|
esp_deep_sleep_start();
|
|
|
|
}
|
|
|
|
|
2016-12-14 03:38:45 -05:00
|
|
|
TEST_CASE("wake up using ext0 (13 low)", "[deepsleep][ignore]")
|
2016-12-08 09:22:10 -05:00
|
|
|
{
|
|
|
|
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));
|
2017-04-21 00:32:50 -04:00
|
|
|
ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, 0));
|
2016-12-08 09:22:10 -05:00
|
|
|
esp_deep_sleep_start();
|
|
|
|
}
|
|
|
|
|
2016-12-14 03:38:45 -05:00
|
|
|
TEST_CASE("wake up using ext1 when RTC_PERIPH is off (13 high)", "[deepsleep][ignore]")
|
2016-12-16 01:10:07 -05:00
|
|
|
{
|
|
|
|
// This test needs external pulldown
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
|
2017-04-21 00:32:50 -04:00
|
|
|
ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_HIGH));
|
2016-12-16 01:10:07 -05:00
|
|
|
esp_deep_sleep_start();
|
|
|
|
}
|
|
|
|
|
2016-12-14 03:38:45 -05:00
|
|
|
TEST_CASE("wake up using ext1 when RTC_PERIPH is off (13 low)", "[deepsleep][ignore]")
|
2016-12-16 01:10:07 -05:00
|
|
|
{
|
|
|
|
// This test needs external pullup
|
|
|
|
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
|
2017-04-21 00:32:50 -04:00
|
|
|
ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW));
|
2016-12-16 01:10:07 -05:00
|
|
|
esp_deep_sleep_start();
|
|
|
|
}
|
|
|
|
|
2016-12-14 03:38:45 -05:00
|
|
|
TEST_CASE("wake up using ext1 when RTC_PERIPH is on (13 high)", "[deepsleep][ignore]")
|
2016-12-08 09:22:10 -05:00
|
|
|
{
|
|
|
|
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));
|
2017-04-21 00:32:50 -04:00
|
|
|
ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON));
|
|
|
|
ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ANY_HIGH));
|
2016-12-08 09:22:10 -05:00
|
|
|
esp_deep_sleep_start();
|
|
|
|
}
|
|
|
|
|
2016-12-14 03:38:45 -05:00
|
|
|
TEST_CASE("wake up using ext1 when RTC_PERIPH is on (13 low)", "[deepsleep][ignore]")
|
2016-12-08 09:22:10 -05:00
|
|
|
{
|
|
|
|
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));
|
2017-04-21 00:32:50 -04:00
|
|
|
ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON));
|
|
|
|
ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW));
|
2016-12-08 09:22:10 -05:00
|
|
|
esp_deep_sleep_start();
|
|
|
|
}
|