mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 16:48:52 +08:00
lps25h move to px4 work queue
This commit is contained in:
@@ -57,7 +57,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <px4_work_queue/ScheduledWorkItem.hpp>
|
||||
#include <nuttx/clock.h>
|
||||
|
||||
#include <board_config.h>
|
||||
@@ -189,11 +189,7 @@ enum LPS25H_BUS {
|
||||
LPS25H_BUS_SPI
|
||||
};
|
||||
|
||||
#ifndef CONFIG_SCHED_WORKQUEUE
|
||||
# error This requires CONFIG_SCHED_WORKQUEUE.
|
||||
#endif
|
||||
|
||||
class LPS25H : public cdev::CDev
|
||||
class LPS25H : public cdev::CDev, public px4::ScheduledWorkItem
|
||||
{
|
||||
public:
|
||||
LPS25H(device::Device *interface, const char *path);
|
||||
@@ -213,8 +209,7 @@ protected:
|
||||
device::Device *_interface;
|
||||
|
||||
private:
|
||||
work_s _work{};
|
||||
unsigned _measure_ticks{0};
|
||||
unsigned _measure_interval{0};
|
||||
|
||||
ringbuffer::RingBuffer *_reports{nullptr};
|
||||
bool _collect_phase{false};
|
||||
@@ -259,15 +254,7 @@ private:
|
||||
* and measurement to provide the most recent measurement possible
|
||||
* at the next interval.
|
||||
*/
|
||||
void cycle();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
void Run() override;
|
||||
|
||||
/**
|
||||
* Write a register.
|
||||
@@ -312,6 +299,7 @@ extern "C" __EXPORT int lps25h_main(int argc, char *argv[]);
|
||||
|
||||
LPS25H::LPS25H(device::Device *interface, const char *path) :
|
||||
CDev(path),
|
||||
ScheduledWorkItem(px4::device_bus_to_wq(interface->get_device_id())),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, "lps25h_read")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, "lps25h_comms_errors"))
|
||||
@@ -386,7 +374,7 @@ LPS25H::read(struct file *filp, char *buffer, size_t buflen)
|
||||
}
|
||||
|
||||
/* if automatic measurement is enabled */
|
||||
if (_measure_ticks > 0) {
|
||||
if (_measure_interval > 0) {
|
||||
|
||||
/*
|
||||
* While there is space in the caller's buffer, and reports, copy them.
|
||||
@@ -448,10 +436,10 @@ LPS25H::ioctl(struct file *filp, int cmd, unsigned long arg)
|
||||
/* set default polling rate */
|
||||
case SENSOR_POLLRATE_DEFAULT: {
|
||||
/* 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 */
|
||||
_measure_ticks = USEC2TICK(LPS25H_CONVERSION_INTERVAL);
|
||||
_measure_interval = (LPS25H_CONVERSION_INTERVAL);
|
||||
|
||||
/* if we need to start the poll state machine, do it */
|
||||
if (want_start) {
|
||||
@@ -464,18 +452,18 @@ LPS25H::ioctl(struct file *filp, int cmd, unsigned long arg)
|
||||
/* adjust to a legal polling interval in Hz */
|
||||
default: {
|
||||
/* 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 */
|
||||
unsigned ticks = USEC2TICK(1000000 / arg);
|
||||
unsigned interval = (1000000 / arg);
|
||||
|
||||
/* check against maximum rate */
|
||||
if (ticks < USEC2TICK(LPS25H_CONVERSION_INTERVAL)) {
|
||||
if (interval < (LPS25H_CONVERSION_INTERVAL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* update interval for next measurement */
|
||||
_measure_ticks = ticks;
|
||||
_measure_interval = interval;
|
||||
|
||||
/* if we need to start the poll state machine, do it */
|
||||
if (want_start) {
|
||||
@@ -507,13 +495,13 @@ LPS25H::start()
|
||||
_reports->flush();
|
||||
|
||||
/* schedule a cycle to start things */
|
||||
work_queue(HPWORK, &_work, (worker_t)&LPS25H::cycle_trampoline, this, 1);
|
||||
ScheduleNow();
|
||||
}
|
||||
|
||||
void
|
||||
LPS25H::stop()
|
||||
{
|
||||
work_cancel(HPWORK, &_work);
|
||||
ScheduleClear();
|
||||
}
|
||||
|
||||
int
|
||||
@@ -540,15 +528,7 @@ LPS25H::reset()
|
||||
}
|
||||
|
||||
void
|
||||
LPS25H::cycle_trampoline(void *arg)
|
||||
{
|
||||
LPS25H *dev = reinterpret_cast<LPS25H *>(arg);
|
||||
|
||||
dev->cycle();
|
||||
}
|
||||
|
||||
void
|
||||
LPS25H::cycle()
|
||||
LPS25H::Run()
|
||||
{
|
||||
/* collection phase? */
|
||||
if (_collect_phase) {
|
||||
@@ -567,14 +547,10 @@ LPS25H::cycle()
|
||||
/*
|
||||
* Is there a collect->measure gap?
|
||||
*/
|
||||
if (_measure_ticks > USEC2TICK(LPS25H_CONVERSION_INTERVAL)) {
|
||||
if (_measure_interval > (LPS25H_CONVERSION_INTERVAL)) {
|
||||
|
||||
/* schedule a fresh cycle call when we are ready to measure again */
|
||||
work_queue(HPWORK,
|
||||
&_work,
|
||||
(worker_t)&LPS25H::cycle_trampoline,
|
||||
this,
|
||||
_measure_ticks - USEC2TICK(LPS25H_CONVERSION_INTERVAL));
|
||||
ScheduleDelayed(_measure_interval - LPS25H_CONVERSION_INTERVAL);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -589,11 +565,7 @@ LPS25H::cycle()
|
||||
_collect_phase = true;
|
||||
|
||||
/* schedule a fresh cycle call when the measurement is done */
|
||||
work_queue(HPWORK,
|
||||
&_work,
|
||||
(worker_t)&LPS25H::cycle_trampoline,
|
||||
this,
|
||||
USEC2TICK(LPS25H_CONVERSION_INTERVAL));
|
||||
ScheduleDelayed(LPS25H_CONVERSION_INTERVAL);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -713,7 +685,7 @@ LPS25H::print_info()
|
||||
{
|
||||
perf_print_counter(_sample_perf);
|
||||
perf_print_counter(_comms_errors);
|
||||
printf("poll interval: %u ticks\n", _measure_ticks);
|
||||
printf("poll interval: %u \n", _measure_interval);
|
||||
print_message(_last_report);
|
||||
|
||||
_reports->print_info("report queue");
|
||||
|
||||
Reference in New Issue
Block a user