mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-03-02 11:43:56 -04:00
AP_HAL: tidy set/get of hw RTC
This commit is contained in:
parent
522056d6f7
commit
f50d48f005
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user