#include "soc/rtc.h" // for wakeup trigger defines
#include "soc/rtc_cntl_reg.h" // for read rtc registers directly (cause)
#include "soc/soc.h" // for direct register read macros
+#include "rom/rtc.h"
+#include "esp_newlib.h"
#define ESP_EXT0_WAKEUP_LEVEL_LOW 0
#define ESP_EXT0_WAKEUP_LEVEL_HIGH 1
TEST_ASSERT(err_code == ESP_ERR_INVALID_STATE);
}
+static RTC_DATA_ATTR struct timeval start;
+static void trigger_deepsleep(void)
+{
+ printf("Trigger deep sleep. Waiting 30 sec ...\n");
+
+ // Simulate the dispersion of the calibration coefficients at start-up.
+ // Corrupt the calibration factor.
+ esp_clk_slowclk_cal_set(esp_clk_slowclk_cal_get() - 1000000);
+ esp_set_time_from_rtc();
+
+ // Delay for time error accumulation.
+ vTaskDelay(30000/portTICK_RATE_MS);
+
+ // Save start time. Deep sleep.
+ gettimeofday(&start, NULL);
+ esp_sleep_enable_timer_wakeup(1000);
+ esp_deep_sleep_start();
+}
+
+static void check_time_deepsleep(void)
+{
+ struct timeval stop;
+ RESET_REASON reason = rtc_get_reset_reason(0);
+ TEST_ASSERT(reason == DEEPSLEEP_RESET);
+ gettimeofday(&stop, NULL);
+ // Time dt_ms must in any case be positive.
+ int dt_ms = (stop.tv_sec - start.tv_sec) * 1000 + (stop.tv_usec - start.tv_usec) / 1000;
+ printf("delta time = %d \n", dt_ms);
+ TEST_ASSERT_MESSAGE(dt_ms > 0, "Time in deep sleep is negative");
+}
+
+TEST_CASE_MULTIPLE_STAGES("check a time after wakeup from deep sleep", "[deepsleep][reset=DEEPSLEEP_RESET]", trigger_deepsleep, check_time_deepsleep);
#define UNITY_TEST_FN_SET(...) \
static test_func UNITY_TEST_UID(test_functions)[] = {__VA_ARGS__}; \
- static char* UNITY_TEST_UID(test_fn_name)[] = FN_NAME_SET(PP_NARG(__VA_ARGS__), __VA_ARGS__)
+ static const char* UNITY_TEST_UID(test_fn_name)[] = FN_NAME_SET(PP_NARG(__VA_ARGS__), __VA_ARGS__)
typedef void (* test_func)(void);
const char* file;
int line;
uint8_t test_fn_count;
- char ** test_fn_name;
+ const char ** test_fn_name;
struct test_desc_t* next;
};