Skip to content

refactor(radio): move per10ms() to a software timer #5966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 1 addition & 39 deletions radio/src/edgetx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void checkValidMCU(void)
static bool evalFSok = false;
#endif

void timer_10ms()
void per10ms()
{
DEBUG_TIMER_START(debugTimerPer10ms);
DEBUG_TIMER_SAMPLE(debugTimerPer10msPeriod);
Expand Down Expand Up @@ -245,44 +245,6 @@ void timer_10ms()
DEBUG_TIMER_STOP(debugTimerPer10ms);
}

#if !defined(SIMU)
// Handle 10ms timer asynchronously
#include <FreeRTOS/include/FreeRTOS.h>
#include <FreeRTOS/include/timers.h>

static volatile bool _timer_10ms_cb_in_queue = false;

static void _timer_10ms_cb(void *pvParameter1, uint32_t ulParameter2)
{
(void)pvParameter1;
(void)ulParameter2;
_timer_10ms_cb_in_queue = false;
timer_10ms();
}

void per10ms()
{

if (!_timer_10ms_cb_in_queue && xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
BaseType_t xReturn = pdFALSE;

xReturn = xTimerPendFunctionCallFromISR(_timer_10ms_cb, nullptr, 0, &xHigherPriorityTaskWoken);

if (xReturn == pdPASS) {
_timer_10ms_cb_in_queue = true;
} else {
TRACE("xTimerPendFunctionCallFromISR() queue full");
}
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
}

#else // !defined(SIMU)
void per10ms() { timer_10ms(); }
#endif


FlightModeData *flightModeAddress(uint8_t idx)
{
return &g_model.flightModeData[idx];
Expand Down
2 changes: 0 additions & 2 deletions radio/src/targets/common/arm/stm32/timers_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ static inline void _interrupt_1ms()
watchdogTimeout -= 1;
WDG_RESET(); // Retrigger hardware watchdog
}

per10ms();
}
}

Expand Down
34 changes: 34 additions & 0 deletions radio/src/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ TASK_FUNCTION(menusTask)
TASK_RETURN();
}

#if !defined(SIMU)
// Handle 10ms timer asynchronously
#include <FreeRTOS/include/FreeRTOS.h>
#include <FreeRTOS/include/timers.h>

static TimerHandle_t _timer10ms = nullptr;
static StaticTimer_t _timer10msBuffer;

static void _timer_10ms_cb(TimerHandle_t xTimer)
{
(void)xTimer;
per10ms();
}

void timer10msStart()
{
if (!_timer10ms) {
_timer10ms =
xTimerCreateStatic("10ms", 10 / RTOS_MS_PER_TICK, pdTRUE, (void*)0,
_timer_10ms_cb, &_timer10msBuffer);
}

if (_timer10ms) {
if( xTimerStart( _timer10ms, 0 ) != pdPASS ) {
/* The timer could not be set into the Active state. */
}
}
}
#endif

void tasksStart()
{
RTOS_CREATE_MUTEX(audioMutex);
Expand All @@ -111,6 +141,10 @@ void tasksStart()
cliStart();
#endif

#if !defined(SIMU)
timer10msStart();
#endif

RTOS_CREATE_TASK(menusTaskId, menusTask, "menus", menusStack,
MENUS_STACK_SIZE, MENUS_TASK_PRIO);

Expand Down