Merge pull request #4632 from 0xc0170/fix_stm32_32bitticker

STM32: fix us ticker set event timestamp double ISR possibility
pull/4636/head
Jimmy Brisson 2017-06-29 11:08:42 -05:00 committed by GitHub
commit d52ed5394c
1 changed files with 4 additions and 2 deletions

View File

@ -44,14 +44,16 @@ uint32_t us_ticker_read()
void us_ticker_set_interrupt(timestamp_t timestamp)
{
TimMasterHandle.Instance = TIM_MST;
// disable IT while we are handling the correct timestamp
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
// Set new output compare value
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
// Enable IT
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
// Check if timestamp has already passed, and if so, set the event immediately
if ((int32_t)(timestamp - TIM_MST->CNT) <= 0) {
LL_TIM_GenerateEvent_CC1(TimMasterHandle.Instance);
}
// Enable IT
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
}
void us_ticker_disable_interrupt(void)