feat(radio): OS compatibility layer (#5840)

This commit is contained in:
Raphael Coeffic
2025-05-03 19:07:49 +10:00
committed by GitHub
parent c996612b0a
commit ab2a19e153
92 changed files with 1740 additions and 896 deletions
+60 -25
View File
@@ -19,7 +19,12 @@
* GNU General Public License for more details.
*/
#include "debug.h"
#include "edgetx.h"
#include "os/sleep.h"
#include "os/task.h"
#include "os/time.h"
#include "os/timer.h"
#include "timers_driver.h"
#include "hal/abnormal_reboot.h"
#include "hal/watchdog_driver.h"
@@ -32,23 +37,23 @@
#include "startup_shutdown.h"
#endif
RTOS_TASK_HANDLE menusTaskId;
RTOS_DEFINE_STACK(menusTaskId, menusStack, MENUS_STACK_SIZE);
task_handle_t menusTaskId;
TASK_DEFINE_STACK(menusStack, MENUS_STACK_SIZE);
#if defined(AUDIO)
RTOS_TASK_HANDLE audioTaskId;
RTOS_DEFINE_STACK(audioTaskId, audioStack, AUDIO_STACK_SIZE);
task_handle_t audioTaskId;
TASK_DEFINE_STACK(audioStack, AUDIO_STACK_SIZE);
#endif
RTOS_MUTEX_HANDLE audioMutex;
mutex_handle_t audioMutex;
#define MENU_TASK_PERIOD_TICKS (50 / RTOS_MS_PER_TICK) // 50ms
#define MENU_TASK_PERIOD (50) // 50ms
#if defined(COLORLCD) && defined(CLI)
bool perMainEnabled = true;
#endif
TASK_FUNCTION(menusTask)
static void menusTask()
{
#if defined(LIBOPENUI)
LvglWrapper::instance();
@@ -63,15 +68,14 @@ TASK_FUNCTION(menusTask)
uint32_t pwr_check = pwrCheck();
if (pwr_check == e_power_off) {
break;
}
else if (pwr_check == e_power_press) {
RTOS_WAIT_TICKS(MENU_TASK_PERIOD_TICKS);
} else if (pwr_check == e_power_press) {
sleep_ms(MENU_TASK_PERIOD);
continue;
}
#else
while (pwrCheck() != e_power_off) {
#endif
uint32_t start = (uint32_t)RTOS_GET_TIME();
time_point_t next_tick = time_point_now();
DEBUG_TIMER_START(debugTimerPerMain);
#if defined(COLORLCD) && defined(CLI)
if (perMainEnabled) {
@@ -81,14 +85,8 @@ TASK_FUNCTION(menusTask)
perMain();
#endif
DEBUG_TIMER_STOP(debugTimerPerMain);
// TODO remove completely massstorage from sky9x firmware
uint32_t runtime = ((uint32_t)RTOS_GET_TIME() - start);
// deduct the thread run-time from the wait, if run-time was more than
// desired period, then skip the wait all together
if (runtime < MENU_TASK_PERIOD_TICKS) {
RTOS_WAIT_TICKS(MENU_TASK_PERIOD_TICKS - runtime);
}
sleep_until(&next_tick, MENU_TASK_PERIOD);
resetForcePowerOffRequest();
}
@@ -99,24 +97,61 @@ TASK_FUNCTION(menusTask)
drawSleepBitmap();
edgeTxClose();
boardOff();
}
TASK_RETURN();
static void audioTask()
{
while (!audioQueue.started()) {
sleep_ms(1);
}
#if defined(PCBX12S) || defined(RADIO_TX16S) || defined(RADIO_F16) || defined(RADIO_V16)
// The audio amp needs ~2s to start
sleep_ms(1000); // 1s
#endif
time_point_t next_tick = time_point_now();
while (true) {
DEBUG_TIMER_SAMPLE(debugTimerAudioIterval);
DEBUG_TIMER_START(debugTimerAudioDuration);
audioQueue.wakeup();
DEBUG_TIMER_STOP(debugTimerAudioDuration);
sleep_until(&next_tick, 4);
}
}
static timer_handle_t _timer10ms = TIMER_INITIALIZER;
static void _timer_10ms_cb(timer_handle_t* h)
{
per10ms();
}
void timer10msStart()
{
if (!timer_is_created(&_timer10ms)) {
timer_create(&_timer10ms, _timer_10ms_cb, "10ms", 10, true);
}
timer_start(&_timer10ms);
}
void tasksStart()
{
RTOS_CREATE_MUTEX(audioMutex);
mutex_create(&audioMutex);
#if defined(CLI) && !defined(SIMU)
cliStart();
#endif
RTOS_CREATE_TASK(menusTaskId, menusTask, "menus", menusStack,
MENUS_STACK_SIZE, MENUS_TASK_PRIO);
timer10msStart();
#if !defined(SIMU) && defined(AUDIO)
RTOS_CREATE_TASK(audioTaskId, audioTask, "audio", audioStack,
AUDIO_STACK_SIZE, AUDIO_TASK_PRIO);
task_create(&menusTaskId, menusTask, "menus", menusStack, MENUS_STACK_SIZE,
MENUS_TASK_PRIO);
#if defined(AUDIO)
task_create(&audioTaskId, audioTask, "audio", audioStack, AUDIO_STACK_SIZE,
AUDIO_TASK_PRIO);
#endif
RTOS_START();