mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-04 15:08:39 -04:00
AP_HAL Scheduler: simplify register_timer_process, min time for delay cb
This commit is contained in:
parent
6a59ad143e
commit
bae7e4b88e
@ -14,9 +14,9 @@ public:
|
|||||||
virtual uint32_t millis() = 0;
|
virtual uint32_t millis() = 0;
|
||||||
virtual uint32_t micros() = 0;
|
virtual uint32_t micros() = 0;
|
||||||
virtual void delay_microseconds(uint16_t us) = 0;
|
virtual void delay_microseconds(uint16_t us) = 0;
|
||||||
virtual void register_delay_callback(AP_HAL::Proc) = 0;
|
virtual void register_delay_callback(AP_HAL::Proc,
|
||||||
virtual void register_timer_process(AP_HAL::TimedProc,
|
uint16_t min_time_ms) = 0;
|
||||||
uint32_t period_us, uint16_t phase) = 0;
|
virtual void register_timer_process(AP_HAL::TimedProc) = 0;
|
||||||
virtual bool defer_timer_process(AP_HAL::TimedProc) = 0;
|
virtual bool defer_timer_process(AP_HAL::TimedProc) = 0;
|
||||||
virtual void register_timer_failsafe(AP_HAL::TimedProc,
|
virtual void register_timer_failsafe(AP_HAL::TimedProc,
|
||||||
uint32_t period_us) = 0;
|
uint32_t period_us) = 0;
|
||||||
|
@ -14,7 +14,7 @@ APM1AnalogIn::APM1AnalogIn () :
|
|||||||
|
|
||||||
void APM1AnalogIn::init(void* machtnichts) {
|
void APM1AnalogIn::init(void* machtnichts) {
|
||||||
/* Register AVRAnalogIn::_timer_event with the scheduler. */
|
/* Register AVRAnalogIn::_timer_event with the scheduler. */
|
||||||
hal.scheduler->register_timer_process(_timer_event, 1000, 0);
|
hal.scheduler->register_timer_process(_timer_event);
|
||||||
/* Register each private channel with AVRAnalogIn. */
|
/* Register each private channel with AVRAnalogIn. */
|
||||||
_register_channel(&_bat_voltage);
|
_register_channel(&_bat_voltage);
|
||||||
_register_channel(&_bat_current);
|
_register_channel(&_bat_current);
|
||||||
|
@ -17,7 +17,7 @@ APM2AnalogIn::APM2AnalogIn () :
|
|||||||
|
|
||||||
void APM2AnalogIn::init(void * machtichts) {
|
void APM2AnalogIn::init(void * machtichts) {
|
||||||
/* Register AVRAnalogIn::_timer_event with the scheduler. */
|
/* Register AVRAnalogIn::_timer_event with the scheduler. */
|
||||||
hal.scheduler->register_timer_process(_timer_event, 1000, 0);
|
hal.scheduler->register_timer_process(_timer_event);
|
||||||
/* Register each private channel with AVRAnalogIn. */
|
/* Register each private channel with AVRAnalogIn. */
|
||||||
_register_channel(&_pitot);
|
_register_channel(&_pitot);
|
||||||
_register_channel(&_bat_voltage);
|
_register_channel(&_bat_voltage);
|
||||||
|
@ -178,12 +178,14 @@ void ArduinoScheduler::delay(uint32_t ms)
|
|||||||
if (((uint16_t)micros() - start) >= 1000) {
|
if (((uint16_t)micros() - start) >= 1000) {
|
||||||
ms--;
|
ms--;
|
||||||
start += 1000;
|
start += 1000;
|
||||||
|
if (_min_delay_cb_ms >= ms) {
|
||||||
if (_delay_cb) {
|
if (_delay_cb) {
|
||||||
_delay_cb();
|
_delay_cb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Delay for the given number of microseconds. Assumes a 16 MHz clock. */
|
/* Delay for the given number of microseconds. Assumes a 16 MHz clock. */
|
||||||
void ArduinoScheduler::delay_microseconds(uint16_t us)
|
void ArduinoScheduler::delay_microseconds(uint16_t us)
|
||||||
@ -209,14 +211,13 @@ void ArduinoScheduler::delay_microseconds(uint16_t us)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArduinoScheduler::register_delay_callback(AP_HAL::Proc proc) {
|
void ArduinoScheduler::register_delay_callback(AP_HAL::Proc proc,
|
||||||
|
uint16_t min_time_ms) {
|
||||||
_delay_cb = proc;
|
_delay_cb = proc;
|
||||||
|
_min_delay_cb_ms = min_time_ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArduinoScheduler::register_timer_process(
|
void ArduinoScheduler::register_timer_process(AP_HAL::TimedProc proc) {
|
||||||
AP_HAL::TimedProc proc, uint32_t period_us, uint16_t phase) {
|
|
||||||
/* XXX Assert period_us == 1000 */
|
|
||||||
/* XXX phase meaningless */
|
|
||||||
for (int i = 0; i < _num_timer_procs; i++) {
|
for (int i = 0; i < _num_timer_procs; i++) {
|
||||||
if (_timer_proc[i] == proc) {
|
if (_timer_proc[i] == proc) {
|
||||||
return;
|
return;
|
||||||
|
@ -19,9 +19,8 @@ public:
|
|||||||
uint32_t millis();
|
uint32_t millis();
|
||||||
uint32_t micros();
|
uint32_t micros();
|
||||||
void delay_microseconds(uint16_t us);
|
void delay_microseconds(uint16_t us);
|
||||||
void register_delay_callback(AP_HAL::Proc);
|
void register_delay_callback(AP_HAL::Proc, uint16_t min_time_ms);
|
||||||
void register_timer_process(AP_HAL::TimedProc,
|
void register_timer_process(AP_HAL::TimedProc);
|
||||||
uint32_t period_us, uint16_t phase);
|
|
||||||
bool defer_timer_process(AP_HAL::TimedProc);
|
bool defer_timer_process(AP_HAL::TimedProc);
|
||||||
void register_timer_failsafe(AP_HAL::TimedProc, uint32_t period_us);
|
void register_timer_failsafe(AP_HAL::TimedProc, uint32_t period_us);
|
||||||
void suspend_timer_procs();
|
void suspend_timer_procs();
|
||||||
@ -39,6 +38,7 @@ private:
|
|||||||
static uint32_t _micros();
|
static uint32_t _micros();
|
||||||
|
|
||||||
AP_HAL::Proc _delay_cb;
|
AP_HAL::Proc _delay_cb;
|
||||||
|
uint16_t _min_delay_cb_ms;
|
||||||
static AP_HAL::TimedProc _failsafe;
|
static AP_HAL::TimedProc _failsafe;
|
||||||
|
|
||||||
static volatile bool _timer_suspended;
|
static volatile bool _timer_suspended;
|
||||||
|
@ -71,7 +71,7 @@ void setup (void) {
|
|||||||
"Pin %d should toggle at 1khz:\r\n"),
|
"Pin %d should toggle at 1khz:\r\n"),
|
||||||
(int) DELAY_TOGGLE_PIN);
|
(int) DELAY_TOGGLE_PIN);
|
||||||
|
|
||||||
hal.scheduler->register_delay_callback(delay_toggle);
|
hal.scheduler->register_delay_callback(delay_toggle,0);
|
||||||
|
|
||||||
hal.scheduler->delay(100);
|
hal.scheduler->delay(100);
|
||||||
|
|
||||||
@ -89,8 +89,8 @@ void setup (void) {
|
|||||||
hal.console->printf_P(PSTR("Pin %d should toggle at 1khz.\r\n"),
|
hal.console->printf_P(PSTR("Pin %d should toggle at 1khz.\r\n"),
|
||||||
(int) SCHEDULED_TOGGLE_PIN_2);
|
(int) SCHEDULED_TOGGLE_PIN_2);
|
||||||
|
|
||||||
hal.scheduler->register_timer_process(schedule_toggle_1, 1000, 0);
|
hal.scheduler->register_timer_process(schedule_toggle_1);
|
||||||
hal.scheduler->register_timer_process(schedule_toggle_2, 1000, 0);
|
hal.scheduler->register_timer_process(schedule_toggle_2);
|
||||||
|
|
||||||
hal.scheduler->delay(100);
|
hal.scheduler->delay(100);
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ void setup (void) {
|
|||||||
"dominates the processor."));
|
"dominates the processor."));
|
||||||
hal.console->printf_P(PSTR("Pin %d should toggle then go high forever.\r\n"),
|
hal.console->printf_P(PSTR("Pin %d should toggle then go high forever.\r\n"),
|
||||||
(int) SCHEDULED_TOGGLE_PIN_2);
|
(int) SCHEDULED_TOGGLE_PIN_2);
|
||||||
hal.scheduler->register_timer_process(schedule_toggle_hang, 1000, 0);
|
hal.scheduler->register_timer_process(schedule_toggle_hang);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop (void) { }
|
void loop (void) { }
|
||||||
|
Loading…
Reference in New Issue
Block a user