mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 04:43:33 +00:00
esp32: Fix not the right time spent in a deep sleep
Before entering the deep sleep, the RTC and FRC counters are synchronized. Updating the boot_time. Added a unit test for this case. Fixed warnings for MULTIPLE_STAGES Closes https://github.com/espressif/esp-idf/issues/1840
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
#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
|
||||
@@ -338,3 +340,35 @@ TEST_CASE("disable source trigger behavior", "[deepsleep]")
|
||||
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);
|
||||
|
Reference in New Issue
Block a user