From af8cbee6d535c0dd8c6b5cbe6fd132dc65c90b29 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Tue, 27 Sep 2016 10:32:09 +0200 Subject: [PATCH] Support 10.11 and 10.12 in parallel in PX4 --- cmake/posix/px4_impl_posix.cmake | 10 +++++++++ src/platforms/posix/px4_layer/drv_hrt.c | 27 ++++++++++++++++++++++++- src/platforms/px4_time.h | 15 +++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/cmake/posix/px4_impl_posix.cmake b/cmake/posix/px4_impl_posix.cmake index 42514476ce..e76ef7e768 100644 --- a/cmake/posix/px4_impl_posix.cmake +++ b/cmake/posix/px4_impl_posix.cmake @@ -200,6 +200,16 @@ if(UNIX AND APPLE) message(FATAL_ERROR "PX4 Firmware requires XCode 8 or newer on Mac OS. Version installed on this system: ${CMAKE_CXX_COMPILER_VERSION}") endif() + EXEC_PROGRAM(uname ARGS -v OUTPUT_VARIABLE DARWIN_VERSION) + STRING(REGEX MATCH "[0-9]+" DARWIN_VERSION ${DARWIN_VERSION}) + message(STATUS "DARWIN_VERSION: ${DARWIN_VERSION}") + if (DARWIN_VERSION LESS 16) + list(APPEND added_definitions + -DCLOCK_MONOTONIC=1 + -D__PX4_APPLE_LEGACY + ) + endif() + else() set(added_definitions diff --git a/src/platforms/posix/px4_layer/drv_hrt.c b/src/platforms/posix/px4_layer/drv_hrt.c index 7cedbd0e7c..b7f9029715 100644 --- a/src/platforms/posix/px4_layer/drv_hrt.c +++ b/src/platforms/posix/px4_layer/drv_hrt.c @@ -93,7 +93,32 @@ static void hrt_unlock(void) px4_sem_post(&_hrt_lock); } -#if defined(__QURT) +#if defined(__PX4_APPLE_LEGACY) +#include +#include + +int px4_clock_gettime(clockid_t clk_id, struct timespec *tp) +{ + struct timeval now; + int rv = gettimeofday(&now, NULL); + + if (rv) { + return rv; + } + + tp->tv_sec = now.tv_sec; + tp->tv_nsec = now.tv_usec * 1000; + + return 0; +} + +int px4_clock_settime(clockid_t clk_id, struct timespec *tp) +{ + /* do nothing right now */ + return 0; +} + +#elif defined(__QURT) #include "dspal_time.h" diff --git a/src/platforms/px4_time.h b/src/platforms/px4_time.h index a3bcc90605..2d310b54b9 100644 --- a/src/platforms/px4_time.h +++ b/src/platforms/px4_time.h @@ -3,7 +3,20 @@ #include #include -#if defined(__PX4_LINUX) || defined(__PX4_NUTTX) || defined(__PX4_DARWIN) +#if defined(__PX4_APPLE_LEGACY) + +__BEGIN_DECLS + +#define clockid_t unsigned + +int px4_clock_gettime(clockid_t clk_id, struct timespec *tp); +int px4_clock_settime(clockid_t clk_id, struct timespec *tp); + +__EXPORT unsigned int sleep(unsigned int sec); + +__END_DECLS + +#elif defined(__PX4_LINUX) || defined(__PX4_NUTTX) || defined(__PX4_DARWIN) #define px4_clock_gettime clock_gettime #define px4_clock_settime clock_settime