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:
Julian Oes
2018-11-20 14:23:04 +01:00
parent 23264fe579
commit e41518a08b
10 changed files with 76 additions and 67 deletions

View File

@@ -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)

View File

@@ -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 <px4_workqueue.h>
#include <px4_tasks.h>
#include <drivers/drv_hrt.h>
#include <lockstep_scheduler/lockstep_scheduler.h>
#include <semaphore.h>
#include <time.h>
#include <string.h>
#include <errno.h>
#include "hrt_work.h"
static struct sq_queue_s callout_queue;
static void hrt_call_reschedule(void);
#if defined(__PX4_POSIX_SITL)
#include <lockstep_scheduler/lockstep_scheduler.h>
#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

View File

@@ -46,7 +46,7 @@
#include <pthread.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>

View File

@@ -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

View File

@@ -39,7 +39,6 @@
#include <px4_defines.h>
#include <px4_workqueue.h>
#include <perf_counter.h>
#include <drivers/drv_hrt.h>
#include <semaphore.h>
#include <time.h>

View File

@@ -40,6 +40,7 @@
#pragma once
#include <px4_defines.h>
#include <px4_time.h>
#define GPS_INFO(...) PX4_INFO(__VA_ARGS__)
#define GPS_WARN(...) PX4_WARN(__VA_ARGS__)

View File

@@ -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 <stdlib.h>
#if defined(__PX4_POSIX_SITL)
#include <stdlib.h>
#include <unistd.h>
#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
// <string> include.
#ifdef __cplusplus
#include <cstdlib>
#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 <stdlib.h>
#ifdef __cplusplus
#include <cstdlib>
#endif
@@ -102,11 +99,25 @@
#include <unistd.h>
#include <time.h>
#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 <stdlib.h>
#ifdef __cplusplus
#include <cstdlib>
#endif
#pragma GCC poison getenv setenv putenv
#endif /* __PX4_NUTTX */
#endif // defined(__PX4_NUTTX)

View File

@@ -42,6 +42,7 @@
#include <px4_defines.h>
#include <px4_posix.h>
#include <px4_tasks.h>
#include <px4_time.h>
#include <stdint.h>
#include <signal.h>
#include <stdio.h>

View File

@@ -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

View File

@@ -1,5 +1,6 @@
#pragma once
#include <unistd.h>
#include <sys/types.h>
#include <time.h>
#include <pthread.h>
@@ -8,20 +9,7 @@
#define clockid_t unsigned
#endif
#if 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)
#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