Correct ticks being returned from port_get_raw_ticks()

Issue #2958 . Correct calculation of usec back to ticks in port_get_raw_ticks().
This commit is contained in:
DavePutz 2020-06-08 10:52:27 -05:00 committed by GitHub
parent ef87cc3ed3
commit d8bb2d7c6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -118,11 +118,12 @@ uint32_t port_get_saved_word(void) {
uint64_t port_get_raw_ticks(uint8_t* subticks) {
struct timeval tv_now;
gettimeofday(&tv_now, NULL);
uint64_t all_subticks = (uint64_t)tv_now.tv_usec / 32768;
// convert usec back to ticks
uint64_t all_subticks = (uint64_t)tv_now.tv_usec / 1024;
if (subticks != NULL) {
*subticks = all_subticks % 32;
}
return (uint64_t)tv_now.tv_sec * 1024L + all_subticks / 32;
return (uint64_t)tv_now.tv_sec * 1024L + all_subticks;
}
// Enable 1/1024 second tick.