From 92f27a853ae16c194ccc302bc6b2a4a03e5be748 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 8 Sep 2020 12:07:09 +0200 Subject: [PATCH] moved sync pulse sending to *before* periodic mixer processing This should enable a more stable pulse sending to the module. --- radio/src/opentx.cpp | 13 +++++++++++++ radio/src/opentx.h | 1 + radio/src/tasks.cpp | 11 ++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 73b39c407..bebb5b317 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1426,6 +1426,19 @@ void doMixerCalculations() DEBUG_TIMER_START(debugTimerEvalMixes); evalMixes(tick10ms); DEBUG_TIMER_STOP(debugTimerEvalMixes); +} + +void doMixerPeriodicUpdates() +{ + static tmr10ms_t lastTMR = 0; + + tmr10ms_t tmr10ms = get_tmr10ms(); + + uint8_t tick10ms = (tmr10ms >= lastTMR ? tmr10ms - lastTMR : 1); + // handle tick10ms overrun + // correct overflow handling costs a lot of code; happens only each 11 min; + // therefore forget the exact calculation and use only 1 instead; good compromise + lastTMR = tmr10ms; DEBUG_TIMER_START(debugTimerMixes10ms); if (tick10ms) { diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 394a0734f..6d028ff06 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -483,6 +483,7 @@ extern uint32_t nextMixerTime[NUM_MODULES]; void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms); void evalMixes(uint8_t tick10ms); void doMixerCalculations(); +void doMixerPeriodicUpdates(); void checkTrims(); extern uint8_t currentBacklightBright; diff --git a/radio/src/tasks.cpp b/radio/src/tasks.cpp index e4c209edd..431ed7e52 100644 --- a/radio/src/tasks.cpp +++ b/radio/src/tasks.cpp @@ -168,12 +168,20 @@ TASK_FUNCTION(mixerTask) DEBUG_TIMER_START(debugTimerMixer); RTOS_LOCK_MUTEX(mixerMutex); + doMixerCalculations(); + + // TODO: fix runMask + sendSynchronousPulses((1 << INTERNAL_MODULE) | (1 << EXTERNAL_MODULE)); + + doMixerPeriodicUpdates(); + DEBUG_TIMER_START(debugTimerMixerCalcToUsage); DEBUG_TIMER_SAMPLE(debugTimerMixerIterval); RTOS_UNLOCK_MUTEX(mixerMutex); DEBUG_TIMER_STOP(debugTimerMixer); + #if defined(STM32) && !defined(SIMU) if (getSelectedUsbMode() == USB_JOYSTICK_MODE) { usbJoystickUpdate(); @@ -202,9 +210,6 @@ TASK_FUNCTION(mixerTask) // between protocols with multi-proto RF if (timeout) serialPrint("mix sched timeout!"); - - // TODO: fix runMask - sendSynchronousPulses((1 << INTERNAL_MODULE) | (1 << EXTERNAL_MODULE)); } } }