diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 3d3cc3ae7..ddfcb9830 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -502,6 +502,7 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms); void evalMixes(uint8_t tick10ms); void doMixerCalculations(); void doMixerPeriodicUpdates(); +void scheduleNextMixerCalculation(uint8_t module, uint32_t period_ms); void checkTrims(); extern uint8_t currentBacklightBright; diff --git a/radio/src/pulses/pulses.cpp b/radio/src/pulses/pulses.cpp index 7292bb200..810fd9378 100755 --- a/radio/src/pulses/pulses.cpp +++ b/radio/src/pulses/pulses.cpp @@ -241,8 +241,12 @@ void enablePulsesExternalModule(uint8_t protocol) case PROTOCOL_CHANNELS_DSM2_LP45: case PROTOCOL_CHANNELS_DSM2_DSM2: case PROTOCOL_CHANNELS_DSM2_DSMX: +#if defined(PCBSKY9X) + extmoduleSerialStart(DSM2_BAUDRATE, DSM2_PERIOD * 2000, false); +#else extmoduleSerialStart(); mixerSchedulerSetPeriod(EXTERNAL_MODULE, DSM2_PERIOD); +#endif break; #endif @@ -274,15 +278,23 @@ void enablePulsesExternalModule(uint8_t protocol) #if defined(MULTIMODULE) case PROTOCOL_CHANNELS_MULTIMODULE: +#if defined(PCBSKY9X) + extmoduleSerialStart(MULTIMODULE_BAUDRATE, MULTIMODULE_PERIOD * 2000, true); +#else extmoduleSerialStart(); mixerSchedulerSetPeriod(EXTERNAL_MODULE, MULTIMODULE_PERIOD); +#endif break; #endif #if defined(SBUS) case PROTOCOL_CHANNELS_SBUS: +#if defined(PCBSKY9X) + extmoduleSerialStart(SBUS_BAUDRATE, SBUS_PERIOD_HALF_US, false); +#else extmoduleSerialStart(); mixerSchedulerSetPeriod(EXTERNAL_MODULE, SBUS_PERIOD); +#endif break; #endif @@ -314,12 +326,18 @@ bool setupPulsesExternalModule(uint8_t protocol) #if defined(PXX1) case PROTOCOL_CHANNELS_PXX1_PULSES: extmodulePulsesData.pxx.setupFrame(EXTERNAL_MODULE); +#if defined(PCBSKY9X) + scheduleNextMixerCalculation(EXTERNAL_MODULE, PXX_PULSES_PERIOD); +#endif return true; #endif #if defined(PXX1) && defined(HARDWARE_EXTERNAL_MODULE_SIZE_SML) case PROTOCOL_CHANNELS_PXX1_SERIAL: extmodulePulsesData.pxx_uart.setupFrame(EXTERNAL_MODULE); +#if defined(PCBSKY9X) + scheduleNextMixerCalculation(EXTERNAL_MODULE, EXTMODULE_PXX1_SERIAL_PERIOD); +#endif return true; #endif @@ -327,13 +345,18 @@ bool setupPulsesExternalModule(uint8_t protocol) case PROTOCOL_CHANNELS_PXX2_HIGHSPEED: case PROTOCOL_CHANNELS_PXX2_LOWSPEED: extmodulePulsesData.pxx2.setupFrame(EXTERNAL_MODULE); +#if defined(PCBSKY9X) + sheduleNextMixerCalculation(EXTERNAL_MODULE, PXX2_PERIOD); +#endif return true; #endif #if defined(SBUS) case PROTOCOL_CHANNELS_SBUS: setupPulsesSbus(); - +#if defined(PCBSKY9X) + scheduleNextMixerCalculation(EXTERNAL_MODULE, SBUS_PERIOD); +#endif // SBUS_PERIOD is not a constant! It can be set from UI mixerSchedulerSetPeriod(EXTERNAL_MODULE, SBUS_PERIOD); return true; @@ -344,6 +367,9 @@ bool setupPulsesExternalModule(uint8_t protocol) case PROTOCOL_CHANNELS_DSM2_DSM2: case PROTOCOL_CHANNELS_DSM2_DSMX: setupPulsesDSM2(); +#if defined(PCBSKY9X) + scheduleNextMixerCalculation(EXTERNAL_MODULE, DSM2_PERIOD); +#endif return true; #endif @@ -356,6 +382,9 @@ bool setupPulsesExternalModule(uint8_t protocol) else mixerSchedulerSetPeriod(EXTERNAL_MODULE, CROSSFIRE_PERIOD); setupPulsesCrossfire(); +#if defined(PCBSKY9X) + scheduleNextMixerCalculation(EXTERNAL_MODULE, CROSSFIRE_PERIOD); +#endif return true; } #endif @@ -369,6 +398,9 @@ bool setupPulsesExternalModule(uint8_t protocol) else mixerSchedulerSetPeriod(EXTERNAL_MODULE, GHOST_PERIOD); setupPulsesGhost(); +#if defined(PCBSKPCBSKY9X) + scheduleNextMixerCalculation(EXTERNAL_MODULE, GHOST_PERIOD); +#endif return true; } #endif @@ -382,6 +414,9 @@ bool setupPulsesExternalModule(uint8_t protocol) else mixerSchedulerSetPeriod(EXTERNAL_MODULE, MULTIMODULE_PERIOD); setupPulsesMultiExternalModule(); +#if defined(PCBSKY9X) + scheduleNextMixerCalculation(EXTERNAL_MODULE, MULTIMODULE_PERIOD); +#endif return true; } #endif @@ -389,12 +424,18 @@ bool setupPulsesExternalModule(uint8_t protocol) #if defined(PPM) case PROTOCOL_CHANNELS_PPM: setupPulsesPPMExternalModule(); +#if defined(PCBSKY9X) + scheduleNextMixerCalculation(EXTERNAL_MODULE, PPM_PERIOD(EXTERNAL_MODULE)); +#endif return true; #endif #if defined(AFHDS3) case PROTOCOL_CHANNELS_AFHDS3: extmodulePulsesData.afhds3.setupFrame(); +#if defined(PCBSKY9X) + scheduleNextMixerCalculation(EXTERNAL_MODULE, AFHDS3_COMMAND_TIMEOUT); +#endif return true; #endif diff --git a/radio/src/tasks.cpp b/radio/src/tasks.cpp index d0aa8e3d2..97f78c972 100644 --- a/radio/src/tasks.cpp +++ b/radio/src/tasks.cpp @@ -118,7 +118,9 @@ TASK_FUNCTION(mixerTask) s_pulses_paused = true; mixerSchedulerInit(); +#if !defined(PCBSKY9X) mixerSchedulerStart(); +#endif while (true) { #if defined(SBUS_TRAINER) @@ -142,8 +144,10 @@ TASK_FUNCTION(mixerTask) GPIO_ResetBits(EXTMODULE_TX_GPIO, EXTMODULE_TX_GPIO_PIN); #endif +#if !defined(PCBSKY9X) // re-enable trigger mixerSchedulerEnableTrigger(); +#endif #if defined(SIMU) if (pwrCheck() == e_power_off) { @@ -164,7 +168,11 @@ TASK_FUNCTION(mixerTask) doMixerCalculations(); // TODO: fix runMask +#if defined(PCBSKY9X) + sendSynchronousPulses(1 << EXTERNAL_MODULE); +#else sendSynchronousPulses((1 << INTERNAL_MODULE) | (1 << EXTERNAL_MODULE)); +#endif doMixerPeriodicUpdates(); @@ -200,12 +208,32 @@ TASK_FUNCTION(mixerTask) // TODO: // - check the cause of timeouts when switching // between protocols with multi-proto RF +#if defined(DEBUG) if (timeout) serialPrint("mix sched timeout!"); +#endif } } } +void scheduleNextMixerCalculation(uint8_t module, uint32_t period_ms) +{ + // Schedule next mixer calculation time, + + if (isModuleSynchronous(module)) { + nextMixerTime[module] += period_ms / RTOS_MS_PER_TICK; + if (nextMixerTime[module] < RTOS_GET_TIME()) { + // we are late ... let's add some small delay + nextMixerTime[module] = (uint32_t) RTOS_GET_TIME() + (period_ms / RTOS_MS_PER_TICK); + } + } + else { + // for now assume mixer calculation takes 2 ms. + nextMixerTime[module] = (uint32_t) RTOS_GET_TIME() + (period_ms / RTOS_MS_PER_TICK); + } + + DEBUG_TIMER_STOP(debugTimerMixerCalcToUsage); +} #define MENU_TASK_PERIOD_TICKS (50 / RTOS_MS_PER_TICK) // 50ms diff --git a/radio/src/telemetry/multi.cpp b/radio/src/telemetry/multi.cpp index 1cb560b14..624effbba 100644 --- a/radio/src/telemetry/multi.cpp +++ b/radio/src/telemetry/multi.cpp @@ -252,8 +252,9 @@ static void processMultiSyncPacket(const uint8_t * data, uint8_t module) // inputLag -= refreshRate; status.update(refreshRate, inputLag); - +#if defined(DEBUG) serialPrint("MP ADJ: R %d, L %04d", refreshRate, inputLag); +#endif } #if defined(PCBTARANIS) || defined(PCBHORUS)