drivers/differential_pressure move all to px4 work queue

This commit is contained in:
Daniel Agar
2019-05-24 12:58:55 -04:00
parent 83d3ead821
commit e1bc975065
8 changed files with 36 additions and 73 deletions
@@ -84,9 +84,9 @@ protected:
* Perform a poll cycle; collect from the previous measurement * Perform a poll cycle; collect from the previous measurement
* and start a new one. * and start a new one.
*/ */
virtual void cycle(); void Run() override;
virtual int measure(); int measure() override;
virtual int collect(); int collect() override;
}; };
@@ -174,7 +174,7 @@ ETSAirspeed::collect()
} }
void void
ETSAirspeed::cycle() ETSAirspeed::Run()
{ {
int ret; int ret;
@@ -198,14 +198,10 @@ ETSAirspeed::cycle()
/* /*
* Is there a collect->measure gap? * Is there a collect->measure gap?
*/ */
if (_measure_ticks > USEC2TICK(CONVERSION_INTERVAL)) { if (_measure_interval > CONVERSION_INTERVAL) {
/* schedule a fresh cycle call when we are ready to measure again */ /* schedule a fresh cycle call when we are ready to measure again */
work_queue(HPWORK, ScheduleDelayed(_measure_interval - CONVERSION_INTERVAL);
&_work,
(worker_t)&Airspeed::cycle_trampoline,
this,
_measure_ticks - USEC2TICK(CONVERSION_INTERVAL));
return; return;
} }
@@ -224,11 +220,7 @@ ETSAirspeed::cycle()
_collect_phase = true; _collect_phase = true;
/* schedule a fresh cycle call when the measurement is done */ /* schedule a fresh cycle call when the measurement is done */
work_queue(HPWORK, ScheduleDelayed(CONVERSION_INTERVAL);
&_work,
(worker_t)&Airspeed::cycle_trampoline,
this,
USEC2TICK(CONVERSION_INTERVAL));
} }
/** /**
@@ -99,9 +99,9 @@ protected:
* Perform a poll cycle; collect from the previous measurement * Perform a poll cycle; collect from the previous measurement
* and start a new one. * and start a new one.
*/ */
virtual void cycle(); void Run() override;
virtual int measure(); int measure() override;
virtual int collect(); int collect() override;
math::LowPassFilter2p _filter{MEAS_RATE, MEAS_DRIVER_FILTER_FREQ}; math::LowPassFilter2p _filter{MEAS_RATE, MEAS_DRIVER_FILTER_FREQ};
@@ -238,7 +238,7 @@ MEASAirspeed::collect()
} }
void void
MEASAirspeed::cycle() MEASAirspeed::Run()
{ {
int ret; int ret;
@@ -261,14 +261,10 @@ MEASAirspeed::cycle()
/* /*
* Is there a collect->measure gap? * Is there a collect->measure gap?
*/ */
if (_measure_ticks > USEC2TICK(CONVERSION_INTERVAL)) { if (_measure_interval > CONVERSION_INTERVAL) {
/* schedule a fresh cycle call when we are ready to measure again */ /* schedule a fresh cycle call when we are ready to measure again */
work_queue(HPWORK, ScheduleDelayed(_measure_interval - CONVERSION_INTERVAL);
&_work,
(worker_t)&Airspeed::cycle_trampoline,
this,
_measure_ticks - USEC2TICK(CONVERSION_INTERVAL));
return; return;
} }
@@ -287,11 +283,7 @@ MEASAirspeed::cycle()
_collect_phase = true; _collect_phase = true;
/* schedule a fresh cycle call when the measurement is done */ /* schedule a fresh cycle call when the measurement is done */
work_queue(HPWORK, ScheduleDelayed(CONVERSION_INTERVAL);
&_work,
(worker_t)&Airspeed::cycle_trampoline,
this,
USEC2TICK(CONVERSION_INTERVAL));
} }
/** /**
@@ -272,7 +272,7 @@ MS5525::collect()
} }
void void
MS5525::cycle() MS5525::Run()
{ {
int ret = PX4_ERROR; int ret = PX4_ERROR;
@@ -292,11 +292,10 @@ MS5525::cycle()
_collect_phase = false; _collect_phase = false;
// is there a collect->measure gap? // is there a collect->measure gap?
if (_measure_ticks > USEC2TICK(CONVERSION_INTERVAL)) { if (_measure_interval > CONVERSION_INTERVAL) {
// schedule a fresh cycle call when we are ready to measure again // schedule a fresh cycle call when we are ready to measure again
work_queue(HPWORK, &_work, (worker_t)&Airspeed::cycle_trampoline, this, ScheduleDelayed(_measure_interval - CONVERSION_INTERVAL);
_measure_ticks - USEC2TICK(CONVERSION_INTERVAL));
return; return;
} }
@@ -315,5 +314,5 @@ MS5525::cycle()
_collect_phase = true; _collect_phase = true;
// schedule a fresh cycle call when the measurement is done // schedule a fresh cycle call when the measurement is done
work_queue(HPWORK, &_work, (worker_t)&Airspeed::cycle_trampoline, this, USEC2TICK(CONVERSION_INTERVAL)); ScheduleDelayed(CONVERSION_INTERVAL);
} }
@@ -71,7 +71,7 @@ private:
* Perform a poll cycle; collect from the previous measurement * Perform a poll cycle; collect from the previous measurement
* and start a new one. * and start a new one.
*/ */
void cycle() override; void Run() override;
int measure() override; int measure() override;
int collect() override; int collect() override;
@@ -168,7 +168,7 @@ SDP3X::collect()
} }
void void
SDP3X::cycle() SDP3X::Run()
{ {
int ret = PX4_ERROR; int ret = PX4_ERROR;
@@ -181,7 +181,7 @@ SDP3X::cycle()
} }
// schedule a fresh cycle call when the measurement is done // schedule a fresh cycle call when the measurement is done
work_queue(HPWORK, &_work, (worker_t)&Airspeed::cycle_trampoline, this, USEC2TICK(CONVERSION_INTERVAL)); ScheduleDelayed(CONVERSION_INTERVAL);
} }
bool SDP3X::crc(const uint8_t data[], unsigned size, uint8_t checksum) bool SDP3X::crc(const uint8_t data[], unsigned size, uint8_t checksum)
@@ -87,7 +87,7 @@ private:
* Perform a poll cycle; collect from the previous measurement * Perform a poll cycle; collect from the previous measurement
* and start a new one. * and start a new one.
*/ */
void cycle() override; void Run() override;
int measure() override { return 0; } int measure() override { return 0; }
int collect() override; int collect() override;
int probe() override; int probe() override;
+10 -21
View File
@@ -58,8 +58,9 @@
Airspeed::Airspeed(int bus, int address, unsigned conversion_interval, const char *path) : Airspeed::Airspeed(int bus, int address, unsigned conversion_interval, const char *path) :
I2C("Airspeed", path, bus, address, 100000), I2C("Airspeed", path, bus, address, 100000),
ScheduledWorkItem(px4::device_bus_to_wq(get_device_id())),
_sensor_ok(false), _sensor_ok(false),
_measure_ticks(0), _measure_interval(0),
_collect_phase(false), _collect_phase(false),
_diff_pres_offset(0.0f), _diff_pres_offset(0.0f),
_airspeed_pub(nullptr), _airspeed_pub(nullptr),
@@ -69,11 +70,6 @@ Airspeed::Airspeed(int bus, int address, unsigned conversion_interval, const cha
_sample_perf(perf_alloc(PC_ELAPSED, "aspd_read")), _sample_perf(perf_alloc(PC_ELAPSED, "aspd_read")),
_comms_errors(perf_alloc(PC_COUNT, "aspd_com_err")) _comms_errors(perf_alloc(PC_COUNT, "aspd_com_err"))
{ {
// enable debug() calls
_debug_enabled = false;
// work_cancel in the dtor will explode if we don't do this...
memset(&_work, 0, sizeof(_work));
} }
Airspeed::~Airspeed() Airspeed::~Airspeed()
@@ -148,10 +144,10 @@ Airspeed::ioctl(device::file_t *filp, int cmd, unsigned long arg)
/* set default polling rate */ /* set default polling rate */
case SENSOR_POLLRATE_DEFAULT: { case SENSOR_POLLRATE_DEFAULT: {
/* do we need to start internal polling? */ /* do we need to start internal polling? */
bool want_start = (_measure_ticks == 0); bool want_start = (_measure_interval == 0);
/* set interval for next measurement to minimum legal value */ /* set interval for next measurement to minimum legal value */
_measure_ticks = USEC2TICK(_conversion_interval); _measure_interval = USEC2TICK(_conversion_interval);
/* if we need to start the poll state machine, do it */ /* if we need to start the poll state machine, do it */
if (want_start) { if (want_start) {
@@ -164,18 +160,18 @@ Airspeed::ioctl(device::file_t *filp, int cmd, unsigned long arg)
/* adjust to a legal polling interval in Hz */ /* adjust to a legal polling interval in Hz */
default: { default: {
/* do we need to start internal polling? */ /* do we need to start internal polling? */
bool want_start = (_measure_ticks == 0); bool want_start = (_measure_interval == 0);
/* convert hz to tick interval via microseconds */ /* convert hz to tick interval via microseconds */
unsigned ticks = USEC2TICK(1000000 / arg); unsigned interval = (1000000 / arg);
/* check against maximum rate */ /* check against maximum rate */
if (ticks < USEC2TICK(_conversion_interval)) { if (interval < _conversion_interval) {
return -EINVAL; return -EINVAL;
} }
/* update interval for next measurement */ /* update interval for next measurement */
_measure_ticks = ticks; _measure_interval = interval;
/* if we need to start the poll state machine, do it */ /* if we need to start the poll state machine, do it */
if (want_start) { if (want_start) {
@@ -207,18 +203,11 @@ Airspeed::start()
_collect_phase = false; _collect_phase = false;
/* schedule a cycle to start things */ /* schedule a cycle to start things */
work_queue(HPWORK, &_work, (worker_t)&Airspeed::cycle_trampoline, this, 1); ScheduleNow();
} }
void void
Airspeed::stop() Airspeed::stop()
{ {
work_cancel(HPWORK, &_work); ScheduleClear();
}
void
Airspeed::cycle_trampoline(void *arg)
{
Airspeed *dev = (Airspeed *)arg;
dev->cycle();
} }
+4 -13
View File
@@ -39,15 +39,15 @@
#include <drivers/drv_hrt.h> #include <drivers/drv_hrt.h>
#include <px4_config.h> #include <px4_config.h>
#include <px4_defines.h> #include <px4_defines.h>
#include <px4_workqueue.h>
#include <perf/perf_counter.h> #include <perf/perf_counter.h>
#include <uORB/topics/differential_pressure.h> #include <uORB/topics/differential_pressure.h>
#include <uORB/uORB.h> #include <uORB/uORB.h>
#include <px4_work_queue/ScheduledWorkItem.hpp>
/* Default I2C bus */ /* Default I2C bus */
static constexpr uint8_t PX4_I2C_BUS_DEFAULT = PX4_I2C_BUS_EXPANSION; static constexpr uint8_t PX4_I2C_BUS_DEFAULT = PX4_I2C_BUS_EXPANSION;
class __EXPORT Airspeed : public device::I2C class __EXPORT Airspeed : public device::I2C, public px4::ScheduledWorkItem
{ {
public: public:
Airspeed(int bus, int address, unsigned conversion_interval, const char *path); Airspeed(int bus, int address, unsigned conversion_interval, const char *path);
@@ -69,13 +69,12 @@ protected:
* Perform a poll cycle; collect from the previous measurement * Perform a poll cycle; collect from the previous measurement
* and start a new one. * and start a new one.
*/ */
virtual void cycle() = 0; virtual void Run() = 0;
virtual int measure() = 0; virtual int measure() = 0;
virtual int collect() = 0; virtual int collect() = 0;
work_s _work;
bool _sensor_ok; bool _sensor_ok;
int _measure_ticks; int _measure_interval;
bool _collect_phase; bool _collect_phase;
float _diff_pres_offset; float _diff_pres_offset;
@@ -102,14 +101,6 @@ protected:
*/ */
void stop(); void stop();
/**
* Static trampoline from the workq context; because we don't have a
* generic workq wrapper yet.
*
* @param arg Instance pointer for the driver that is polling.
*/
static void cycle_trampoline(void *arg);
/** /**
* add a new report to the reports queue * add a new report to the reports queue
* *