mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 04:45:24 +03:00
Updates to the way that timers are forced to overflow in oneshot mode.
Now the current count value is saved, and then passed to the listeners. This _should_ mean that CC3D PPM might work this time.
This commit is contained in:
parent
5096873ab1
commit
e9aaff808e
3 changed files with 28 additions and 3 deletions
|
@ -154,8 +154,7 @@ void pwmFinishedWritingMotors(uint8_t numberMotors)
|
||||||
if(motors[index]->tim != lastTimerPtr){
|
if(motors[index]->tim != lastTimerPtr){
|
||||||
lastTimerPtr = motors[index]->tim;
|
lastTimerPtr = motors[index]->tim;
|
||||||
|
|
||||||
// Force an overflow by setting the UG bit
|
timerForceOverflow(motors[index]->tim);
|
||||||
motors[index]->tim->EGR |= 0x0001;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -216,6 +216,7 @@ typedef struct timerConfig_s {
|
||||||
timerCCHandlerRec_t *edgeCallback[CC_CHANNELS_PER_TIMER];
|
timerCCHandlerRec_t *edgeCallback[CC_CHANNELS_PER_TIMER];
|
||||||
timerOvrHandlerRec_t *overflowCallback[CC_CHANNELS_PER_TIMER];
|
timerOvrHandlerRec_t *overflowCallback[CC_CHANNELS_PER_TIMER];
|
||||||
timerOvrHandlerRec_t *overflowCallbackActive; // null-terminated linkded list of active overflow callbacks
|
timerOvrHandlerRec_t *overflowCallbackActive; // null-terminated linkded list of active overflow callbacks
|
||||||
|
uint32_t forcedOverflowTimerValue;
|
||||||
} timerConfig_t;
|
} timerConfig_t;
|
||||||
timerConfig_t timerConfig[USED_TIMER_COUNT];
|
timerConfig_t timerConfig[USED_TIMER_COUNT];
|
||||||
|
|
||||||
|
@ -612,7 +613,14 @@ static void timCCxHandler(TIM_TypeDef *tim, timerConfig_t *timerConfig)
|
||||||
tim_status &= mask;
|
tim_status &= mask;
|
||||||
switch(bit) {
|
switch(bit) {
|
||||||
case __builtin_clz(TIM_IT_Update):
|
case __builtin_clz(TIM_IT_Update):
|
||||||
capture = tim->ARR;
|
|
||||||
|
if(timerConfig->forcedOverflowTimerValue != 0){
|
||||||
|
capture = timerConfig->forcedOverflowTimerValue - 1;
|
||||||
|
timerConfig->forcedOverflowTimerValue = 0;
|
||||||
|
} else {
|
||||||
|
capture = tim->ARR;
|
||||||
|
}
|
||||||
|
|
||||||
timerOvrHandlerRec_t *cb = timerConfig->overflowCallbackActive;
|
timerOvrHandlerRec_t *cb = timerConfig->overflowCallbackActive;
|
||||||
while(cb) {
|
while(cb) {
|
||||||
cb->fn(cb, capture);
|
cb->fn(cb, capture);
|
||||||
|
@ -789,3 +797,19 @@ void timerStart(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force an overflow for a given timer.
|
||||||
|
* Saves the current value of the counter in the relevant timerConfig's forcedOverflowTimerValue variable.
|
||||||
|
* @param TIM_Typedef *tim The timer to overflow
|
||||||
|
* @return void
|
||||||
|
**/
|
||||||
|
void timerForceOverflow(volatile TIM_TypeDef *tim)
|
||||||
|
{
|
||||||
|
// Save the current count so that PPM reading will work on the same timer that was forced to overflow
|
||||||
|
uint8_t timerIndex = lookupTimerIndex((const TIM_TypeDef *)tim);
|
||||||
|
timerConfig[timerIndex].forcedOverflowTimerValue = tim->CNT + 1;
|
||||||
|
|
||||||
|
// Force an overflow by setting the UG bit
|
||||||
|
tim->EGR |= 0x0001;
|
||||||
|
}
|
|
@ -117,5 +117,7 @@ void timerChInit(const timerHardware_t *timHw, channelType_t type, int irqPriori
|
||||||
|
|
||||||
void timerInit(void);
|
void timerInit(void);
|
||||||
void timerStart(void);
|
void timerStart(void);
|
||||||
|
void timerForceOverflow(volatile TIM_TypeDef *tim);
|
||||||
|
|
||||||
void configTimeBase(TIM_TypeDef *tim, uint16_t period, uint8_t mhz); // TODO - just for migration
|
void configTimeBase(TIM_TypeDef *tim, uint16_t period, uint8_t mhz); // TODO - just for migration
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue