mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 00:35:39 +03:00
Update timer handling to support multiple events at the same time.
This can occur when servicing two software serial ports via a multiple timer channels on the same channel.
This commit is contained in:
parent
e2deeeebd3
commit
aef3c6ad97
1 changed files with 28 additions and 24 deletions
|
@ -181,36 +181,40 @@ static void timCCxHandler(TIM_TypeDef *tim)
|
||||||
uint16_t capture;
|
uint16_t capture;
|
||||||
timerConfig_t *timerConfig;
|
timerConfig_t *timerConfig;
|
||||||
|
|
||||||
if (TIM_GetITStatus(tim, TIM_IT_CC1) == SET) {
|
uint8_t channelIndex = 0;
|
||||||
TIM_ClearITPendingBit(tim, TIM_IT_CC1);
|
for (channelIndex = 0; channelIndex < CC_CHANNELS_PER_TIMER; channelIndex++) {
|
||||||
|
uint8_t channel = channels[channelIndex];
|
||||||
|
|
||||||
timerConfig = findTimerConfig(tim, TIM_Channel_1);
|
if (channel == TIM_Channel_1 && TIM_GetITStatus(tim, TIM_IT_CC1) == SET) {
|
||||||
capture = TIM_GetCapture1(tim);
|
TIM_ClearITPendingBit(tim, TIM_IT_CC1);
|
||||||
} else if (TIM_GetITStatus(tim, TIM_IT_CC2) == SET) {
|
|
||||||
TIM_ClearITPendingBit(tim, TIM_IT_CC2);
|
|
||||||
|
|
||||||
timerConfig = findTimerConfig(tim, TIM_Channel_2);
|
timerConfig = findTimerConfig(tim, TIM_Channel_1);
|
||||||
capture = TIM_GetCapture2(tim);
|
capture = TIM_GetCapture1(tim);
|
||||||
} else if (TIM_GetITStatus(tim, TIM_IT_CC3) == SET) {
|
} else if (channel == TIM_Channel_2 && TIM_GetITStatus(tim, TIM_IT_CC2) == SET) {
|
||||||
TIM_ClearITPendingBit(tim, TIM_IT_CC3);
|
TIM_ClearITPendingBit(tim, TIM_IT_CC2);
|
||||||
|
|
||||||
timerConfig = findTimerConfig(tim, TIM_Channel_3);
|
timerConfig = findTimerConfig(tim, TIM_Channel_2);
|
||||||
capture = TIM_GetCapture3(tim);
|
capture = TIM_GetCapture2(tim);
|
||||||
} else if (TIM_GetITStatus(tim, TIM_IT_CC4) == SET) {
|
} else if (channel == TIM_Channel_3 && TIM_GetITStatus(tim, TIM_IT_CC3) == SET) {
|
||||||
TIM_ClearITPendingBit(tim, TIM_IT_CC4);
|
TIM_ClearITPendingBit(tim, TIM_IT_CC3);
|
||||||
|
|
||||||
timerConfig = findTimerConfig(tim, TIM_Channel_4);
|
timerConfig = findTimerConfig(tim, TIM_Channel_3);
|
||||||
capture = TIM_GetCapture4(tim);
|
capture = TIM_GetCapture3(tim);
|
||||||
} else {
|
} else if (channel == TIM_Channel_4 && TIM_GetITStatus(tim, TIM_IT_CC4) == SET) {
|
||||||
return; // avoid uninitialised variable dereference
|
TIM_ClearITPendingBit(tim, TIM_IT_CC4);
|
||||||
|
|
||||||
|
timerConfig = findTimerConfig(tim, TIM_Channel_4);
|
||||||
|
capture = TIM_GetCapture4(tim);
|
||||||
|
} else {
|
||||||
|
continue; // avoid uninitialised variable dereference
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!timerConfig->callback) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
timerConfig->callback(timerConfig->reference, capture);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!timerConfig->callback) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
timerConfig->callback(timerConfig->reference, capture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TIM1_CC_IRQHandler(void)
|
void TIM1_CC_IRQHandler(void)
|
||||||
{
|
{
|
||||||
timCCxHandler(TIM1);
|
timCCxHandler(TIM1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue