diff --git a/src/platforms/posix/px4_layer/px4_posix_impl.cpp b/src/platforms/posix/px4_layer/px4_posix_impl.cpp index 94387f648b..37132a0641 100644 --- a/src/platforms/posix/px4_layer/px4_posix_impl.cpp +++ b/src/platforms/posix/px4_layer/px4_posix_impl.cpp @@ -48,6 +48,7 @@ #include "systemlib/param/param.h" #include "hrt_work.h" #include +#include "px4_time.h" extern pthread_t _shell_task_id; @@ -55,8 +56,26 @@ __BEGIN_DECLS long PX4_TICKS_PER_SEC = sysconf(_SC_CLK_TCK); +#ifdef __PX4_DARWIN extern void hrt_init(void); +int px4_clock_gettime(clockid_t clk_id, struct timespec *tp) +{ + uint64_t currtime = hrt_absolute_time(); + + tp->tv_sec = currtime / (1000 * 1000); + tp->tv_nsec = (currtime - (currtime * 1000 * 1000)) * 1000; + + return 0; +} + +int px4_clock_settime(clockid_t clk_id, struct timespec *tp) +{ + /* do nothing right now */ +} + +#endif + __END_DECLS namespace px4 diff --git a/src/platforms/px4_tasks.h b/src/platforms/px4_tasks.h index 3d36a65cfd..9dc237e63b 100644 --- a/src/platforms/px4_tasks.h +++ b/src/platforms/px4_tasks.h @@ -80,6 +80,12 @@ typedef int px4_task_t; #error "No target OS defined" #endif +#if defined (__PX4_LINUX) || defined(__PX4_NUTTX) +#include +#else +#define prctl(_action, _string, _pid) +#endif + typedef int px4_task_t; typedef struct { diff --git a/src/platforms/px4_time.h b/src/platforms/px4_time.h index 5a93dedf40..22751b3a99 100644 --- a/src/platforms/px4_time.h +++ b/src/platforms/px4_time.h @@ -8,6 +8,20 @@ #define px4_clock_gettime clock_gettime #define px4_clock_settime clock_settime +#elif defined(__PX4_DARWIN) + +__BEGIN_DECLS + +#define clockid_t unsigned +#define CLOCK_REALTIME 0 + +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_QURT) #include