diff --git a/src/platforms/posix/px4_layer/drv_hrt.c b/src/platforms/posix/px4_layer/drv_hrt.c index 0544131705..3b0502866c 100644 --- a/src/platforms/posix/px4_layer/drv_hrt.c +++ b/src/platforms/posix/px4_layer/drv_hrt.c @@ -81,35 +81,23 @@ static void hrt_unlock(void) px4_sem_post(&_hrt_lock); } -#ifdef __PX4_DARWIN - -#include -#define MAC_NANO (+1.0E-9) -#define MAC_GIGA UINT64_C(1000000000) -#define CLOCK_MONOTONIC 1 -#define HRT_LOCK_NAME "/hrt_lock" - -static double px4_timebase = 0.0; +#if defined(__APPLE__) && defined(__MACH__) +#include +#include +#define CLOCK_REALTIME 0 int px4_clock_gettime(clockid_t clk_id, struct timespec *tp) { - if (clk_id != CLOCK_MONOTONIC) { - return 1; + struct timeval now; + int rv = gettimeofday(&now, NULL); + + if(rv) { + return rv; } - if (!px4_timestart) { - mach_timebase_info_data_t tb = {}; - mach_timebase_info(&tb); - px4_timebase = tb.numer; - px4_timebase /= tb.denom; - // px4_timestart = mach_absolute_time(); - } + tp->tv_sec = now.tv_sec; + tp->tv_nsec = now.tv_usec * 1000; - memset(tp, 0, sizeof(*tp)); - - double diff = mach_absolute_time() * px4_timebase; - tp->tv_sec = diff * MAC_NANO; - tp->tv_nsec = diff - (tp->tv_sec * MAC_GIGA); return 0; }