From 6fee1b8831e982303c35d551d634f92017142171 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Mon, 25 Feb 2019 10:09:50 -0500 Subject: [PATCH] adis16497 move to px4 work queue --- src/drivers/imu/adis16497/ADIS16497.cpp | 13 ++++++------- src/drivers/imu/adis16497/ADIS16497.hpp | 13 ++++--------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/drivers/imu/adis16497/ADIS16497.cpp b/src/drivers/imu/adis16497/ADIS16497.cpp index 73d26eba53fc..8b18f19f8722 100644 --- a/src/drivers/imu/adis16497/ADIS16497.cpp +++ b/src/drivers/imu/adis16497/ADIS16497.cpp @@ -68,6 +68,7 @@ using namespace time_literals; ADIS16497::ADIS16497(int bus, const char *path_accel, const char *path_gyro, uint32_t device, enum Rotation rotation) : SPI("ADIS16497", path_accel, bus, device, SPIDEV_MODE3, 5000000), + ScheduledWorkItem(px4::device_bus_to_wq(get_device_id())), _gyro(new ADIS16497_gyro(this, path_gyro)), _sample_perf(perf_alloc(PC_ELAPSED, "ADIS16497_read")), _sample_interval_perf(perf_alloc(PC_INTERVAL, "ADIS16497_read_int")), @@ -474,7 +475,7 @@ ADIS16497::start() stop(); // Start polling at the specified rate - hrt_call_every(&_call, 1000, _call_interval, (hrt_callout)&ADIS16497::measure_trampoline, this); + ScheduleOnInterval(_call_interval, 1000); #endif } @@ -485,7 +486,7 @@ ADIS16497::stop() // Disable data ready callback px4_arch_gpiosetevent(GPIO_SPI1_DRDY1_ADIS16497, false, false, false, nullptr, nullptr); #else - hrt_cancel(&_call); + ScheduleClear(); #endif } @@ -495,18 +496,16 @@ ADIS16497::data_ready_interrupt(int irq, void *context, void *arg) ADIS16497 *dev = reinterpret_cast(arg); /* make another measurement */ - dev->measure(); + dev->ScheduleNow(); return PX4_OK; } void -ADIS16497::measure_trampoline(void *arg) +ADIS16497::Run() { - ADIS16497 *dev = reinterpret_cast(arg); - /* make another measurement */ - dev->measure(); + measure(); } int diff --git a/src/drivers/imu/adis16497/ADIS16497.hpp b/src/drivers/imu/adis16497/ADIS16497.hpp index 54c0d8302a63..607ae2e19321 100644 --- a/src/drivers/imu/adis16497/ADIS16497.hpp +++ b/src/drivers/imu/adis16497/ADIS16497.hpp @@ -49,6 +49,7 @@ #include #include #include +#include #define ADIS16497_GYRO_DEFAULT_RATE 1000 #define ADIS16497_GYRO_DEFAULT_DRIVER_FILTER_FREQ 80 @@ -94,7 +95,7 @@ static const uint32_t crc32_tab[] = { class ADIS16497_gyro; -class ADIS16497 : public device::SPI +class ADIS16497 : public device::SPI, public px4::ScheduledWorkItem { public: ADIS16497(int bus, const char *path_accel, const char *path_gyro, uint32_t device, enum Rotation rotation); @@ -116,7 +117,6 @@ class ADIS16497 : public device::SPI private: ADIS16497_gyro *_gyro{nullptr}; - struct hrt_call _call {}; unsigned _call_interval{1000}; struct gyro_calibration_s _gyro_scale {}; @@ -197,15 +197,10 @@ class ADIS16497 : public device::SPI int reset(); /** - * Static trampoline from the hrt_call context; because we don't have a - * generic hrt wrapper yet. - * - * Called by the HRT in interrupt context at the specified rate if + * Called by the ScheduledWorkItem at the specified rate if * automatic polling is enabled. - * - * @param arg Instance pointer for the driver that is polling. */ - static void measure_trampoline(void *arg); + void Run() override; static int data_ready_interrupt(int irq, void *context, void *arg);