diff --git a/platforms/posix/src/px4_layer/CMakeLists.txt b/platforms/posix/src/px4_layer/CMakeLists.txt index 2dbf47c4bb..7ce430ae0e 100644 --- a/platforms/posix/src/px4_layer/CMakeLists.txt +++ b/platforms/posix/src/px4_layer/CMakeLists.txt @@ -55,9 +55,11 @@ add_library(px4_layer target_compile_definitions(px4_layer PRIVATE MODULE_NAME="px4") target_link_libraries(px4_layer PRIVATE work_queue) target_link_libraries(px4_layer PRIVATE px4_daemon) -target_link_libraries(px4_layer PRIVATE lockstep_scheduler) -include_directories(${PX4_SOURCE_DIR}/src/platforms/posix/lockstep_scheduler/include) +if(LOCKSTEP_SCHEDULER_NEEDED) + target_link_libraries(px4_layer PRIVATE lockstep_scheduler) + include_directories(${PX4_SOURCE_DIR}/src/platforms/posix/lockstep_scheduler/include) +endif() if (EXTRA_DEPENDS) diff --git a/platforms/posix/src/px4_layer/drv_hrt.cpp b/platforms/posix/src/px4_layer/drv_hrt.cpp index cdf6c30a54..fe6d35b6fe 100644 --- a/platforms/posix/src/px4_layer/drv_hrt.cpp +++ b/platforms/posix/src/px4_layer/drv_hrt.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2012, 2013 PX4 Development Team. All rights reserved. + * Copyright (c) 2012 - 2018 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,7 +32,7 @@ ****************************************************************************/ /** - * @file drv_hrt.c + * @file drv_hrt.cpp * * High-resolution timer with callouts and timekeeping. */ @@ -43,49 +43,53 @@ #include #include #include -#include #include #include #include #include #include "hrt_work.h" - -static struct sq_queue_s callout_queue; - - -static void hrt_call_reschedule(void); +#if defined(__PX4_POSIX_SITL) +#include +#endif // Intervals in usec -#define HRT_INTERVAL_MIN 50 -#define HRT_INTERVAL_MAX 50000000 +static constexpr unsigned HRT_INTERVAL_MIN = 50; +static constexpr unsigned HRT_INTERVAL_MAX = 50000000; +static struct sq_queue_s callout_queue; static px4_sem_t _hrt_lock; static struct work_s _hrt_work; + #ifndef __PX4_QURT static hrt_abstime px4_timestart_monotonic = 0; #else static int32_t dsp_offset = 0; #endif + static hrt_abstime _start_delay_time = 0; static hrt_abstime _delay_interval = 0; static hrt_abstime max_time = 0; -pthread_mutex_t _hrt_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t _hrt_mutex = PTHREAD_MUTEX_INITIALIZER; +#if defined(__PX4_POSIX_SITL) static LockstepScheduler lockstep_scheduler; +#endif -static void -hrt_call_invoke(void); - -static hrt_abstime -_hrt_absolute_time_internal(void); +hrt_abstime hrt_absolute_time_offset(void); +static void hrt_call_reschedule(void); +static void hrt_call_invoke(void); +static hrt_abstime _hrt_absolute_time_internal(void); __EXPORT hrt_abstime hrt_reset(void); - hrt_abstime hrt_absolute_time_offset(void) { +#ifndef __PX4_QURT return px4_timestart_monotonic; +#else + return 0; +#endif } static void hrt_lock(void) @@ -590,18 +594,9 @@ void abstime_to_ts(struct timespec *ts, hrt_abstime abstime) ts->tv_nsec = abstime * 1000; } +#if defined(__PX4_POSIX_SITL) int px4_clock_gettime(clockid_t clk_id, struct timespec *tp) { -#if defined(__PX4_QURT) - // Don't use the timestart on the DSP on Snapdragon because we manually - // set the px4_timestart using the hrt_set_absolute_time_offset(). - return clock_gettime(clk_id, &tp); - -#elif defined(__PX4_POSIX_EAGLE) || defined(__PX4_POSIX_EXCELSIOR) - // Don't do any offseting on the Linux side on the Snapdragon. - return clock_gettime(clk_id, &tp); -#else - if (clk_id == CLOCK_MONOTONIC) { const uint64_t abstime = lockstep_scheduler.get_absolute_time(); @@ -611,8 +606,6 @@ int px4_clock_gettime(clockid_t clk_id, struct timespec *tp) } else { return system_clock_gettime(clk_id, tp); } - -#endif } int px4_clock_settime(clockid_t clk_id, const struct timespec *ts) @@ -660,3 +653,4 @@ int px4_pthread_cond_timedwait(pthread_cond_t *cond, const uint64_t scheduled = time_us + px4_timestart_monotonic; return lockstep_scheduler.cond_timedwait(cond, mutex, scheduled); } +#endif diff --git a/platforms/posix/src/px4_layer/px4_sem.cpp b/platforms/posix/src/px4_layer/px4_sem.cpp index f3598a349b..bb02319bc2 100644 --- a/platforms/posix/src/px4_layer/px4_sem.cpp +++ b/platforms/posix/src/px4_layer/px4_sem.cpp @@ -46,7 +46,7 @@ #include #include -#if defined(__PX4_DARWIN) || defined(__PX4_CYGWIN) || defined(__PX4_POSIX) +#if (defined(__PX4_DARWIN) || defined(__PX4_CYGWIN) || defined(__PX4_POSIX)) && !defined(__PX4_QURT) #include diff --git a/platforms/qurt/src/px4_layer/CMakeLists.txt b/platforms/qurt/src/px4_layer/CMakeLists.txt index 87affa5a40..c9a4dac893 100644 --- a/platforms/qurt/src/px4_layer/CMakeLists.txt +++ b/platforms/qurt/src/px4_layer/CMakeLists.txt @@ -40,7 +40,7 @@ set(QURT_LAYER_SRCS px4_qurt_impl.cpp px4_qurt_tasks.cpp lib_crc32.c - ../../../posix/src/px4_layer/drv_hrt.c + ../../../posix/src/px4_layer/drv_hrt.cpp qurt_stubs.c main.cpp shmem_qurt.cpp diff --git a/platforms/qurt/src/px4_layer/drv_hrt.c b/platforms/qurt/src/px4_layer/drv_hrt.c index 052a9b24e1..80e2c97a9e 100644 --- a/platforms/qurt/src/px4_layer/drv_hrt.c +++ b/platforms/qurt/src/px4_layer/drv_hrt.c @@ -39,7 +39,6 @@ #include #include -#include #include #include #include diff --git a/src/drivers/gps/definitions.h b/src/drivers/gps/definitions.h index 2d402f0c2d..7d483212c9 100644 --- a/src/drivers/gps/definitions.h +++ b/src/drivers/gps/definitions.h @@ -40,6 +40,7 @@ #pragma once #include +#include #define GPS_INFO(...) PX4_INFO(__VA_ARGS__) #define GPS_WARN(...) PX4_WARN(__VA_ARGS__) diff --git a/src/include/visibility.h b/src/include/visibility.h index b5044e216f..0f8494fb53 100644 --- a/src/include/visibility.h +++ b/src/include/visibility.h @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Copyright (C) 2012-2018 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -64,10 +64,12 @@ * still needs to be used, thus we remap system_exit to exit. */ #define system_exit exit -#ifdef __PX4_POSIX -#include +#if defined(__PX4_POSIX_SITL) + +#include #include + #define system_usleep usleep #pragma GCC poison usleep #define system_sleep sleep @@ -81,18 +83,13 @@ // We can't poison pthread_cond_timedwait because it seems to be used in the // include. - #ifdef __cplusplus #include #endif #pragma GCC poison exit -#endif -#ifdef __PX4_NUTTX -/* On NuttX we call clearenv() so we cannot use getenv() and others (see px4_task_spawn_cmd() in px4_nuttx_tasks.c). - * We need to include the headers declaring getenv() before the pragma, otherwise it will trigger a poison error. - */ #include + #ifdef __cplusplus #include #endif @@ -102,11 +99,25 @@ #include #include +#else // defined(__PX4_POSIX_SITL) + #define system_usleep usleep #define system_sleep sleep - #define system_clock_gettime clock_gettime #define system_clock_settime clock_settime +#define system_pthread_cond_timedwait pthread_cond_timedwait +#endif + + +#if defined(__PX4_NUTTX) +/* On NuttX we call clearenv() so we cannot use getenv() and others (see + * px4_task_spawn_cmd() in px4_nuttx_tasks.c). + * We need to include the headers declaring getenv() before the pragma, + * otherwise it will trigger a poison error. */ +#include +#ifdef __cplusplus +#include +#endif #pragma GCC poison getenv setenv putenv -#endif /* __PX4_NUTTX */ +#endif // defined(__PX4_NUTTX) diff --git a/src/platforms/common/work_queue/hrt_thread.c b/src/platforms/common/work_queue/hrt_thread.c index e17b90ddba..df1f0bd75e 100644 --- a/src/platforms/common/work_queue/hrt_thread.c +++ b/src/platforms/common/work_queue/hrt_thread.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include diff --git a/src/platforms/px4_sem.h b/src/platforms/px4_sem.h index 661fb97953..970a8985fa 100644 --- a/src/platforms/px4_sem.h +++ b/src/platforms/px4_sem.h @@ -50,7 +50,7 @@ #define sem_setprotocol(s,p) #endif -#if defined(__PX4_DARWIN) || defined(__PX4_CYGWIN) || defined(__PX4_POSIX) +#if (defined(__PX4_DARWIN) || defined(__PX4_CYGWIN) || defined(__PX4_POSIX)) && !defined(__PX4_QURT) __BEGIN_DECLS @@ -71,24 +71,36 @@ __EXPORT int px4_sem_destroy(px4_sem_t *s); __END_DECLS -#else +//#elif defined(__PX4_QURT) -__BEGIN_DECLS +//typedef sem_t px4_sem_t; + +//#define px4_sem_init sem_init +//#define px4_sem_setprotocol sem_setprotocol +//#define px4_sem_wait sem_wait +//#define px4_sem_trywait sem_trywait +//#define px4_sem_post sem_post +//#define px4_sem_getvalue sem_getvalue +//#define px4_sem_destroy sem_destroy + +#else typedef sem_t px4_sem_t; +__BEGIN_DECLS + #define px4_sem_init sem_init -#define px4_sem_setprotocol sem_setprotocol +#define px4_sem_setprotocol sem_setprotocol #define px4_sem_wait sem_wait -#define px4_sem_trywait sem_trywait +#define px4_sem_trywait sem_trywait #define px4_sem_post sem_post #define px4_sem_getvalue sem_getvalue #define px4_sem_destroy sem_destroy -#ifdef __PX4_QURT +#if defined(__PX4_QURT) __EXPORT int px4_sem_timedwait(px4_sem_t *sem, const struct timespec *abstime); #else -#define px4_sem_timedwait sem_timedwait +#define px4_sem_timedwait sem_timedwait #endif __END_DECLS diff --git a/src/platforms/px4_time.h b/src/platforms/px4_time.h index f4ab83acf9..f6d5e4c66d 100644 --- a/src/platforms/px4_time.h +++ b/src/platforms/px4_time.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -8,20 +9,7 @@ #define clockid_t unsigned #endif -#if defined(__PX4_QURT) - -#include - -__BEGIN_DECLS - -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_POSIX) +#if defined(__PX4_POSIX_SITL) || defined(__PX4_QURT) __BEGIN_DECLS __EXPORT int px4_clock_gettime(clockid_t clk_id, struct timespec *tp); @@ -34,11 +22,12 @@ __EXPORT int px4_pthread_cond_timedwait(pthread_cond_t *cond, const struct timespec *abstime); __END_DECLS -#elif defined(__PX4_NUTTX) +#else #define px4_clock_gettime system_clock_gettime #define px4_clock_settime system_clock_settime #define px4_usleep system_usleep #define px4_sleep system_sleep +#define px4_pthread_cond_timedwait system_pthread_cond_timedwait #endif