8000 Correct ticks being returned from port_get_raw_ticks() · jensechu/circuitpython@d8bb2d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit d8bb2d7

Browse files
authored
Correct ticks being returned from port_get_raw_ticks()
Issue adafruit#2958 . Correct calculation of usec back to ticks in port_get_raw_ticks().
1 parent ef87cc3 commit d8bb2d7

File tree

1 file changed

+3
-2
lines changed
  • ports/esp32s2/supervisor

1 file changed

+3
-2
lines changed

ports/esp32s2/supervisor/port.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ uint32_t port_get_saved_word(void) {
118118
uint64_t port_get_raw_ticks(uint8_t* subticks) {
119119
struct timeval tv_now;
120120
gettimeofday(&tv_now, NULL);
121-
uint64_t all_subticks = (uint64_t)tv_now.tv_usec / 32768;
121+
// convert usec back to ticks
122+
uint64_t all_subticks = (uint64_t)tv_now.tv_usec / 1024;
122123
if (subticks != NULL) {
123124
*subticks = all_subticks % 32;
124125
}
125-
return (uint64_t)tv_now.tv_sec * 1024L + all_subticks / 32;
126+
return (uint64_t)tv_now.tv_sec * 1024L + all_subticks;
126127
}
127128

128129
// Enable 1/1024 second tick.

0 commit comments

Comments
 (0)
0