oreoled move to px4 work queue

This commit is contained in:
Daniel Agar
2019-05-24 12:58:55 -04:00
parent d8dd592d20
commit e7f539f29a
+13 -34
View File
@@ -57,7 +57,7 @@
#include <px4_getopt.h> #include <px4_getopt.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/wqueue.h> #include <px4_work_queue/ScheduledWorkItem.hpp>
#include <nuttx/clock.h> #include <nuttx/clock.h>
#include <perf/perf_counter.h> #include <perf/perf_counter.h>
@@ -80,7 +80,7 @@
#define OREOLED_CMD_QUEUE_SIZE 10 ///< up to 10 messages can be queued up to send to the LEDs #define OREOLED_CMD_QUEUE_SIZE 10 ///< up to 10 messages can be queued up to send to the LEDs
class OREOLED : public device::I2C class OREOLED : public device::I2C, public px4::ScheduledWorkItem
{ {
public: public:
OREOLED(int bus, int i2c_addr, bool autoupdate, bool alwaysupdate); OREOLED(int bus, int i2c_addr, bool autoupdate, bool alwaysupdate);
@@ -112,15 +112,10 @@ private:
*/ */
void stop(); void stop();
/**
* static function that is called by worker queue
*/
static void cycle_trampoline(void *arg);
/** /**
* update the colours displayed by the LEDs * update the colours displayed by the LEDs
*/ */
void cycle(); void Run() override;
int bootloader_app_reset(int led_num); int bootloader_app_reset(int led_num);
int bootloader_app_ping(int led_num); int bootloader_app_ping(int led_num);
@@ -136,7 +131,6 @@ private:
int bootloader_coerce_healthy(void); int bootloader_coerce_healthy(void);
/* internal variables */ /* internal variables */
work_s _work; ///< work queue for scheduling reads
bool _healthy[OREOLED_NUM_LEDS]; ///< health of each LED bool _healthy[OREOLED_NUM_LEDS]; ///< health of each LED
bool _in_boot[OREOLED_NUM_LEDS]; ///< true for each LED that is in bootloader mode bool _in_boot[OREOLED_NUM_LEDS]; ///< true for each LED that is in bootloader mode
uint8_t _num_healthy; ///< number of healthy LEDs uint8_t _num_healthy; ///< number of healthy LEDs
@@ -171,7 +165,7 @@ extern "C" __EXPORT int oreoled_main(int argc, char *argv[]);
/* constructor */ /* constructor */
OREOLED::OREOLED(int bus, int i2c_addr, bool autoupdate, bool alwaysupdate) : OREOLED::OREOLED(int bus, int i2c_addr, bool autoupdate, bool alwaysupdate) :
I2C("oreoled", OREOLED0_DEVICE_PATH, bus, i2c_addr, 100000), I2C("oreoled", OREOLED0_DEVICE_PATH, bus, i2c_addr, 100000),
_work{}, ScheduledWorkItem(px4::device_bus_to_wq(get_device_id())),
_num_healthy(0), _num_healthy(0),
_num_inboot(0), _num_inboot(0),
_cmd_queue(nullptr), _cmd_queue(nullptr),
@@ -279,28 +273,17 @@ void
OREOLED::start() OREOLED::start()
{ {
/* schedule a cycle to start things */ /* schedule a cycle to start things */
work_queue(HPWORK, &_work, (worker_t)&OREOLED::cycle_trampoline, this, 1); ScheduleNow();
} }
void void
OREOLED::stop() OREOLED::stop()
{ {
work_cancel(HPWORK, &_work); ScheduleClear();
} }
void void
OREOLED::cycle_trampoline(void *arg) OREOLED::Run()
{
OREOLED *dev = (OREOLED *)arg;
/* check global oreoled and cycle */
if (g_oreoled != nullptr) {
dev->cycle();
}
}
void
OREOLED::cycle()
{ {
/* check time since startup */ /* check time since startup */
uint64_t now = hrt_absolute_time(); uint64_t now = hrt_absolute_time();
@@ -369,8 +352,8 @@ OREOLED::cycle()
} }
/* schedule another attempt in 0.1 sec */ /* schedule another attempt in 0.1 sec */
work_queue(HPWORK, &_work, (worker_t)&OREOLED::cycle_trampoline, this, ScheduleDelayed(OREOLED_STARTUP_INTERVAL_US);
USEC2TICK(OREOLED_STARTUP_INTERVAL_US));
return; return;
} else if (_alwaysupdate) { } else if (_alwaysupdate) {
@@ -406,8 +389,7 @@ OREOLED::cycle()
_alwaysupdate = false; _alwaysupdate = false;
/* 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)&OREOLED::cycle_trampoline, this, ScheduleDelayed(OREOLED_UPDATE_INTERVAL_US);
USEC2TICK(OREOLED_UPDATE_INTERVAL_US));
return; return;
} else if (_autoupdate) { } else if (_autoupdate) {
@@ -461,8 +443,7 @@ OREOLED::cycle()
_autoupdate = false; _autoupdate = false;
/* 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)&OREOLED::cycle_trampoline, this, ScheduleDelayed(OREOLED_UPDATE_INTERVAL_US);
USEC2TICK(OREOLED_UPDATE_INTERVAL_US));
return; return;
} else if (_num_inboot > 0) { } else if (_num_inboot > 0) {
@@ -480,8 +461,7 @@ OREOLED::cycle()
_num_inboot = 0; _num_inboot = 0;
/* 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)&OREOLED::cycle_trampoline, this, ScheduleDelayed(OREOLED_UPDATE_INTERVAL_US);
USEC2TICK(OREOLED_UPDATE_INTERVAL_US));
return; return;
} else if (!_is_ready) { } else if (!_is_ready) {
@@ -539,8 +519,7 @@ OREOLED::cycle()
} }
/* schedule a fresh cycle call when the command is sent */ /* schedule a fresh cycle call when the command is sent */
work_queue(HPWORK, &_work, (worker_t)&OREOLED::cycle_trampoline, this, ScheduleDelayed(OREOLED_UPDATE_INTERVAL_US);
USEC2TICK(OREOLED_UPDATE_INTERVAL_US));
} }
int int