mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 23:03:34 +08:00
OS X porting: Make unit tests compile on OS X
This commit is contained in:
@@ -77,6 +77,40 @@ static void hrt_unlock(void)
|
||||
sem_post(&_hrt_lock);
|
||||
}
|
||||
|
||||
#ifndef clock_gettime
|
||||
#include <mach/mach_time.h>
|
||||
#define MAC_NANO (+1.0E-9)
|
||||
#define MAC_GIGA UINT64_C(1000000000)
|
||||
#define CLOCK_MONOTONIC 1
|
||||
#define clockid_t int
|
||||
|
||||
static double px4_timebase = 0.0;
|
||||
static uint64_t px4_timestart = 0;
|
||||
|
||||
int clock_gettime(clockid_t clk_id, struct timespec *t)
|
||||
{
|
||||
if (clk_id != CLOCK_MONOTONIC) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// XXX multithreading locking
|
||||
if (!px4_timestart) {
|
||||
mach_timebase_info_data_t tb = { 0 };
|
||||
mach_timebase_info(&tb);
|
||||
px4_timebase = tb.numer;
|
||||
px4_timebase /= tb.denom;
|
||||
px4_timestart = mach_absolute_time();
|
||||
}
|
||||
|
||||
memset(t, 0, sizeof(*t));
|
||||
|
||||
double diff = (mach_absolute_time() - px4_timestart) * px4_timebase;
|
||||
t->tv_sec = diff * MAC_NANO;
|
||||
t->tv_nsec = diff - (t->tv_sec * MAC_GIGA);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Get absolute time.
|
||||
*/
|
||||
|
||||
@@ -86,6 +86,21 @@
|
||||
#define PX4_WARN(...) __px4_log_verbose("WARN", __VA_ARGS__)
|
||||
#define PX4_ERR(...) __px4_log_verbose("ERROR", __VA_ARGS__)
|
||||
|
||||
#elif defined(__PX4_DARWIN)
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#define __px4_log_threads(level, ...) { \
|
||||
printf("%-5s %ld ", level, pthread_self());\
|
||||
printf(__VA_ARGS__);\
|
||||
printf(" (file %s line %d)\n", __FILE__, __LINE__);\
|
||||
}
|
||||
|
||||
#define PX4_DEBUG(...) __px4_log_omit("DEBUG", __VA_ARGS__)
|
||||
#define PX4_INFO(...) __px4_log("INFO", __VA_ARGS__)
|
||||
#define PX4_WARN(...) __px4_log_verbose("WARN", __VA_ARGS__)
|
||||
#define PX4_ERR(...) __px4_log_verbose("ERROR", __VA_ARGS__)
|
||||
|
||||
#elif defined(__PX4_ROS)
|
||||
|
||||
#define PX4_DBG(...)
|
||||
|
||||
@@ -68,10 +68,16 @@ typedef int px4_task_t;
|
||||
#define SCHED_PRIORITY_MAX sched_get_priority_max(SCHED_FIFO)
|
||||
#define SCHED_PRIORITY_MIN sched_get_priority_min(SCHED_FIFO)
|
||||
#define SCHED_PRIORITY_DEFAULT sched_get_priority_max(SCHED_FIFO)
|
||||
#elif defined(__PX4_DARWIN)
|
||||
#define SCHED_PRIORITY_MAX sched_get_priority_max(SCHED_FIFO)
|
||||
#define SCHED_PRIORITY_MIN sched_get_priority_min(SCHED_FIFO)
|
||||
#define SCHED_PRIORITY_DEFAULT sched_get_priority_max(SCHED_FIFO)
|
||||
#elif defined(__PX4_QURT)
|
||||
#define SCHED_PRIORITY_MAX 0
|
||||
#define SCHED_PRIORITY_MIN 0
|
||||
#define SCHED_PRIORITY_DEFAULT 0
|
||||
#else
|
||||
#error "No target OS defined"
|
||||
#endif
|
||||
|
||||
typedef int px4_task_t;
|
||||
|
||||
Reference in New Issue
Block a user