Putting overflow code inside an atomic block, and style improvement (using predefined constant instead of raw number)

This commit is contained in:
Ben Hitchcock 2014-12-02 06:11:40 +08:00
parent e9aaff808e
commit 8a9e51c779
1 changed files with 7 additions and 5 deletions

View File

@ -806,10 +806,12 @@ void timerStart(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;
ATOMIC_BLOCK(NVIC_PRIO_TIMER) {
// 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;
// Force an overflow by setting the UG bit
tim->EGR |= TIM_EGR_UG;
}
}