HAL_ChibiOS: cope with nesting of expected_delay_ms()

This commit is contained in:
Andrew Tridgell 2019-05-11 18:20:53 +10:00
parent 64c723fd31
commit a7eb85e1c5
2 changed files with 17 additions and 2 deletions

View File

@ -540,10 +540,24 @@ void Scheduler::expect_delay_ms(uint32_t ms)
return;
}
if (ms == 0) {
expect_delay_start = 0;
if (expect_delay_nesting > 0) {
expect_delay_nesting--;
}
if (expect_delay_nesting == 0) {
expect_delay_start = 0;
}
} else {
expect_delay_start = AP_HAL::millis();
uint32_t now = AP_HAL::millis();
if (expect_delay_start != 0) {
// we already have a delay running, possibly extend it
uint32_t done = now - expect_delay_start;
if (expect_delay_length > done) {
ms = MAX(ms, expect_delay_length - done);
}
}
expect_delay_start = now;
expect_delay_length = ms;
expect_delay_nesting++;
// also put our priority below timer thread if we are boosted
boost_end();

View File

@ -133,6 +133,7 @@ private:
bool _priority_boosted;
uint32_t expect_delay_start;
uint32_t expect_delay_length;
uint32_t expect_delay_nesting;
AP_HAL::MemberProc _timer_proc[CHIBIOS_SCHEDULER_MAX_TIMER_PROCS];
uint8_t _num_timer_procs;