From 0e923fe061171451bd642847812c9c2398daa508 Mon Sep 17 00:00:00 2001 From: Siddharth Purohit Date: Sun, 31 May 2020 17:55:55 +0530 Subject: [PATCH] HAL_Linux: add methods for native clock info methods --- libraries/AP_HAL_Linux/system.cpp | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/libraries/AP_HAL_Linux/system.cpp b/libraries/AP_HAL_Linux/system.cpp index fd40dc4380..d649cdaf4c 100644 --- a/libraries/AP_HAL_Linux/system.cpp +++ b/libraries/AP_HAL_Linux/system.cpp @@ -79,4 +79,43 @@ uint64_t millis64() (state.start_time.tv_nsec*1.0e-9))); } + +uint32_t native_micros() +{ + return native_micros64() & 0xFFFFFFFF; +} + +uint32_t native_millis() +{ + return native_millis64() & 0xFFFFFFFF; +} + +/* + we define a millis16() here to avoid an issue with sitl builds in cygwin + */ +uint16_t native_millis16() +{ + return native_millis64() & 0xFFFF; +} + + +uint64_t native_micros64() +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return 1.0e6*((ts.tv_sec + (ts.tv_nsec*1.0e-9)) - + (state.start_time.tv_sec + + (state.start_time.tv_nsec*1.0e-9))); +} + +uint64_t native_millis64() +{ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return 1.0e3*((ts.tv_sec + (ts.tv_nsec*1.0e-9)) - + (state.start_time.tv_sec + + (state.start_time.tv_nsec*1.0e-9))); +} + + } // namespace AP_HAL