Skip to content

Commit

Permalink
adis16497 move to px4 work queue
Browse files Browse the repository at this point in the history
  • Loading branch information
dagar committed Mar 15, 2019
1 parent 74b1882 commit 6fee1b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
13 changes: 6 additions & 7 deletions src/drivers/imu/adis16497/ADIS16497.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -495,18 +496,16 @@ ADIS16497::data_ready_interrupt(int irq, void *context, void *arg)
ADIS16497 *dev = reinterpret_cast<ADIS16497 *>(arg);

/* make another measurement */
dev->measure();
dev->ScheduleNow();

return PX4_OK;
}

void
ADIS16497::measure_trampoline(void *arg)
ADIS16497::Run()
{
ADIS16497 *dev = reinterpret_cast<ADIS16497 *>(arg);

/* make another measurement */
dev->measure();
measure();
}

int
Expand Down
13 changes: 4 additions & 9 deletions src/drivers/imu/adis16497/ADIS16497.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <lib/conversion/rotation.h>
#include <perf/perf_counter.h>
#include <ecl/geo/geo.h>
#include <px4_work_queue/ScheduledWorkItem.hpp>

#define ADIS16497_GYRO_DEFAULT_RATE 1000
#define ADIS16497_GYRO_DEFAULT_DRIVER_FILTER_FREQ 80
Expand Down Expand Up @@ -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);
Expand All @@ -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 {};
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6fee1b8

Please sign in to comment.