AP_HAL_ChibiOS: fix dshot cancel race with waiter

This commit is contained in:
Andy Piper
2025-04-01 10:51:17 +11:00
committed by Andrew Tridgell
parent 3b4dc13825
commit beb4cd62b2
2 changed files with 13 additions and 3 deletions
+4 -3
View File
@@ -347,7 +347,7 @@ void RCOutput::dshot_collect_dma_locks(rcout_timer_t cycle_start_us, rcout_timer
if (!mask) {
dma_cancel(group);
}
group.dshot_waiter = nullptr;
osalDbgAssert(group.dshot_waiter == nullptr, "Dshot waiter was not reset");
#ifdef HAL_WITH_BIDIR_DSHOT
// if using input capture DMA then clean up
if (group.bdshot.enabled) {
@@ -1847,12 +1847,12 @@ __RAMFUNC__ void RCOutput::dma_unlock(virtual_timer_t* vt, void *p)
{
chSysLockFromISR();
pwm_group *group = (pwm_group *)p;
group->dshot_state = DshotState::IDLE;
if (group->dshot_waiter != nullptr) {
// tell the waiting process we've done the DMA. Note that
// dshot_waiter can be null if we have cancelled the send
// dshot_waiter can be null if we have just cancelled the send
chEvtSignalI(group->dshot_waiter, group->dshot_event_mask);
group->dshot_waiter = nullptr;
}
chSysUnlockFromISR();
}
@@ -1911,6 +1911,7 @@ void RCOutput::dma_cancel(pwm_group& group)
chEvtGetAndClearEventsI(group.dshot_event_mask | DSHOT_CASCADE);
group.dshot_state = DshotState::IDLE;
group.dshot_waiter = nullptr;
chSysUnlock();
}
@@ -496,6 +496,13 @@ __RAMFUNC__ void RCOutput::bdshot_finish_dshot_gcr_transaction(virtual_timer_t*
#ifdef HAL_GPIO_LINE_GPIO56
TOGGLE_PIN_DEBUG(56);
#endif
osalDbgAssert(group->dshot_waiter, "No dshot waiter to signal");
if (group->dshot_waiter == nullptr) { // transaction was cancelled, leave everything alone
chSysUnlockFromISR();
return;
}
uint8_t curr_telem_chan = group->bdshot.curr_telem_chan;
// the DMA buffer is either the regular outbound one because we are sharing UP and CH
@@ -542,6 +549,8 @@ __RAMFUNC__ void RCOutput::bdshot_finish_dshot_gcr_transaction(virtual_timer_t*
// tell the waiting process we've done the DMA
chEvtSignalI(group->dshot_waiter, group->dshot_event_mask);
group->dshot_waiter = nullptr;
#ifdef HAL_GPIO_LINE_GPIO56
TOGGLE_PIN_DEBUG(56);
#endif