diff --git a/radio/src/audio_arm.cpp b/radio/src/audio.cpp similarity index 100% rename from radio/src/audio_arm.cpp rename to radio/src/audio.cpp diff --git a/radio/src/audio_arm.h b/radio/src/audio.h similarity index 100% rename from radio/src/audio_arm.h rename to radio/src/audio.h diff --git a/radio/src/cli.h b/radio/src/cli.h index fdb96d6d1..a590e101c 100644 --- a/radio/src/cli.h +++ b/radio/src/cli.h @@ -28,7 +28,7 @@ extern uint8_t cliTracesEnabled; #ifdef __cplusplus #include "fifo.h" extern Fifo cliRxFifo; -#include "tasks_arm.h" +#include "tasks.h" extern RTOS_TASK_HANDLE cliTaskId; extern RTOS_DEFINE_STACK(cliStack, CLI_STACK_SIZE); #endif diff --git a/radio/src/main_arm.cpp b/radio/src/main.cpp similarity index 100% rename from radio/src/main_arm.cpp rename to radio/src/main.cpp diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index ec716ea5f..feb604939 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1907,7 +1907,6 @@ void opentxInit(OPENTX_INIT_ARGS) init_trainer_capture(); #endif - startPulses(); wdt_enable(WDTO_500MS); diff --git a/radio/src/opentx.h b/radio/src/opentx.h index add26a283..e2d79bc14 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -657,7 +657,7 @@ uint16_t isqrt32(uint32_t n); #define pauseMixerCalculations() #define resumeMixerCalculations() #else -#include "tasks_arm.h" +#include "tasks.h" extern RTOS_MUTEX_HANDLE mixerMutex; inline void pauseMixerCalculations() { @@ -1040,7 +1040,7 @@ enum AUDIO_SOUNDS { }; #if defined(AUDIO) -#include "audio_arm.h" +#include "audio.h" #endif #include "buzzer.h" diff --git a/radio/src/pulses/pulses_arm.cpp b/radio/src/pulses/pulses_arm.cpp index 290369e3a..83963ed86 100755 --- a/radio/src/pulses/pulses_arm.cpp +++ b/radio/src/pulses/pulses_arm.cpp @@ -48,7 +48,7 @@ uint8_t getRequiredProtocol(uint8_t port) break; #endif case MODULE_TYPE_XJT: - required_protocol = PROTOCOL_CHANNELS_PXX; + required_protocol = PROTOCOL_CHANNELS_PXX2; break; default: required_protocol = PROTOCOL_CHANNELS_NONE; @@ -139,58 +139,118 @@ void setupPulsesPXX(uint8_t port) #endif } -void setupPulses(uint8_t port) +void setupPulsesPXX2(uint8_t module) { - bool init_needed = false; - uint8_t required_protocol = getRequiredProtocol(port); + if (module == INTERNAL_MODULE) { + modulePulsesData[module].pxx2.setupFrame(module); + intmoduleSendNextFrame(); + } - heartbeat |= (HEART_TIMER_PULSES << port); +#if 0 + // here we have to wait that telemetryInit() is called, hence this test + if (telemetryProtocol == PROTOCOL_TELEMETRY_PXX2) { + modulePulsesData[port].pxx2.setupFrame(port); + sportSendBuffer(modulePulsesData[port].pxx2.getData(), modulePulsesData[port].pxx2.getSize()); + } +#endif +} - if (s_current_protocol[port] != required_protocol) { - init_needed = true; - switch (s_current_protocol[port]) { // stop existing protocol hardware - case PROTOCOL_CHANNELS_PXX: - disable_pxx(port); - break; +void disablePulses(uint8_t port, uint8_t protocol) +{ + // stop existing protocol hardware + + switch (protocol) { + case PROTOCOL_CHANNELS_PXX: + disable_pxx(port); + break; #if defined(DSM2) - case PROTOCOL_CHANNELS_DSM2_LP45: - case PROTOCOL_CHANNELS_DSM2_DSM2: - case PROTOCOL_CHANNELS_DSM2_DSMX: - disable_serial(port); - break; + case PROTOCOL_CHANNELS_DSM2_LP45: + case PROTOCOL_CHANNELS_DSM2_DSM2: + case PROTOCOL_CHANNELS_DSM2_DSMX: + disable_serial(port); + break; #endif #if defined(CROSSFIRE) - case PROTOCOL_CHANNELS_CROSSFIRE: - disable_module_timer(port); - break; + case PROTOCOL_CHANNELS_CROSSFIRE: + disable_module_timer(port); + break; #endif - case PROTOCOL_CHANNELS_PXX2: - disable_module_timer(port); - break; + case PROTOCOL_CHANNELS_PXX2: + disable_pxx2(port); + break; #if defined(MULTIMODULE) case PROTOCOL_CHANNELS_MULTIMODULE: #endif - case PROTOCOL_CHANNELS_SBUS: - disable_serial(port); - break; + case PROTOCOL_CHANNELS_SBUS: + disable_serial(port); + break; - case PROTOCOL_CHANNELS_PPM: - disable_ppm(port); - break; + case PROTOCOL_CHANNELS_PPM: + disable_ppm(port); + break; - default: - disable_no_pulses(port); - break; - } - s_current_protocol[port] = required_protocol; + default: + disable_no_pulses(port); + break; } +} - // Set up output data here - switch (required_protocol) { +void enablePulses(uint8_t port, uint8_t protocol) +{ + // start new protocol hardware here + + #warning "CHECK THAT ALL PROTOCOL INIT WON'T SEND A FIRST WRONG FRAME HERE" + + switch (protocol) { + case PROTOCOL_CHANNELS_PXX: + init_pxx(port); + break; + +#if defined(DSM2) + case PROTOCOL_CHANNELS_DSM2_LP45: + case PROTOCOL_CHANNELS_DSM2_DSM2: + case PROTOCOL_CHANNELS_DSM2_DSMX: + init_serial(port, DSM2_BAUDRATE, DSM2_PERIOD * 2000); + break; +#endif + +#if defined(CROSSFIRE) + case PROTOCOL_CHANNELS_CROSSFIRE: + init_module_timer(port, CROSSFIRE_PERIOD, true); + break; +#endif + + case PROTOCOL_CHANNELS_PXX2: + init_pxx2(port); + break; + +#if defined(MULTIMODULE) + case PROTOCOL_CHANNELS_MULTIMODULE: + init_serial(port, MULTIMODULE_BAUDRATE, MULTIMODULE_PERIOD * 2000); + break; +#endif + + case PROTOCOL_CHANNELS_SBUS: + init_serial(port, SBUS_BAUDRATE, SBUS_PERIOD_HALF_US); + break; + + case PROTOCOL_CHANNELS_PPM: + init_ppm(port); + break; + + default: + init_no_pulses(port); + break; + } +} + +void sendPulses(uint8_t port, uint8_t protocol) +{ + switch (protocol) { case PROTOCOL_CHANNELS_PXX: setupPulsesPXX(port); scheduleNextMixerCalculation(port, PXX_PERIOD); @@ -212,7 +272,7 @@ void setupPulses(uint8_t port) #if defined(CROSSFIRE) case PROTOCOL_CHANNELS_CROSSFIRE: - if (telemetryProtocol == PROTOCOL_TELEMETRY_CROSSFIRE && !init_needed) { + if (telemetryProtocol == PROTOCOL_TELEMETRY_CROSSFIRE) { uint8_t * crossfire = modulePulsesData[port].crossfire.pulses; uint8_t len; #if defined(LUA) @@ -234,11 +294,7 @@ void setupPulses(uint8_t port) #endif case PROTOCOL_CHANNELS_PXX2: - // here we have to wait that telemetryInit() is called, hence this test - if (telemetryProtocol == PROTOCOL_TELEMETRY_PXX2 && !init_needed) { - modulePulsesData[port].pxx2.setupFrame(port); - sportSendBuffer(modulePulsesData[port].pxx2.getData(), modulePulsesData[port].pxx2.getSize()); - } + setupPulsesPXX2(port); scheduleNextMixerCalculation(port, PXX2_PERIOD); break; @@ -251,7 +307,7 @@ void setupPulses(uint8_t port) case PROTOCOL_CHANNELS_PPM: #if defined(PCBSKY9X) - case PROTOCOL_CHANNELS_NONE: + case PROTOCOL_CHANNELS_NONE: #endif setupPulsesPPMModule(port); scheduleNextMixerCalculation(port, PPM_PERIOD(port)); @@ -260,49 +316,21 @@ void setupPulses(uint8_t port) default: break; } +} - if (init_needed) { - switch (required_protocol) { // Start new protocol hardware here - case PROTOCOL_CHANNELS_PXX: - init_pxx(port); - break; +void setupPulses(uint8_t module) +{ + uint8_t required_protocol = getRequiredProtocol(module); -#if defined(DSM2) - case PROTOCOL_CHANNELS_DSM2_LP45: - case PROTOCOL_CHANNELS_DSM2_DSM2: - case PROTOCOL_CHANNELS_DSM2_DSMX: - init_serial(port, DSM2_BAUDRATE, DSM2_PERIOD * 2000); - break; -#endif + heartbeat |= (HEART_TIMER_PULSES << module); -#if defined(CROSSFIRE) - case PROTOCOL_CHANNELS_CROSSFIRE: - init_module_timer(port, CROSSFIRE_PERIOD, true); - break; -#endif - - case PROTOCOL_CHANNELS_PXX2: - init_module_timer(port, PXX2_PERIOD, true); - break; - -#if defined(MULTIMODULE) - case PROTOCOL_CHANNELS_MULTIMODULE: - init_serial(port, MULTIMODULE_BAUDRATE, MULTIMODULE_PERIOD * 2000); - break; -#endif - - case PROTOCOL_CHANNELS_SBUS: - init_serial(port, SBUS_BAUDRATE, SBUS_PERIOD_HALF_US); - break; - - case PROTOCOL_CHANNELS_PPM: - init_ppm(port); - break; - - default: - init_no_pulses(port); - break; - } + if (s_current_protocol[module] != required_protocol) { + disablePulses(module, s_current_protocol[module]); + s_current_protocol[module] = required_protocol; + enablePulses(module, required_protocol); + } + else { + sendPulses(module, required_protocol); } } diff --git a/radio/src/targets/common/arm/CMakeLists.txt b/radio/src/targets/common/arm/CMakeLists.txt index 3acf9aaa1..3e1b89fb6 100644 --- a/radio/src/targets/common/arm/CMakeLists.txt +++ b/radio/src/targets/common/arm/CMakeLists.txt @@ -88,9 +88,9 @@ foreach(LANGUAGE ${TTS_LANGUAGES}) endforeach() set(SRC ${SRC} - main_arm.cpp - tasks_arm.cpp - audio_arm.cpp + main.cpp + tasks.cpp + audio.cpp io/frsky_sport.cpp telemetry/telemetry.cpp telemetry/telemetry_holders.cpp diff --git a/radio/src/targets/common/arm/stm32/intmodule_serial_driver.cpp b/radio/src/targets/common/arm/stm32/intmodule_serial_driver.cpp index b372d8744..a91b944f6 100755 --- a/radio/src/targets/common/arm/stm32/intmodule_serial_driver.cpp +++ b/radio/src/targets/common/arm/stm32/intmodule_serial_driver.cpp @@ -23,40 +23,20 @@ void intmoduleStop() { INTERNAL_MODULE_OFF(); - - NVIC_DisableIRQ(INTMODULE_TIMER_IRQn); - INTMODULE_DMA_STREAM->CR &= ~DMA_SxCR_EN; // Disable DMA - INTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE; - INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN; -} - -void intmoduleNoneStart() -{ - INTERNAL_MODULE_OFF(); - - GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.GPIO_Pin = INTMODULE_TX_GPIO_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(INTMODULE_TX_GPIO, &GPIO_InitStructure); - GPIO_SetBits(INTMODULE_TX_GPIO, INTMODULE_TX_GPIO_PIN); // Set high - - INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN; - INTMODULE_TIMER->PSC = INTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS (2Mhz) - INTMODULE_TIMER->ARR = 36000; // 18mS - INTMODULE_TIMER->CCR2 = 32000; // Update time - INTMODULE_TIMER->EGR = 1; // Restart - INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; // Clear flag - INTMODULE_TIMER->DIER |= TIM_DIER_CC2IE; // Enable this interrupt - INTMODULE_TIMER->CR1 |= TIM_CR1_CEN; - NVIC_EnableIRQ(INTMODULE_TIMER_IRQn); - NVIC_SetPriority(INTMODULE_TIMER_IRQn, 7); } void intmodulePxxStart() +{ + // shouldn't be used anymore +} + +void intmoduleTimerStart(uint32_t period, uint8_t state) +{ + // shouldn't be used anymore +} + +void intmodulePxx2Start() { INTERNAL_MODULE_ON(); @@ -94,23 +74,6 @@ void intmodulePxxStart() USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(INTMODULE_USART, &USART_InitStructure); USART_Cmd(INTMODULE_USART, ENABLE); - - // Timer - INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN; - INTMODULE_TIMER->PSC = INTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS (2Mhz) - INTMODULE_TIMER->ARR = PXX_PERIOD_HALF_US; - INTMODULE_TIMER->CCR2 = PXX_PERIOD_HALF_US - 2000; // Update time - INTMODULE_TIMER->CCER = TIM_CCER_CC3E; - INTMODULE_TIMER->CCMR2 = 0; - INTMODULE_TIMER->EGR = 1; // Restart - - INTMODULE_TIMER->CCMR2 = TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_0; // Toggle CC1 o/p - INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; // Clear flag - INTMODULE_TIMER->DIER |= TIM_DIER_CC2IE; // Enable this interrupt - INTMODULE_TIMER->CR1 |= TIM_CR1_CEN; - - NVIC_EnableIRQ(INTMODULE_TIMER_IRQn); - NVIC_SetPriority(INTMODULE_TIMER_IRQn, 7); } extern "C" void INTMODULE_DMA_STREAM_IRQHandler(void) @@ -124,14 +87,14 @@ extern "C" void INTMODULE_DMA_STREAM_IRQHandler(void) void intmoduleSendNextFrame() { - if (s_current_protocol[INTERNAL_MODULE] == PROTOCOL_CHANNELS_PXX) { + if (s_current_protocol[INTERNAL_MODULE] == PROTOCOL_CHANNELS_PXX2) { DMA_InitTypeDef DMA_InitStructure; DMA_DeInit(INTMODULE_DMA_STREAM); DMA_InitStructure.DMA_Channel = INTMODULE_DMA_CHANNEL; DMA_InitStructure.DMA_PeripheralBaseAddr = CONVERT_PTR_UINT(&INTMODULE_USART->DR); DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; - DMA_InitStructure.DMA_Memory0BaseAddr = CONVERT_PTR_UINT(modulePulsesData[INTERNAL_MODULE].pxx_uart.getData()); - DMA_InitStructure.DMA_BufferSize = modulePulsesData[INTERNAL_MODULE].pxx_uart.getSize(); + DMA_InitStructure.DMA_Memory0BaseAddr = CONVERT_PTR_UINT(modulePulsesData[INTERNAL_MODULE].pxx2.getData()); + DMA_InitStructure.DMA_BufferSize = modulePulsesData[INTERNAL_MODULE].pxx2.getSize(); DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; @@ -143,21 +106,7 @@ void intmoduleSendNextFrame() DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(INTMODULE_DMA_STREAM, &DMA_InitStructure); - DMA_Cmd(INTMODULE_DMA_STREAM, ENABLE); USART_DMACmd(INTMODULE_USART, USART_DMAReq_Tx, ENABLE); } } - -extern "C" void INTMODULE_TIMER_IRQHandler() -{ - DEBUG_INTERRUPT(INT_TIM1CC); - DEBUG_TIMER_SAMPLE(debugTimerIntPulses); - DEBUG_TIMER_START(debugTimerIntPulsesDuration); - - INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; // clear flag - setupPulses(INTERNAL_MODULE); - intmoduleSendNextFrame(); - - DEBUG_TIMER_STOP(debugTimerIntPulsesDuration); -} diff --git a/radio/src/targets/horus/extmodule_driver.cpp b/radio/src/targets/horus/extmodule_driver.cpp index be1248b54..e8e71ae76 100644 --- a/radio/src/targets/horus/extmodule_driver.cpp +++ b/radio/src/targets/horus/extmodule_driver.cpp @@ -65,7 +65,6 @@ void extmoduleTimerStart(uint32_t period, uint8_t state) NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7); } - void extmodulePpmStart() { EXTERNAL_MODULE_ON(); @@ -165,6 +164,11 @@ void extmodulePxxStart() NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7); } +void extmodulePxx2Start() +{ + // TODO just enable the S.PORT line (or let telemetry init do it) +} + #if defined(DSM2) void extmoduleSerialStart(uint32_t /*baudrate*/, uint32_t period_half_us) { diff --git a/radio/src/targets/horus/pulses_driver.cpp b/radio/src/targets/horus/pulses_driver.cpp index 97305df0b..16009415c 100644 --- a/radio/src/targets/horus/pulses_driver.cpp +++ b/radio/src/targets/horus/pulses_driver.cpp @@ -20,23 +20,20 @@ #include "opentx.h" -void intmoduleStop(void); -void extmoduleStop(void); - -void intmoduleNoneStart(void); -void intmodulePxxStart(void); +void intmoduleStop(); +void intmoduleTimerStart(uint32_t period, uint8_t state); +void intmodulePxxStart(); +void extmoduleStop(); void extmoduleTimerStart(uint32_t period, uint8_t state); -void extmodulePpmStart(void); -void extmodulePxxStart(void); +void extmodulePpmStart(); +void extmodulePxxStart(); +void extmodulePxx2Start(); void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us); void init_no_pulses(uint32_t port) { - if (port == INTERNAL_MODULE) - intmoduleNoneStart(); - else - extmoduleTimerStart(18, false); + init_module_timer(port, 18, false); } void disable_no_pulses(uint32_t port) @@ -61,6 +58,14 @@ void disable_ppm(uint32_t port) } } +void init_pxx2(uint32_t port) +{ + if (port == INTERNAL_MODULE) + intmodulePxx2Start(); + else + extmodulePxx2Start(); +} + void init_pxx(uint32_t port) { if (port == INTERNAL_MODULE) @@ -95,15 +100,17 @@ void disable_serial(uint32_t port) void init_module_timer(uint32_t port, uint32_t period, uint8_t state) { - if (port == EXTERNAL_MODULE) { + if (port == INTERNAL_MODULE) + intmoduleTimerStart(period, state); + else extmoduleTimerStart(period, state); - } } void disable_module_timer(uint32_t port) { - if (port == EXTERNAL_MODULE) { + if (port == INTERNAL_MODULE) + intmoduleStop(); + else extmoduleStop(); - } } diff --git a/radio/src/targets/taranis/CMakeLists.txt b/radio/src/targets/taranis/CMakeLists.txt index 262c4ee5a..10c8405c0 100644 --- a/radio/src/targets/taranis/CMakeLists.txt +++ b/radio/src/targets/taranis/CMakeLists.txt @@ -119,6 +119,7 @@ elseif(PCB STREQUAL XLITES) endif() if(PCB STREQUAL XLITE OR PCB STREQUAL XLITES) + add_definitions(-DINTERNAL_MODULE_SERIAL) if(PXX_FREQUENCY STREQUAL HIGH) add_definitions(-DPXX_FREQUENCY_HIGH) endif() diff --git a/radio/src/targets/taranis/board.h b/radio/src/targets/taranis/board.h index d451cd5ad..89905bd43 100644 --- a/radio/src/targets/taranis/board.h +++ b/radio/src/targets/taranis/board.h @@ -180,16 +180,19 @@ uint32_t isBootloaderStart(const uint8_t * buffer); #else #define IS_UART_MODULE(port) (false) #endif -void init_no_pulses(uint32_t port); -void disable_no_pulses(uint32_t port); -void init_ppm( uint32_t module_index); -void disable_ppm( uint32_t module_index); -void init_pxx( uint32_t module_index); -void disable_pxx( uint32_t module_index); -void init_serial( uint32_t module_index, uint32_t baudrate, uint32_t period); -void disable_serial( uint32_t module_index); -void init_module_timer( uint32_t module_index, uint32_t period, uint8_t state); -void disable_module_timer( uint32_t module_index); +void init_no_pulses(uint8_t module); +void disable_no_pulses(uint8_t module); +void init_ppm(uint8_t module); +void disable_ppm(uint8_t module); +void intmoduleSendNextFrame(); +void init_pxx2(uint8_t module); +void disable_pxx2(uint8_t module); +void init_pxx(uint8_t module); +void disable_pxx(uint8_t module); +void init_serial(uint8_t module, uint32_t baudrate, uint32_t period); +void disable_serial(uint8_t module); +void init_module_timer(uint8_t module, uint32_t period, uint8_t state); +void disable_module_timer(uint8_t module); // Trainer driver #define SLAVE_MODE() (g_model.trainerData.mode == TRAINER_MODE_SLAVE) diff --git a/radio/src/targets/taranis/extmodule_driver.cpp b/radio/src/targets/taranis/extmodule_driver.cpp index b092499b9..109275c6f 100644 --- a/radio/src/targets/taranis/extmodule_driver.cpp +++ b/radio/src/targets/taranis/extmodule_driver.cpp @@ -200,6 +200,11 @@ void extmodulePxxStart() { extmoduleInvertedSerialStart(EXTMODULE_USART_PXX_BAUDRATE, PXX_PERIOD_HALF_US); } + +void extmodulePxx2Start() +{ + extmoduleInvertedSerialStart(EXTMODULE_USART_PXX_BAUDRATE, PXX_PERIOD_HALF_US); +} #else void extmodulePxxStart() { @@ -234,6 +239,11 @@ void extmodulePxxStart() NVIC_EnableIRQ(EXTMODULE_TIMER_CC_IRQn); NVIC_SetPriority(EXTMODULE_TIMER_CC_IRQn, 7); } + +void extmodulePxx2Start() +{ + // TODO just enable the S.PORT line (or let telemetry init do it) +} #endif void extmoduleSendNextFrame() diff --git a/radio/src/targets/taranis/intmodule_pulses_driver.cpp b/radio/src/targets/taranis/intmodule_pulses_driver.cpp index 10ef3303c..5058f3b74 100644 --- a/radio/src/targets/taranis/intmodule_pulses_driver.cpp +++ b/radio/src/targets/taranis/intmodule_pulses_driver.cpp @@ -32,9 +32,14 @@ void intmoduleStop() INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN; } -void intmoduleNoneStart() +void intmoduleTimerStart(uint32_t period, uint8_t state) { - INTERNAL_MODULE_OFF(); + if (state) + INTERNAL_MODULE_ON(); + else + INTERNAL_MODULE_OFF(); + + GPIO_PinAFConfig(EXTMODULE_TX_GPIO, EXTMODULE_TX_GPIO_PinSource, 0); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = INTMODULE_TX_GPIO_PIN; @@ -46,9 +51,9 @@ void intmoduleNoneStart() GPIO_SetBits(INTMODULE_TX_GPIO, INTMODULE_TX_GPIO_PIN); // Set high INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN; - INTMODULE_TIMER->PSC = INTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS from 30MHz - INTMODULE_TIMER->ARR = 36000; // 18mS - INTMODULE_TIMER->CCR2 = 32000; // Update time + INTMODULE_TIMER->PSC = EXTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS from 30MHz + INTMODULE_TIMER->ARR = (2000 * period); + INTMODULE_TIMER->CCR2 = (2000 * period) - 1000; INTMODULE_TIMER->EGR = 1; // Restart INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; // Clear flag INTMODULE_TIMER->DIER |= TIM_DIER_CC2IE; // Enable this interrupt diff --git a/radio/src/targets/taranis/pulses_driver.cpp b/radio/src/targets/taranis/pulses_driver.cpp index 9b7cfea4d..6e5070222 100644 --- a/radio/src/targets/taranis/pulses_driver.cpp +++ b/radio/src/targets/taranis/pulses_driver.cpp @@ -20,103 +20,118 @@ #include "opentx.h" -void intmoduleStop(void); -void extmoduleStop(void); - -void intmoduleNoneStart(void); -void intmodulePxxStart(void); +void intmoduleStop(); +void intmoduleTimerStart(uint32_t period, uint8_t state); +void intmodulePxxStart(); +void intmodulePxx2Start(); #if defined(TARANIS_INTERNAL_PPM) void intmodulePpmStart(void); #endif +void extmoduleStop(); void extmoduleTimerStart(uint32_t period, uint8_t state); -void extmodulePpmStart(void); -void extmodulePxxStart(void); +void extmodulePpmStart(); +void extmodulePxxStart(); +void extmodulePxx2Start(); void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us); - -void init_pxx(uint32_t port) +void init_pxx(uint8_t module) { - if (port == INTERNAL_MODULE) + if (module == INTERNAL_MODULE) intmodulePxxStart(); else extmodulePxxStart(); } -void disable_pxx(uint32_t port) +void disable_pxx(uint8_t module) { - if (port == INTERNAL_MODULE) + if (module == INTERNAL_MODULE) + intmoduleStop(); + else + extmoduleStop(); +} + +void init_pxx2(uint8_t module) +{ + if (module == INTERNAL_MODULE) + intmodulePxx2Start(); + else + extmodulePxx2Start(); +} + +void disable_pxx2(uint8_t module) +{ + if (module == INTERNAL_MODULE) intmoduleStop(); else extmoduleStop(); } #if defined(DSM2) -void init_serial(uint32_t port, uint32_t baudrate, uint32_t period_half_us) +void init_serial(uint8_t module, uint32_t baudrate, uint32_t period_half_us) { - if (port == EXTERNAL_MODULE) { + if (module == EXTERNAL_MODULE) { extmoduleSerialStart(baudrate, period_half_us); } } -void disable_serial(uint32_t port) +void disable_serial(uint8_t module) { - if (port == EXTERNAL_MODULE) { + if (module == EXTERNAL_MODULE) { extmoduleStop(); } } #endif -void init_ppm(uint32_t port) +void init_ppm(uint8_t module) { - if (port == EXTERNAL_MODULE) { + if (module == EXTERNAL_MODULE) { extmodulePpmStart(); } #if defined(TARANIS_INTERNAL_PPM) - else if (port == INTERNAL_MODULE) { + else { intmodulePpmStart(); } #endif } -void disable_ppm(uint32_t port) +void disable_ppm(uint8_t module) { - if (port == EXTERNAL_MODULE) { + if (module == EXTERNAL_MODULE) { extmoduleStop(); } #if defined(TARANIS_INTERNAL_PPM) - else if (port == INTERNAL_MODULE) { + else { intmoduleStop(); } #endif } -void init_no_pulses(uint32_t port) +void init_no_pulses(uint8_t module) { - if (port == INTERNAL_MODULE) - intmoduleNoneStart(); - else - extmoduleTimerStart(18, false); + init_module_timer(module, 18, false); } -void disable_no_pulses(uint32_t port) +void disable_no_pulses(uint8_t module) { - if (port == INTERNAL_MODULE) + if (module == INTERNAL_MODULE) intmoduleStop(); else extmoduleStop(); } -void init_module_timer(uint32_t port, uint32_t period, uint8_t state) +void init_module_timer(uint8_t module, uint32_t period, uint8_t state) { - if (port == EXTERNAL_MODULE) { + if (module == INTERNAL_MODULE) + intmoduleTimerStart(period, state); + else extmoduleTimerStart(period, state); - } } -void disable_module_timer(uint32_t port) +void disable_module_timer(uint8_t module) { - if (port == EXTERNAL_MODULE) { + if (module == INTERNAL_MODULE) + intmoduleStop(); + else extmoduleStop(); - } } diff --git a/radio/src/tasks_arm.cpp b/radio/src/tasks.cpp similarity index 91% rename from radio/src/tasks_arm.cpp rename to radio/src/tasks.cpp index 129684a4d..41901446d 100644 --- a/radio/src/tasks_arm.cpp +++ b/radio/src/tasks.cpp @@ -73,6 +73,21 @@ bool isForcePowerOffRequested() return false; } +bool isProtocolSynchronous(uint8_t protocol) +{ + return (protocol == PROTOCOL_CHANNELS_PXX2 || protocol == PROTOCOL_CHANNELS_NONE); +} + +void sendSynchronousPulses() +{ + for (uint8_t module = 0; module < NUM_MODULES; module++) { + uint8_t protocol = s_current_protocol[module]; + if (isProtocolSynchronous(protocol)) { + setupPulses(module); + } + } +} + uint32_t nextMixerTime[NUM_MODULES]; TASK_FUNCTION(mixerTask) @@ -89,8 +104,9 @@ TASK_FUNCTION(mixerTask) RTOS_WAIT_TICKS(1); #if defined(SIMU) - if (pwrCheck() == e_power_off) + if (pwrCheck() == e_power_off) { TASK_RETURN(); + } #else if (isForcePowerOffRequested()) { pwrOff(); @@ -153,7 +169,9 @@ TASK_FUNCTION(mixerTask) } t0 = getTmr2MHz() - t0; - if (t0 > maxMixerDuration) maxMixerDuration = t0 ; + if (t0 > maxMixerDuration) maxMixerDuration = t0; + + sendSynchronousPulses(); } } } diff --git a/radio/src/tasks_arm.h b/radio/src/tasks.h similarity index 100% rename from radio/src/tasks_arm.h rename to radio/src/tasks.h diff --git a/radio/src/trainer_input.cpp b/radio/src/trainer_input.cpp index 838c78297..a84ed0d6e 100644 --- a/radio/src/trainer_input.cpp +++ b/radio/src/trainer_input.cpp @@ -24,7 +24,7 @@ int16_t ppmInput[MAX_TRAINER_CHANNELS]; uint8_t ppmInputValidityTimer; -#include "audio_arm.h" +#include "audio.h" void checkTrainerSignalWarning() {