Skip to content

Commit

Permalink
AP_HAL_ChibiOS: correct locking on LED thread
Browse files Browse the repository at this point in the history
  • Loading branch information
andyp1per authored and peterbarker committed May 17, 2023
1 parent 3d05d8c commit d7bcfd7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions libraries/AP_HAL_ChibiOS/RCOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void RCOutput::dshot_collect_dma_locks(uint64_t time_out_us, bool led_thread)
for (int8_t i = NUM_GROUPS - 1; i >= 0; i--) {
pwm_group &group = pwm_group_list[i];

if ((led_thread && !is_led_protocol(group.current_mode)) || is_led_protocol(group.current_mode)) {
if (led_thread != is_led_protocol(group.current_mode)) {
continue;
}

Expand Down Expand Up @@ -1313,7 +1313,7 @@ void RCOutput::led_timer_tick(uint64_t time_out_us)
}

// if we have enough time left send out LED data
if (serial_led_pending && (time_out_us > (AP_HAL::micros64() + (LED_OUTPUT_PERIOD_US >> 1)))) {
if (serial_led_pending) {
serial_led_pending = false;
for (auto &group : pwm_group_list) {
serial_led_pending |= !serial_led_send(group);
Expand Down Expand Up @@ -1608,11 +1608,14 @@ bool RCOutput::serial_led_send(pwm_group &group)
}

#ifndef DISABLE_DSHOT
if (irq.waiter || !group.dma_handle->lock_nonblock()) {
// doing serial output, don't send Serial LED pulses
if (irq.waiter || (group.dshot_state != DshotState::IDLE && group.dshot_state != DshotState::RECV_COMPLETE)) {
// doing serial output or DMAR input, don't send DShot pulses
return false;
}

// first make sure we have the DMA channel before anything else
group.dma_handle->lock();

{
WITH_SEMAPHORE(group.serial_led_mutex);

Expand Down

0 comments on commit d7bcfd7

Please sign in to comment.