diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 8b5183a93..47dbc296e 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -157,7 +157,7 @@ void checkValidMCU(void) #endif } -void per10ms() +void timer_10ms() { DEBUG_TIMER_START(debugTimerPer10ms); DEBUG_TIMER_SAMPLE(debugTimerPer10msPeriod); @@ -226,6 +226,32 @@ void per10ms() DEBUG_TIMER_STOP(debugTimerPer10ms); } +#if !defined(SIMU) +// Handle 10ms timer asynchronously +#include +#include + +static void _timer_10ms_cb(void *pvParameter1, uint32_t ulParameter2) +{ + (void)pvParameter1; + (void)ulParameter2; + timer_10ms(); +} + +void per10ms() +{ + if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + xTimerPendFunctionCallFromISR(_timer_10ms_cb, nullptr, 0, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } +} + +#else // !defined(SIMU) +void per10ms() { timer_10ms(); } +#endif + + FlightModeData *flightModeAddress(uint8_t idx) { return &g_model.flightModeData[idx]; diff --git a/radio/src/targets/common/arm/stm32/timers_driver.cpp b/radio/src/targets/common/arm/stm32/timers_driver.cpp index eddaa8f19..bcb981701 100644 --- a/radio/src/targets/common/arm/stm32/timers_driver.cpp +++ b/radio/src/targets/common/arm/stm32/timers_driver.cpp @@ -26,6 +26,8 @@ #include "hal.h" #include "hal/watchdog_driver.h" +#include "FreeRTOSConfig.h" + static volatile uint32_t _ms_ticks; static void _init_1ms_timer() @@ -41,8 +43,9 @@ static void _init_1ms_timer() MS_TIMER->EGR = 0; MS_TIMER->CR1 = TIM_CR1_CEN | TIM_CR1_URS; MS_TIMER->DIER = TIM_DIER_UIE; + NVIC_EnableIRQ(MS_TIMER_IRQn); - NVIC_SetPriority(MS_TIMER_IRQn, 4); + NVIC_SetPriority(MS_TIMER_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY); } void timersInit()