mirror of
https://github.com/opentx/opentx.git
synced 2025-07-19 14:25:11 +03:00
RTOS refactoring + more AVR removal
This commit is contained in:
parent
f60733b561
commit
f3bfde242b
80 changed files with 1111 additions and 1054 deletions
|
@ -20,18 +20,17 @@
|
|||
|
||||
#include "opentx.h"
|
||||
|
||||
OS_TID menusTaskId;
|
||||
// menus stack must be aligned to 8 bytes otherwise printf for %f does not work!
|
||||
TaskStack<MENUS_STACK_SIZE> __ALIGNED(8) menusStack;
|
||||
RTOS_TASK_HANDLE menusTaskId;
|
||||
RTOS_DEFINE_STACK(menusStack, MENUS_STACK_SIZE);
|
||||
|
||||
OS_TID mixerTaskId;
|
||||
TaskStack<MIXER_STACK_SIZE> mixerStack;
|
||||
RTOS_TASK_HANDLE mixerTaskId;
|
||||
RTOS_DEFINE_STACK(mixerStack, MIXER_STACK_SIZE);
|
||||
|
||||
OS_TID audioTaskId;
|
||||
TaskStack<AUDIO_STACK_SIZE> audioStack;
|
||||
RTOS_TASK_HANDLE audioTaskId;
|
||||
RTOS_DEFINE_STACK(audioStack, AUDIO_STACK_SIZE);
|
||||
|
||||
OS_MutexID audioMutex;
|
||||
OS_MutexID mixerMutex;
|
||||
RTOS_MUTEX_HANDLE audioMutex;
|
||||
RTOS_MUTEX_HANDLE mixerMutex;
|
||||
|
||||
enum TaskIndex {
|
||||
MENU_TASK_INDEX,
|
||||
|
@ -43,27 +42,6 @@ enum TaskIndex {
|
|||
MAIN_TASK_INDEX = 255
|
||||
};
|
||||
|
||||
template<int SIZE>
|
||||
void TaskStack<SIZE>::paint()
|
||||
{
|
||||
for (uint32_t i=0; i<SIZE; i++) {
|
||||
stack[i] = 0x55555555;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t getStackAvailable(void * address, uint16_t size)
|
||||
{
|
||||
uint32_t * array = (uint32_t *)address;
|
||||
uint16_t i = 0;
|
||||
while (i < size && array[i] == 0x55555555) {
|
||||
i++;
|
||||
}
|
||||
return i*4;
|
||||
#if defined(CLI)
|
||||
cliStackPaint();
|
||||
#endif
|
||||
}
|
||||
|
||||
void stackPaint()
|
||||
{
|
||||
menusStack.paint();
|
||||
|
@ -74,18 +52,6 @@ void stackPaint()
|
|||
#endif
|
||||
}
|
||||
|
||||
#if defined(STM32) && !defined(SIMU)
|
||||
uint16_t stackSize()
|
||||
{
|
||||
return ((unsigned char *)&_estack - (unsigned char *)&_main_stack_start) / 4;
|
||||
}
|
||||
|
||||
uint16_t stackAvailable()
|
||||
{
|
||||
return getStackAvailable(&_main_stack_start, stackSize());
|
||||
}
|
||||
#endif
|
||||
|
||||
volatile uint16_t timeForcePowerOffPressed = 0;
|
||||
|
||||
bool isForcePowerOffRequested()
|
||||
|
@ -109,7 +75,7 @@ bool isForcePowerOffRequested()
|
|||
|
||||
uint32_t nextMixerTime[NUM_MODULES];
|
||||
|
||||
void mixerTask(void * pdata)
|
||||
TASK_FUNCTION(mixerTask)
|
||||
{
|
||||
static uint32_t lastRunTime;
|
||||
s_pulses_paused = true;
|
||||
|
@ -118,20 +84,20 @@ void mixerTask(void * pdata)
|
|||
|
||||
#if defined(SIMU)
|
||||
if (main_thread_running == 0)
|
||||
return;
|
||||
TASK_RETURN();
|
||||
#endif
|
||||
|
||||
#if defined(SBUS)
|
||||
processSbusInput();
|
||||
#endif
|
||||
|
||||
CoTickDelay(1);
|
||||
RTOS_WAIT_TICKS(1);
|
||||
|
||||
if (isForcePowerOffRequested()) {
|
||||
pwrOff();
|
||||
}
|
||||
|
||||
uint32_t now = CoGetOSTime();
|
||||
uint32_t now = RTOS_GET_TIME();
|
||||
bool run = false;
|
||||
#if !defined(SIMU) && defined(STM32)
|
||||
if ((now - lastRunTime) >= (usbStarted() ? 5 : 10)) { // run at least every 20ms (every 10ms if USB is active)
|
||||
|
@ -158,11 +124,11 @@ void mixerTask(void * pdata)
|
|||
uint16_t t0 = getTmr2MHz();
|
||||
|
||||
DEBUG_TIMER_START(debugTimerMixer);
|
||||
CoEnterMutexSection(mixerMutex);
|
||||
RTOS_LOCK_MUTEX(mixerMutex);
|
||||
doMixerCalculations();
|
||||
DEBUG_TIMER_START(debugTimerMixerCalcToUsage);
|
||||
DEBUG_TIMER_SAMPLE(debugTimerMixerIterval);
|
||||
CoLeaveMutexSection(mixerMutex);
|
||||
RTOS_UNLOCK_MUTEX(mixerMutex);
|
||||
DEBUG_TIMER_STOP(debugTimerMixer);
|
||||
|
||||
#if defined(STM32) && !defined(SIMU)
|
||||
|
@ -196,7 +162,7 @@ void scheduleNextMixerCalculation(uint8_t module, uint16_t period_ms)
|
|||
{
|
||||
// Schedule next mixer calculation time,
|
||||
// for now assume mixer calculation takes 2 ms.
|
||||
nextMixerTime[module] = (uint32_t)CoGetOSTime() + period_ms / 2 - 1/*2ms*/;
|
||||
nextMixerTime[module] = (uint32_t)RTOS_GET_TIME() + period_ms / 2 - 1/*2ms*/;
|
||||
DEBUG_TIMER_STOP(debugTimerMixerCalcToUsage);
|
||||
}
|
||||
|
||||
|
@ -206,7 +172,7 @@ void scheduleNextMixerCalculation(uint8_t module, uint16_t period_ms)
|
|||
bool perMainEnabled = true;
|
||||
#endif
|
||||
|
||||
void menusTask(void * pdata)
|
||||
TASK_FUNCTION(menusTask)
|
||||
{
|
||||
opentxInit();
|
||||
|
||||
|
@ -217,13 +183,13 @@ void menusTask(void * pdata)
|
|||
break;
|
||||
}
|
||||
else if (pwr_check == e_power_press) {
|
||||
CoTickDelay(MENU_TASK_PERIOD_TICKS);
|
||||
RTOS_WAIT_TICKS(MENU_TASK_PERIOD_TICKS);
|
||||
continue;
|
||||
}
|
||||
#else
|
||||
while (pwrCheck() != e_power_off) {
|
||||
#endif
|
||||
uint32_t start = (uint32_t)CoGetOSTime();
|
||||
uint32_t start = (uint32_t)RTOS_GET_TIME();
|
||||
DEBUG_TIMER_START(debugTimerPerMain);
|
||||
#if defined(COLORLCD) && defined(CLI)
|
||||
if (perMainEnabled) {
|
||||
|
@ -234,11 +200,11 @@ void menusTask(void * pdata)
|
|||
#endif
|
||||
DEBUG_TIMER_STOP(debugTimerPerMain);
|
||||
// TODO remove completely massstorage from sky9x firmware
|
||||
uint32_t runtime = ((uint32_t)CoGetOSTime() - start);
|
||||
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) {
|
||||
CoTickDelay(MENU_TASK_PERIOD_TICKS - runtime);
|
||||
RTOS_WAIT_TICKS(MENU_TASK_PERIOD_TICKS - runtime);
|
||||
}
|
||||
|
||||
resetForcePowerOffRequest();
|
||||
|
@ -260,26 +226,27 @@ void menusTask(void * pdata)
|
|||
drawSleepBitmap();
|
||||
opentxClose();
|
||||
boardOff(); // Only turn power off if necessary
|
||||
|
||||
TASK_RETURN();
|
||||
}
|
||||
|
||||
void tasksStart()
|
||||
{
|
||||
CoInitOS();
|
||||
RTOS_INIT();
|
||||
|
||||
#if defined(CLI)
|
||||
cliStart();
|
||||
#endif
|
||||
|
||||
mixerTaskId = CoCreateTask(mixerTask, NULL, 5, &mixerStack.stack[MIXER_STACK_SIZE-1], MIXER_STACK_SIZE);
|
||||
menusTaskId = CoCreateTask(menusTask, NULL, 10, &menusStack.stack[MENUS_STACK_SIZE-1], MENUS_STACK_SIZE);
|
||||
RTOS_CREATE_TASK(mixerTaskId, mixerTask, "Mixer", mixerStack, MIXER_STACK_SIZE, MIXER_TASK_PRIO);
|
||||
RTOS_CREATE_TASK(menusTaskId, menusTask, "Menus", menusStack, MENUS_STACK_SIZE, MENUS_TASK_PRIO);
|
||||
|
||||
#if !defined(SIMU)
|
||||
// TODO move the SIMU audio in this task
|
||||
audioTaskId = CoCreateTask(audioTask, NULL, 7, &audioStack.stack[AUDIO_STACK_SIZE-1], AUDIO_STACK_SIZE);
|
||||
RTOS_CREATE_TASK(audioTaskId, audioTask, "Audio", audioStack, AUDIO_STACK_SIZE, AUDIO_TASK_PRIO);
|
||||
#endif
|
||||
|
||||
audioMutex = CoCreateMutex();
|
||||
mixerMutex = CoCreateMutex();
|
||||
RTOS_CREATE_MUTEX(audioMutex);
|
||||
RTOS_CREATE_MUTEX(mixerMutex);
|
||||
|
||||
CoStartOS();
|
||||
RTOS_START();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue