esp32s2: port_get_raw_ticks: Use a more efficient, monotonic routine
While trying to debug #3572, I noticed that I would frequently break in the midst of gettimeofday and that the routine get_adjusted_boot_time had to take and release locks. Furthermore, we don't want "adjusted" boot time, which could go forwards or backwards depending on the adjustment (such as setting the clock used by gettimeofday() to the network time)
This commit is contained in:
parent
1bc770c3dc
commit
9206925bf8
@ -191,14 +191,14 @@ uint32_t port_get_saved_word(void) {
|
||||
}
|
||||
|
||||
uint64_t port_get_raw_ticks(uint8_t* subticks) {
|
||||
struct timeval tv_now;
|
||||
gettimeofday(&tv_now, NULL);
|
||||
// convert usec back to ticks
|
||||
uint64_t all_subticks = (uint64_t)(tv_now.tv_usec * 2) / 71;
|
||||
// Convert microseconds to subticks of 1/32768 seconds
|
||||
// 32768/1000000 = 64/15625 in lowest terms
|
||||
// this arithmetic overflows after 570 years
|
||||
int64_t all_subticks = esp_timer_get_time() * 512 / 15625;
|
||||
if (subticks != NULL) {
|
||||
*subticks = all_subticks % 32;
|
||||
}
|
||||
return (uint64_t)tv_now.tv_sec * 1024L + all_subticks / 32;
|
||||
return all_subticks / 32;
|
||||
}
|
||||
|
||||
// Enable 1/1024 second tick.
|
||||
|
Loading…
Reference in New Issue
Block a user