From f50d48f0057d3873dfe035380cab9fdd9b94c6f3 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 23 Nov 2021 13:40:38 +1100 Subject: [PATCH] AP_HAL: tidy set/get of hw RTC --- libraries/AP_HAL/AP_HAL_Boards.h | 4 ---- libraries/AP_HAL/Util.cpp | 28 ---------------------------- libraries/AP_HAL/Util.h | 4 ++-- libraries/AP_HAL/board/linux.h | 2 -- 4 files changed, 2 insertions(+), 36 deletions(-) diff --git a/libraries/AP_HAL/AP_HAL_Boards.h b/libraries/AP_HAL/AP_HAL_Boards.h index d429a357f6..dd782dca33 100644 --- a/libraries/AP_HAL/AP_HAL_Boards.h +++ b/libraries/AP_HAL/AP_HAL_Boards.h @@ -177,10 +177,6 @@ #define HAL_WITH_IO_MCU 0 #endif -#ifndef HAL_HAVE_GETTIME_SETTIME -#define HAL_HAVE_GETTIME_SETTIME 0 -#endif - // this is used as a general mechanism to make a 'small' build by // dropping little used features. We use this to allow us to keep // FMUv2 going for as long as possible diff --git a/libraries/AP_HAL/Util.cpp b/libraries/AP_HAL/Util.cpp index a094f469d5..3afa823be4 100644 --- a/libraries/AP_HAL/Util.cpp +++ b/libraries/AP_HAL/Util.cpp @@ -68,34 +68,6 @@ int AP_HAL::Util::vsnprintf(char* str, size_t size, const char *format, va_list return int(ret); } -uint64_t AP_HAL::Util::get_hw_rtc() const -{ -#if defined(__APPLE__) && defined(__MACH__) - struct timeval ts; - gettimeofday(&ts, nullptr); - return ((long long)((ts.tv_sec * 1000000) + ts.tv_usec)); -#elif HAL_HAVE_GETTIME_SETTIME - struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - const uint64_t seconds = ts.tv_sec; - const uint64_t nanoseconds = ts.tv_nsec; - return (seconds * 1000000ULL + nanoseconds/1000ULL); -#endif - - // no HW clock (or not one worth bothering with) - return 0; -} - -void AP_HAL::Util::set_hw_rtc(uint64_t time_utc_usec) -{ -#if HAL_HAVE_GETTIME_SETTIME - timespec ts; - ts.tv_sec = time_utc_usec/1000000ULL; - ts.tv_nsec = (time_utc_usec % 1000000ULL) * 1000ULL; - clock_settime(CLOCK_REALTIME, &ts); -#endif -} - void AP_HAL::Util::set_soft_armed(const bool b) { if (b != soft_armed) { diff --git a/libraries/AP_HAL/Util.h b/libraries/AP_HAL/Util.h index 19a79a9f6f..e7a725cb45 100644 --- a/libraries/AP_HAL/Util.h +++ b/libraries/AP_HAL/Util.h @@ -94,12 +94,12 @@ public: /* set HW RTC in UTC microseconds */ - virtual void set_hw_rtc(uint64_t time_utc_usec); + virtual void set_hw_rtc(uint64_t time_utc_usec) = 0; /* get system clock in UTC microseconds */ - virtual uint64_t get_hw_rtc() const; + virtual uint64_t get_hw_rtc() const = 0; enum class FlashBootloader { OK=0, diff --git a/libraries/AP_HAL/board/linux.h b/libraries/AP_HAL/board/linux.h index ef7675b366..c62953c14e 100644 --- a/libraries/AP_HAL/board/linux.h +++ b/libraries/AP_HAL/board/linux.h @@ -289,8 +289,6 @@ #define HAL_MAG_PROBE_LIST PROBE_MAG_SPI(LIS3MDL, lis3mdl, false, ROTATION_ROLL_180_YAW_90) #define HAL_OPTFLOW_PX4FLOW_I2C_BUS 0 - #define HAL_HAVE_GETTIME_SETTIME 1 - #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1 //#define HAL_BARO_ALLOW_INIT_NO_BARO