mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 07:43:33 +08:00
Qurt platform custom icm42688p IMU driver (#20753)
- first version of IMU driver for the VOXL 2 platform (Qurt) - this is a customized version of the Invensense ICM42688P driver, it is currently in the VOXL 2 board directory
This commit is contained in:
@@ -59,7 +59,7 @@ typedef int px4_task_t;
|
||||
|
||||
#define px4_task_exit(x) _exit(x)
|
||||
|
||||
#elif defined(__PX4_POSIX) || defined(__PX4_QURT)
|
||||
#elif defined(__PX4_POSIX)
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <time.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#if defined(__PX4_POSIX) || defined(__PX4_QURT)
|
||||
#if defined(__PX4_POSIX)
|
||||
__BEGIN_DECLS
|
||||
__EXPORT int px4_clock_gettime(clockid_t clk_id, struct timespec *tp);
|
||||
__END_DECLS
|
||||
|
||||
@@ -71,7 +71,7 @@ const px4_spi_bus_t *px4_spi_buses{nullptr};
|
||||
|
||||
int px4_find_spi_bus(uint32_t devid)
|
||||
{
|
||||
for (int i = 0; px4_spi_buses != nullptr && i < SPI_BUS_MAX_BUS_ITEMS; ++i) {
|
||||
for (int i = 0; (px4_spi_bus_t *) px4_spi_buses != nullptr && i < SPI_BUS_MAX_BUS_ITEMS; ++i) {
|
||||
const px4_spi_bus_t &bus_data = px4_spi_buses[i];
|
||||
|
||||
if (bus_data.bus == -1) {
|
||||
|
||||
@@ -126,15 +126,10 @@ int hrt_work_queue(struct work_s *work, worker_t worker, void *arg, uint32_t del
|
||||
dq_addlast(&work->dq, &wqueue->q);
|
||||
|
||||
if (px4_getpid() != wqueue->pid) { /* only need to wake up if called from a different thread */
|
||||
#ifdef __PX4_QURT
|
||||
px4_task_kill(wqueue->pid, SIGALRM); /* Wake up the worker thread */
|
||||
#else
|
||||
//wqueue->pid == own task? -> don't signal
|
||||
px4_task_kill(wqueue->pid, SIGCONT); /* Wake up the worker thread */
|
||||
#endif
|
||||
}
|
||||
|
||||
hrt_work_unlock();
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -138,6 +138,16 @@ static void hrt_work_process()
|
||||
/* Default to sleeping for 1 sec */
|
||||
next = 1000000;
|
||||
|
||||
#ifdef __PX4_QURT
|
||||
// In Posix certain signals wake up a sleeping thread but it isn't the case
|
||||
// with the Qurt POSIX implementation. So rather than assume we can come out
|
||||
// of the sleep early by a signal we just wake up more often. The best way to
|
||||
// fix this would be to move to a px4_sem_timedwait. But the current implementation
|
||||
// of that function on Qurt uses this hrt_thread! So, it would all have to be
|
||||
// re-written to use Qurt semaphores which do have timed waits.
|
||||
next = 1000;
|
||||
#endif
|
||||
|
||||
hrt_work_lock();
|
||||
|
||||
work = (struct work_s *)wqueue->q.head;
|
||||
@@ -287,9 +297,5 @@ void hrt_work_queue_init(void)
|
||||
(char *const *)NULL);
|
||||
|
||||
|
||||
#ifdef __PX4_QURT
|
||||
signal(SIGALRM, _sighandler);
|
||||
#else
|
||||
signal(SIGCONT, _sighandler);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <px4_platform_common/defines.h>
|
||||
#include <px4_platform_common/workqueue.h>
|
||||
#include <px4_platform_common/tasks.h>
|
||||
#include <px4_platform_common/posix.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
@@ -125,11 +126,7 @@ int work_queue(int qid, struct work_s *work, worker_t worker, void *arg, uint32_
|
||||
work->qtime = clock_systimer(); /* Time work queued */
|
||||
|
||||
dq_addlast((dq_entry_t *)work, &wqueue->q);
|
||||
#ifdef __PX4_QURT
|
||||
px4_task_kill(wqueue->pid, SIGALRM); /* Wake up the worker thread */
|
||||
#else
|
||||
px4_task_kill(wqueue->pid, SIGCONT); /* Wake up the worker thread */
|
||||
#endif
|
||||
|
||||
work_unlock(qid);
|
||||
return PX4_OK;
|
||||
|
||||
@@ -200,6 +200,7 @@ function(px4_os_prebuild_targets)
|
||||
ARGN ${ARGN})
|
||||
|
||||
add_library(prebuild_targets INTERFACE)
|
||||
target_link_libraries(prebuild_targets INTERFACE drivers_board)
|
||||
add_dependencies(prebuild_targets DEPENDS uorb_headers)
|
||||
|
||||
endfunction()
|
||||
|
||||
@@ -99,6 +99,7 @@ set(ARCHCPUFLAGS
|
||||
|
||||
add_definitions(
|
||||
-D __QURT
|
||||
# -D DEBUG_BUILD # Add this to get extra debug output
|
||||
-D _PROVIDE_POSIX_TIME_DECLS
|
||||
-D _HAS_C9X
|
||||
-D restrict=__restrict__
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2015 Mark Charlebois. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <px4_platform_common/log.h>
|
||||
#include <px4_platform_common/posix.h>
|
||||
#include <semaphore.h>
|
||||
#include <px4_platform_common/workqueue.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
extern px4_sem_t _hrt_work_lock;
|
||||
extern struct wqueue_s g_hrt_work;
|
||||
|
||||
void hrt_work_queue_init(void);
|
||||
int hrt_work_queue(struct work_s *work, worker_t worker, void *arg, uint32_t usdelay);
|
||||
void hrt_work_cancel(struct work_s *work);
|
||||
|
||||
static inline void hrt_work_lock(void);
|
||||
static inline void hrt_work_lock()
|
||||
{
|
||||
px4_sem_wait(&_hrt_work_lock);
|
||||
}
|
||||
|
||||
static inline void hrt_work_unlock(void);
|
||||
static inline void hrt_work_unlock()
|
||||
{
|
||||
px4_sem_post(&_hrt_work_lock);
|
||||
}
|
||||
|
||||
__END_DECLS
|
||||
@@ -0,0 +1,60 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2020 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
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <px4_platform_common/spi.h>
|
||||
|
||||
static inline constexpr px4_spi_bus_device_t initSPIDevice(uint8_t devid_driver)
|
||||
{
|
||||
px4_spi_bus_device_t ret{};
|
||||
ret.cs_gpio = 1; // set to some non-zero value to indicate this is used
|
||||
ret.drdy_gpio = 1;
|
||||
ret.devid = PX4_SPIDEV_ID(PX4_SPI_DEVICE_ID, 0);
|
||||
ret.devtype_driver = devid_driver;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline constexpr px4_spi_bus_t initSPIBus(int bus, const px4_spi_bus_devices_t &devices)
|
||||
{
|
||||
px4_spi_bus_t ret{};
|
||||
|
||||
for (int i = 0; i < SPI_BUS_MAX_DEVICES; ++i) {
|
||||
ret.devices[i] = devices.devices[i];
|
||||
}
|
||||
|
||||
ret.bus = bus;
|
||||
ret.is_external = false; // all buses are marked internal on QuRT
|
||||
ret.requires_locking = false;
|
||||
return ret;
|
||||
}
|
||||
@@ -44,3 +44,4 @@ add_library(px4_layer
|
||||
)
|
||||
|
||||
target_link_libraries(px4_layer PRIVATE work_queue)
|
||||
target_link_libraries(px4_layer PRIVATE drivers_board)
|
||||
|
||||
@@ -66,6 +66,14 @@ static task_entry_t taskmap[PX4_MAX_TASKS];
|
||||
static bool task_mutex_initialized = false;
|
||||
static pthread_mutex_t task_mutex;
|
||||
|
||||
// These are some Qurt pthread stubs needed for compilation and linking
|
||||
extern "C" {
|
||||
|
||||
int pthread_setname_np(pthread_t __target_thread, const char *__name) { return 0; }
|
||||
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy) { return 0; }
|
||||
|
||||
}
|
||||
|
||||
static void *entry_adapter(void *ptr)
|
||||
{
|
||||
task_entry_t *data;
|
||||
@@ -147,11 +155,12 @@ static px4_task_t px4_task_spawn_internal(const char *name, int priority, px4_ma
|
||||
return -1;
|
||||
}
|
||||
|
||||
priority = 255 - priority;
|
||||
|
||||
if (priority < 5) { priority = 5; }
|
||||
|
||||
if (priority > 250) { priority = 250; }
|
||||
// Qurt threads have different priority numbers. 1 is the highest
|
||||
// priority and 254 is the lowest. But we are using the pthread
|
||||
// implementation on Qurt which returns 255 when you call sched_get_priority_max.
|
||||
// So, the big assumption is that the Qurt pthread implementation deals with
|
||||
// this properly when creating the underlying Qurt task.
|
||||
// TODO: Needs to be verified!
|
||||
|
||||
if (strlen(name) >= PX4_TASK_MAX_NAME_LENGTH) {
|
||||
pthread_mutex_unlock(&task_mutex);
|
||||
|
||||
Reference in New Issue
Block a user