how to SET esp_timer_get_time() ?

cyberman54
Posts: 27
Joined: Sun Jan 14, 2018 7:47 pm

how to SET esp_timer_get_time() ?

Postby cyberman54 » Thu Dec 10, 2020 2:31 pm

I am using a time critial library (MCCI LMIC), that depends on micros() as monotonic time base. In arduino-esp32 micros() is hardwired to esp_timer_get_time(), which does not persist it's counter value during deep sleep. Thus micros() cannot act as a monotonic counter after waking up from sleep.

https://github.com/espressif/arduino-es ... isc.c#L134

Code: Select all

unsigned long IRAM_ATTR micros()
{
    return (unsigned long) (esp_timer_get_time());
}
How can i solve this, without hacking the library?

Is there a way to add an offset by app to esp_timer_get_time()?
- Perhaps by using a wake stub, which adds a sleep time offset immediately after wake up?
- Or is there a way to overwite the micros() function of arduino-esp32 with a customized version?

lbernstone
Posts: 637
Joined: Mon Jul 22, 2019 3:20 pm

Re: how to SET esp_timer_get_time() ?

Postby lbernstone » Thu Dec 10, 2020 3:40 pm

The rtc clock will run through deep sleep if the rtc power domain is on. Note that the following example shows ticks, not usec. https://github.com/espressif/esp-idf/bl ... rtc.h#L524

Code: Select all

#include <soc/rtc.h>
void setup() {
  Serial.begin(115200);
  Serial.printf("rtc_time: %d", rtc_time_get());
  Serial.flush();
  esp_sleep_enable_timer_wakeup(5000000ULL);
  esp_deep_sleep_start();
}
void loop() {}

cyberman54
Posts: 27
Joined: Sun Jan 14, 2018 7:47 pm

Re: how to SET esp_timer_get_time() ?

Postby cyberman54 » Thu Dec 10, 2020 8:08 pm

lbernstone wrote:
Thu Dec 10, 2020 3:40 pm
The rtc clock will run through deep sleep if the rtc power domain is on.
Thanks for this hint!
But how can i bind micros() or millis() in arduino-esp32 to RTC clock?

Who is online

Users browsing this forum: No registered users and 73 guests