diff --git a/src/main/cli/cli.c b/src/main/cli/cli.c index ebf0597794..56ca481fe4 100644 --- a/src/main/cli/cli.c +++ b/src/main/cli/cli.c @@ -5864,7 +5864,8 @@ static void showTimers(void) cliPrintf("TIM%d:", timerNumber); bool timerUsed = false; for (unsigned timerIndex = 0; timerIndex < CC_CHANNELS_PER_TIMER; timerIndex++) { - const resourceOwner_t *timerOwner = timerGetOwner(timerNumber, CC_CHANNEL_FROM_INDEX(timerIndex)); + const timerHardware_t *timer = timerGetAllocatedByNumberAndChannel(timerNumber, CC_CHANNEL_FROM_INDEX(timerIndex)); + const resourceOwner_t *timerOwner = timerGetOwner(timer); if (timerOwner->owner) { if (!timerUsed) { timerUsed = true; @@ -5873,9 +5874,9 @@ static void showTimers(void) } if (timerOwner->resourceIndex > 0) { - cliPrintLinef(" CH%d: %s %d", timerIndex + 1, ownerNames[timerOwner->owner], timerOwner->resourceIndex); + cliPrintLinef(" CH%d%s: %s %d", timerIndex + 1, timer->output & TIMER_OUTPUT_N_CHANNEL ? "N" : " ", ownerNames[timerOwner->owner], timerOwner->resourceIndex); } else { - cliPrintLinef(" CH%d: %s", timerIndex + 1, ownerNames[timerOwner->owner]); + cliPrintLinef(" CH%d%s: %s", timerIndex + 1, timer->output & TIMER_OUTPUT_N_CHANNEL ? "N" : " ", ownerNames[timerOwner->owner]); } } } diff --git a/src/main/drivers/dshot_bitbang.c b/src/main/drivers/dshot_bitbang.c index 24009a36d0..9775355e96 100644 --- a/src/main/drivers/dshot_bitbang.c +++ b/src/main/drivers/dshot_bitbang.c @@ -245,11 +245,11 @@ static bbPort_t *bbAllocMotorPort(int portIndex) return bbPort; } -const resourceOwner_t *dshotBitbangTimerGetOwner(int8_t timerNumber, uint16_t timerChannel) +const resourceOwner_t *dshotBitbangTimerGetOwner(const timerHardware_t *timer) { for (int index = 0; index < usedMotorPorts; index++) { - const timerHardware_t *timer = bbPorts[index].timhw; - if (timerGetTIMNumber(timer->tim) == timerNumber && timer->channel == timerChannel) { + const timerHardware_t *bitbangTimer = bbPorts[index].timhw; + if (bitbangTimer && bitbangTimer == timer) { return &bbPorts[index].owner; } } @@ -351,7 +351,8 @@ static void bbFindPacerTimer(void) } bool timerConflict = false; for (int channel = 0; channel < CC_CHANNELS_PER_TIMER; channel++) { - const resourceOwner_e timerOwner = timerGetOwner(timNumber, CC_CHANNEL_FROM_INDEX(channel))->owner; + const timerHardware_t *timer = timerGetAllocatedByNumberAndChannel(timNumber, CC_CHANNEL_FROM_INDEX(channel)); + const resourceOwner_e timerOwner = timerGetOwner(timer)->owner; if (timerOwner != OWNER_FREE && timerOwner != OWNER_DSHOT_BITBANG) { timerConflict = true; break; diff --git a/src/main/drivers/dshot_bitbang.h b/src/main/drivers/dshot_bitbang.h index 050f378cba..8bfffe5476 100644 --- a/src/main/drivers/dshot_bitbang.h +++ b/src/main/drivers/dshot_bitbang.h @@ -39,4 +39,4 @@ struct motorDevConfig_s; struct motorDevice_s; struct motorDevice_s *dshotBitbangDevInit(const struct motorDevConfig_s *motorConfig, uint8_t motorCount); dshotBitbangStatus_e dshotBitbangGetStatus(); -const resourceOwner_t *dshotBitbangTimerGetOwner(int8_t timerNumber, uint16_t timerChannel); +const resourceOwner_t *dshotBitbangTimerGetOwner(const timerHardware_t *timer); diff --git a/src/main/drivers/timer.h b/src/main/drivers/timer.h index 82f0008878..42e00eff43 100644 --- a/src/main/drivers/timer.h +++ b/src/main/drivers/timer.h @@ -278,7 +278,8 @@ extern const resourceOwner_t freeOwner; struct timerIOConfig_s; struct timerIOConfig_s *timerIoConfigByTag(ioTag_t ioTag); -const resourceOwner_t *timerGetOwner(int8_t timerNumber, uint16_t timerChannel); +const timerHardware_t *timerGetAllocatedByNumberAndChannel(int8_t timerNumber, uint16_t timerChannel); +const resourceOwner_t *timerGetOwner(const timerHardware_t *timer); #endif const timerHardware_t *timerGetByTag(ioTag_t ioTag); const timerHardware_t *timerAllocate(ioTag_t ioTag, resourceOwner_e owner, uint8_t resourceIndex); diff --git a/src/main/drivers/timer_common.c b/src/main/drivers/timer_common.c index c3ecaa4939..9139c83b69 100644 --- a/src/main/drivers/timer_common.c +++ b/src/main/drivers/timer_common.c @@ -81,12 +81,24 @@ const timerHardware_t *timerGetByTag(ioTag_t ioTag) return timerGetByTagAndIndex(ioTag, timerIndex); } -const resourceOwner_t *timerGetOwner(int8_t timerNumber, uint16_t timerChannel) +const timerHardware_t *timerGetAllocatedByNumberAndChannel(int8_t timerNumber, uint16_t timerChannel) +{ + for (unsigned i = 0; i < MAX_TIMER_PINMAP_COUNT; i++) { + const timerHardware_t *timer = timerGetByTagAndIndex(timerIOConfig(i)->ioTag, timerIOConfig(i)->index); + if (timer && timerGetTIMNumber(timer->tim) == timerNumber && timer->channel == timerChannel && timerOwners[i].owner) { + return timer; + } + } + + return NULL; +} + +const resourceOwner_t *timerGetOwner(const timerHardware_t *timer) { const resourceOwner_t *timerOwner = &freeOwner; for (unsigned i = 0; i < MAX_TIMER_PINMAP_COUNT; i++) { - const timerHardware_t *timer = timerGetByTagAndIndex(timerIOConfig(i)->ioTag, timerIOConfig(i)->index); - if (timer && timerGetTIMNumber(timer->tim) == timerNumber && timer->channel == timerChannel) { + const timerHardware_t *assignedTimer = timerGetByTagAndIndex(timerIOConfig(i)->ioTag, timerIOConfig(i)->index); + if (assignedTimer && assignedTimer == timer) { timerOwner = &timerOwners[i]; break; @@ -95,7 +107,7 @@ const resourceOwner_t *timerGetOwner(int8_t timerNumber, uint16_t timerChannel) #if defined(USE_DSHOT_BITBANG) if (!timerOwner->owner) { - timerOwner = dshotBitbangTimerGetOwner(timerNumber, timerChannel); + timerOwner = dshotBitbangTimerGetOwner(timer); } #endif @@ -112,7 +124,7 @@ const timerHardware_t *timerAllocate(ioTag_t ioTag, resourceOwner_e owner, uint8 if (timerIOConfig(i)->ioTag == ioTag) { const timerHardware_t *timer = timerGetByTagAndIndex(ioTag, timerIOConfig(i)->index); - if (timerGetOwner(timerGetTIMNumber(timer->tim), timer->channel)->owner) { + if (timerGetOwner(timer)->owner) { return NULL; }