Skip to content

#839 Time (relative) in deep sleep #840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: public
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions xs/platforms/esp/xsHost.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ void modGetTimeOfDay(struct modTimeVal *tv, struct modTimeZone *tz)
}
}

#if ESP32
int64_t RTC_SLOW_ATTR __microsecondsOffset = 0;
#endif

void modSetTime(uint32_t seconds)
{
#if !ESP32
Expand All @@ -664,7 +668,9 @@ void modSetTime(uint32_t seconds)
tv.tv_sec = seconds;
tv.tv_usec = 0;

uint64_t usBefore = kMicroseconds64();
settimeofday(&tv, NULL); //@@ implementation doesn't use timezone yet....
__microsecondsOffset += kMicroseconds64() - usBefore;
#endif
}

Expand Down Expand Up @@ -867,9 +873,11 @@ void IRAM_ATTR timer_group0_isr(void *para)

#if ESP32

uint32_t modMilliseconds(void)
uint64_t kMicroseconds64(void)
{
return xTaskGetTickCount();
struct timeval tv_now;
gettimeofday(&tv_now, NULL);
return (uint64_t) tv_now.tv_sec * 1000000L + (uint64_t) tv_now.tv_usec - __microsecondsOffset;
}

#endif
Expand Down
7 changes: 4 additions & 3 deletions xs/platforms/esp/xsHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ extern uint8_t ESP_setBaud(int baud);
*/

#if ESP32
extern uint32_t modMilliseconds(void);
#define modMicroseconds() (uint32_t)(esp_timer_get_time())

extern uint64_t kMicroseconds64(void);
#define modMilliseconds() ((uint32_t) (kMicroseconds64() / 1000L))
#define modMicroseconds() ((uint32_t) kMicroseconds64())

#define modDelayMilliseconds(ms) vTaskDelay(ms)
#define modDelayMicroseconds(us) vTaskDelay(((us) + 500) / 1000)

Expand Down