mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-02 03:49:12 +08:00
platforms: clean up various build/linking issues
This makes sure lockstep is only built for SITL builds and fixes the existing builds.
This commit is contained in:
@@ -55,9 +55,11 @@ add_library(px4_layer
|
|||||||
target_compile_definitions(px4_layer PRIVATE MODULE_NAME="px4")
|
target_compile_definitions(px4_layer PRIVATE MODULE_NAME="px4")
|
||||||
target_link_libraries(px4_layer PRIVATE work_queue)
|
target_link_libraries(px4_layer PRIVATE work_queue)
|
||||||
target_link_libraries(px4_layer PRIVATE px4_daemon)
|
target_link_libraries(px4_layer PRIVATE px4_daemon)
|
||||||
target_link_libraries(px4_layer PRIVATE lockstep_scheduler)
|
|
||||||
|
|
||||||
|
if(LOCKSTEP_SCHEDULER_NEEDED)
|
||||||
|
target_link_libraries(px4_layer PRIVATE lockstep_scheduler)
|
||||||
include_directories(${PX4_SOURCE_DIR}/src/platforms/posix/lockstep_scheduler/include)
|
include_directories(${PX4_SOURCE_DIR}/src/platforms/posix/lockstep_scheduler/include)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
if (EXTRA_DEPENDS)
|
if (EXTRA_DEPENDS)
|
||||||
|
|||||||
@@ -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
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* 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.
|
* High-resolution timer with callouts and timekeeping.
|
||||||
*/
|
*/
|
||||||
@@ -43,49 +43,53 @@
|
|||||||
#include <px4_workqueue.h>
|
#include <px4_workqueue.h>
|
||||||
#include <px4_tasks.h>
|
#include <px4_tasks.h>
|
||||||
#include <drivers/drv_hrt.h>
|
#include <drivers/drv_hrt.h>
|
||||||
#include <lockstep_scheduler/lockstep_scheduler.h>
|
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "hrt_work.h"
|
#include "hrt_work.h"
|
||||||
|
|
||||||
|
#if defined(__PX4_POSIX_SITL)
|
||||||
static struct sq_queue_s callout_queue;
|
#include <lockstep_scheduler/lockstep_scheduler.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static void hrt_call_reschedule(void);
|
|
||||||
|
|
||||||
// Intervals in usec
|
// Intervals in usec
|
||||||
#define HRT_INTERVAL_MIN 50
|
static constexpr unsigned HRT_INTERVAL_MIN = 50;
|
||||||
#define HRT_INTERVAL_MAX 50000000
|
static constexpr unsigned HRT_INTERVAL_MAX = 50000000;
|
||||||
|
|
||||||
|
static struct sq_queue_s callout_queue;
|
||||||
static px4_sem_t _hrt_lock;
|
static px4_sem_t _hrt_lock;
|
||||||
static struct work_s _hrt_work;
|
static struct work_s _hrt_work;
|
||||||
|
|
||||||
#ifndef __PX4_QURT
|
#ifndef __PX4_QURT
|
||||||
static hrt_abstime px4_timestart_monotonic = 0;
|
static hrt_abstime px4_timestart_monotonic = 0;
|
||||||
#else
|
#else
|
||||||
static int32_t dsp_offset = 0;
|
static int32_t dsp_offset = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static hrt_abstime _start_delay_time = 0;
|
static hrt_abstime _start_delay_time = 0;
|
||||||
static hrt_abstime _delay_interval = 0;
|
static hrt_abstime _delay_interval = 0;
|
||||||
static hrt_abstime max_time = 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;
|
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);
|
__EXPORT hrt_abstime hrt_reset(void);
|
||||||
|
|
||||||
|
|
||||||
hrt_abstime hrt_absolute_time_offset(void)
|
hrt_abstime hrt_absolute_time_offset(void)
|
||||||
{
|
{
|
||||||
|
#ifndef __PX4_QURT
|
||||||
return px4_timestart_monotonic;
|
return px4_timestart_monotonic;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hrt_lock(void)
|
static void hrt_lock(void)
|
||||||
@@ -590,18 +594,9 @@ void abstime_to_ts(struct timespec *ts, hrt_abstime abstime)
|
|||||||
ts->tv_nsec = abstime * 1000;
|
ts->tv_nsec = abstime * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__PX4_POSIX_SITL)
|
||||||
int px4_clock_gettime(clockid_t clk_id, struct timespec *tp)
|
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) {
|
if (clk_id == CLOCK_MONOTONIC) {
|
||||||
|
|
||||||
const uint64_t abstime = lockstep_scheduler.get_absolute_time();
|
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 {
|
} else {
|
||||||
return system_clock_gettime(clk_id, tp);
|
return system_clock_gettime(clk_id, tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int px4_clock_settime(clockid_t clk_id, const struct timespec *ts)
|
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;
|
const uint64_t scheduled = time_us + px4_timestart_monotonic;
|
||||||
return lockstep_scheduler.cond_timedwait(cond, mutex, scheduled);
|
return lockstep_scheduler.cond_timedwait(cond, mutex, scheduled);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#if defined(__PX4_DARWIN) || defined(__PX4_CYGWIN) || defined(__PX4_POSIX)
|
#if (defined(__PX4_DARWIN) || defined(__PX4_CYGWIN) || defined(__PX4_POSIX)) && !defined(__PX4_QURT)
|
||||||
|
|
||||||
#include <px4_posix.h>
|
#include <px4_posix.h>
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ set(QURT_LAYER_SRCS
|
|||||||
px4_qurt_impl.cpp
|
px4_qurt_impl.cpp
|
||||||
px4_qurt_tasks.cpp
|
px4_qurt_tasks.cpp
|
||||||
lib_crc32.c
|
lib_crc32.c
|
||||||
../../../posix/src/px4_layer/drv_hrt.c
|
../../../posix/src/px4_layer/drv_hrt.cpp
|
||||||
qurt_stubs.c
|
qurt_stubs.c
|
||||||
main.cpp
|
main.cpp
|
||||||
shmem_qurt.cpp
|
shmem_qurt.cpp
|
||||||
|
|||||||
@@ -39,7 +39,6 @@
|
|||||||
|
|
||||||
#include <px4_defines.h>
|
#include <px4_defines.h>
|
||||||
#include <px4_workqueue.h>
|
#include <px4_workqueue.h>
|
||||||
#include <perf_counter.h>
|
|
||||||
#include <drivers/drv_hrt.h>
|
#include <drivers/drv_hrt.h>
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <px4_defines.h>
|
#include <px4_defines.h>
|
||||||
|
#include <px4_time.h>
|
||||||
|
|
||||||
#define GPS_INFO(...) PX4_INFO(__VA_ARGS__)
|
#define GPS_INFO(...) PX4_INFO(__VA_ARGS__)
|
||||||
#define GPS_WARN(...) PX4_WARN(__VA_ARGS__)
|
#define GPS_WARN(...) PX4_WARN(__VA_ARGS__)
|
||||||
|
|||||||
+22
-11
@@ -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
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -64,10 +64,12 @@
|
|||||||
* still needs to be used, thus we remap system_exit to exit.
|
* still needs to be used, thus we remap system_exit to exit.
|
||||||
*/
|
*/
|
||||||
#define system_exit exit
|
#define system_exit exit
|
||||||
#ifdef __PX4_POSIX
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
|
#if defined(__PX4_POSIX_SITL)
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define system_usleep usleep
|
#define system_usleep usleep
|
||||||
#pragma GCC poison usleep
|
#pragma GCC poison usleep
|
||||||
#define system_sleep sleep
|
#define system_sleep sleep
|
||||||
@@ -81,18 +83,13 @@
|
|||||||
// We can't poison pthread_cond_timedwait because it seems to be used in the
|
// We can't poison pthread_cond_timedwait because it seems to be used in the
|
||||||
// <string> include.
|
// <string> include.
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#endif
|
#endif
|
||||||
#pragma GCC poison exit
|
#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 <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#endif
|
#endif
|
||||||
@@ -102,11 +99,25 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#else // defined(__PX4_POSIX_SITL)
|
||||||
|
|
||||||
#define system_usleep usleep
|
#define system_usleep usleep
|
||||||
#define system_sleep sleep
|
#define system_sleep sleep
|
||||||
|
|
||||||
#define system_clock_gettime clock_gettime
|
#define system_clock_gettime clock_gettime
|
||||||
#define system_clock_settime clock_settime
|
#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 <stdlib.h>
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#include <cstdlib>
|
||||||
|
#endif
|
||||||
#pragma GCC poison getenv setenv putenv
|
#pragma GCC poison getenv setenv putenv
|
||||||
#endif /* __PX4_NUTTX */
|
#endif // defined(__PX4_NUTTX)
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include <px4_defines.h>
|
#include <px4_defines.h>
|
||||||
#include <px4_posix.h>
|
#include <px4_posix.h>
|
||||||
#include <px4_tasks.h>
|
#include <px4_tasks.h>
|
||||||
|
#include <px4_time.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|||||||
+16
-4
@@ -50,7 +50,7 @@
|
|||||||
#define sem_setprotocol(s,p)
|
#define sem_setprotocol(s,p)
|
||||||
#endif
|
#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
|
__BEGIN_DECLS
|
||||||
|
|
||||||
@@ -71,12 +71,24 @@ __EXPORT int px4_sem_destroy(px4_sem_t *s);
|
|||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
|
//#elif defined(__PX4_QURT)
|
||||||
|
|
||||||
|
//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
|
#else
|
||||||
|
|
||||||
__BEGIN_DECLS
|
|
||||||
|
|
||||||
typedef sem_t px4_sem_t;
|
typedef sem_t px4_sem_t;
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
#define px4_sem_init sem_init
|
#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_wait sem_wait
|
||||||
@@ -85,7 +97,7 @@ typedef sem_t px4_sem_t;
|
|||||||
#define px4_sem_getvalue sem_getvalue
|
#define px4_sem_getvalue sem_getvalue
|
||||||
#define px4_sem_destroy sem_destroy
|
#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);
|
__EXPORT int px4_sem_timedwait(px4_sem_t *sem, const struct timespec *abstime);
|
||||||
#else
|
#else
|
||||||
#define px4_sem_timedwait sem_timedwait
|
#define px4_sem_timedwait sem_timedwait
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@@ -8,20 +9,7 @@
|
|||||||
#define clockid_t unsigned
|
#define clockid_t unsigned
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__PX4_QURT)
|
#if defined(__PX4_POSIX_SITL) || defined(__PX4_QURT)
|
||||||
|
|
||||||
#include <sys/timespec.h>
|
|
||||||
|
|
||||||
__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)
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
__EXPORT int px4_clock_gettime(clockid_t clk_id, struct timespec *tp);
|
__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);
|
const struct timespec *abstime);
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#elif defined(__PX4_NUTTX)
|
#else
|
||||||
|
|
||||||
#define px4_clock_gettime system_clock_gettime
|
#define px4_clock_gettime system_clock_gettime
|
||||||
#define px4_clock_settime system_clock_settime
|
#define px4_clock_settime system_clock_settime
|
||||||
#define px4_usleep system_usleep
|
#define px4_usleep system_usleep
|
||||||
#define px4_sleep system_sleep
|
#define px4_sleep system_sleep
|
||||||
|
#define px4_pthread_cond_timedwait system_pthread_cond_timedwait
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user