mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-21 07:13:34 +08:00
cm8jl65 move to px4 work queue
This commit is contained in:
@@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
#include <px4_config.h>
|
#include <px4_config.h>
|
||||||
#include <px4_getopt.h>
|
#include <px4_getopt.h>
|
||||||
#include <px4_workqueue.h>
|
#include <px4_work_queue/ScheduledWorkItem.hpp>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -69,10 +69,6 @@
|
|||||||
|
|
||||||
/* Configuration Constants */
|
/* Configuration Constants */
|
||||||
|
|
||||||
#ifndef CONFIG_SCHED_WORKQUEUE
|
|
||||||
# error This requires CONFIG_SCHED_WORKQUEUE.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CM8JL65_TAKE_RANGE_REG 'd'
|
#define CM8JL65_TAKE_RANGE_REG 'd'
|
||||||
|
|
||||||
// designated serial port on Pixhawk (TELEM2)
|
// designated serial port on Pixhawk (TELEM2)
|
||||||
@@ -82,7 +78,7 @@
|
|||||||
#define CM8JL65_CONVERSION_INTERVAL 50*1000UL/* 50ms */
|
#define CM8JL65_CONVERSION_INTERVAL 50*1000UL/* 50ms */
|
||||||
|
|
||||||
|
|
||||||
class CM8JL65 : public cdev::CDev
|
class CM8JL65 : public cdev::CDev, public px4::ScheduledWorkItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -90,10 +86,10 @@ public:
|
|||||||
CM8JL65(const char *port = CM8JL65_DEFAULT_PORT, uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING);
|
CM8JL65(const char *port = CM8JL65_DEFAULT_PORT, uint8_t rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING);
|
||||||
|
|
||||||
// Virtual destructor
|
// Virtual destructor
|
||||||
virtual ~CM8JL65();
|
virtual ~CM8JL65() override;
|
||||||
|
|
||||||
virtual int init();
|
virtual int init() override;
|
||||||
virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg);
|
virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Diagnostics - print some basic information about the driver.
|
* Diagnostics - print some basic information about the driver.
|
||||||
@@ -107,7 +103,6 @@ private:
|
|||||||
float _min_distance;
|
float _min_distance;
|
||||||
float _max_distance;
|
float _max_distance;
|
||||||
int _conversion_interval;
|
int _conversion_interval;
|
||||||
work_s _work{};
|
|
||||||
ringbuffer::RingBuffer *_reports;
|
ringbuffer::RingBuffer *_reports;
|
||||||
int _fd;
|
int _fd;
|
||||||
uint8_t _linebuf[25];
|
uint8_t _linebuf[25];
|
||||||
@@ -151,15 +146,9 @@ private:
|
|||||||
* Perform a reading cycle; collect from the previous measurement
|
* Perform a reading cycle; collect from the previous measurement
|
||||||
* and start a new one.
|
* and start a new one.
|
||||||
*/
|
*/
|
||||||
void cycle();
|
void Run() override;
|
||||||
|
|
||||||
int collect();
|
int collect();
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -176,6 +165,7 @@ extern "C" __EXPORT int cm8jl65_main(int argc, char *argv[]);
|
|||||||
|
|
||||||
CM8JL65::CM8JL65(const char *port, uint8_t rotation) :
|
CM8JL65::CM8JL65(const char *port, uint8_t rotation) :
|
||||||
CDev(RANGE_FINDER0_DEVICE_PATH),
|
CDev(RANGE_FINDER0_DEVICE_PATH),
|
||||||
|
ScheduledWorkItem(px4::wq_configurations::hp_default),
|
||||||
_rotation(rotation),
|
_rotation(rotation),
|
||||||
_min_distance(0.10f),
|
_min_distance(0.10f),
|
||||||
_max_distance(9.0f),
|
_max_distance(9.0f),
|
||||||
@@ -195,9 +185,9 @@ CM8JL65::CM8JL65(const char *port, uint8_t rotation) :
|
|||||||
{
|
{
|
||||||
/* store port name */
|
/* store port name */
|
||||||
strncpy(_port, port, sizeof(_port) - 1);
|
strncpy(_port, port, sizeof(_port) - 1);
|
||||||
|
|
||||||
/* enforce null termination */
|
/* enforce null termination */
|
||||||
_port[sizeof(_port) - 1] = '\0';
|
_port[sizeof(_port) - 1] = '\0';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -310,10 +300,10 @@ CM8JL65::ioctl(device::file_t *filp, int cmd, unsigned long arg)
|
|||||||
default: {
|
default: {
|
||||||
|
|
||||||
/* convert hz to tick interval via microseconds */
|
/* convert hz to tick interval via microseconds */
|
||||||
int ticks = USEC2TICK(1000000 / arg);
|
int interval = (1000000 / arg);
|
||||||
|
|
||||||
/* check against maximum rate */
|
/* check against maximum rate */
|
||||||
if (ticks < USEC2TICK(_conversion_interval)) {
|
if (interval < _conversion_interval) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,26 +418,17 @@ CM8JL65::start()
|
|||||||
_reports->flush();
|
_reports->flush();
|
||||||
|
|
||||||
/* schedule a cycle to start things */
|
/* schedule a cycle to start things */
|
||||||
work_queue(HPWORK, &_work, (worker_t)&CM8JL65::cycle_trampoline, this, 1);
|
ScheduleNow();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CM8JL65::stop()
|
CM8JL65::stop()
|
||||||
{
|
{
|
||||||
work_cancel(HPWORK, &_work);
|
ScheduleClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CM8JL65::cycle_trampoline(void *arg)
|
CM8JL65::Run()
|
||||||
{
|
|
||||||
CM8JL65 *dev = static_cast<CM8JL65 *>(arg);
|
|
||||||
|
|
||||||
dev->cycle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
CM8JL65::cycle()
|
|
||||||
{
|
{
|
||||||
/* fds initialized? */
|
/* fds initialized? */
|
||||||
if (_fd < 0) {
|
if (_fd < 0) {
|
||||||
@@ -495,9 +476,8 @@ CM8JL65::cycle()
|
|||||||
_cycle_counter++;
|
_cycle_counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* schedule a fresh cycle call when a complete packet has been received */
|
/* schedule a fresh cycle call when a complete packet has been received */
|
||||||
work_queue(HPWORK, &_work, (worker_t)&CM8JL65::cycle_trampoline, this, USEC2TICK(_conversion_interval));
|
ScheduleDelayed(_conversion_interval);
|
||||||
_cycle_counter = 0;
|
_cycle_counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user