feat: async 10ms timer handler (#5424)

This commit is contained in:
Raphael Coeffic
2024-08-13 22:24:06 +10:00
committed by GitHub
parent b6d0bac2a0
commit 2df817fbf0
2 changed files with 31 additions and 2 deletions
+27 -1
View File
@@ -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 <FreeRTOS/include/FreeRTOS.h>
#include <FreeRTOS/include/timers.h>
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];
@@ -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()