ESP32 Wake stub get elapsed time

dovov97815
Posts: 19
Joined: Mon Aug 17, 2020 10:24 am

ESP32 Wake stub get elapsed time

Postby dovov97815 » Wed Aug 19, 2020 5:31 am

Hardware:
Board: ESP32 Dev Module
Core Installation/update date: 16/jun/2020
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10

Description:
when wake stub starts I want to know how much time ESP32 spend in deep sleep, how can I achieve this I tried below code in wake stub but always get 0 in return.

Code: Select all

 static const char RTC_RODATA_ATTR now_str[] = "now=%ld\n";

  // Get current RTC time
  SET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE);
  while (GET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_VALID) == 0) {
    ets_delay_us(1);
  }
  SET_PERI_REG_MASK(RTC_CNTL_INT_CLR_REG, RTC_CNTL_TIME_VALID_INT_CLR);
  uint64_t now = READ_PERI_REG(RTC_CNTL_TIME0_REG);
  
  now |= ((uint64_t)READ_PERI_REG(RTC_CNTL_TIME1_REG)) << 32;

  ets_printf(now_str,now); // print always 0 here
  

snehapawar#
Posts: 20
Joined: Wed Jan 13, 2021 1:11 pm

Re: ESP32 Wake stub get elapsed time

Postby snehapawar# » Sat Oct 01, 2022 7:09 am

Use below lines of code in start of your main code:


struct timeval now;
gettimeofday(&now, NULL);
int sleep_time_ms = ((now.tv_sec - sleep_enter_time.tv_sec) * 1000) + ((now.tv_usec - sleep_enter_time.tv_usec) / 1000);
printf("sleep_time_ms %d\r\n", sleep_time_ms);


this will give you time spend in deep sleep by esp.

Who is online

Users browsing this forum: No registered users and 80 guests