1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-17 21:35:27 +03:00

More work on pulses ...

This commit is contained in:
Bertrand Songis 2019-02-05 11:47:04 +01:00
parent 53bb46ef81
commit 9aa75b1056
19 changed files with 261 additions and 222 deletions

View file

@ -28,7 +28,7 @@ extern uint8_t cliTracesEnabled;
#ifdef __cplusplus #ifdef __cplusplus
#include "fifo.h" #include "fifo.h"
extern Fifo<uint8_t, 256> cliRxFifo; extern Fifo<uint8_t, 256> cliRxFifo;
#include "tasks_arm.h" #include "tasks.h"
extern RTOS_TASK_HANDLE cliTaskId; extern RTOS_TASK_HANDLE cliTaskId;
extern RTOS_DEFINE_STACK(cliStack, CLI_STACK_SIZE); extern RTOS_DEFINE_STACK(cliStack, CLI_STACK_SIZE);
#endif #endif

View file

@ -1907,7 +1907,6 @@ void opentxInit(OPENTX_INIT_ARGS)
init_trainer_capture(); init_trainer_capture();
#endif #endif
startPulses(); startPulses();
wdt_enable(WDTO_500MS); wdt_enable(WDTO_500MS);

View file

@ -657,7 +657,7 @@ uint16_t isqrt32(uint32_t n);
#define pauseMixerCalculations() #define pauseMixerCalculations()
#define resumeMixerCalculations() #define resumeMixerCalculations()
#else #else
#include "tasks_arm.h" #include "tasks.h"
extern RTOS_MUTEX_HANDLE mixerMutex; extern RTOS_MUTEX_HANDLE mixerMutex;
inline void pauseMixerCalculations() inline void pauseMixerCalculations()
{ {
@ -1040,7 +1040,7 @@ enum AUDIO_SOUNDS {
}; };
#if defined(AUDIO) #if defined(AUDIO)
#include "audio_arm.h" #include "audio.h"
#endif #endif
#include "buzzer.h" #include "buzzer.h"

View file

@ -48,7 +48,7 @@ uint8_t getRequiredProtocol(uint8_t port)
break; break;
#endif #endif
case MODULE_TYPE_XJT: case MODULE_TYPE_XJT:
required_protocol = PROTOCOL_CHANNELS_PXX; required_protocol = PROTOCOL_CHANNELS_PXX2;
break; break;
default: default:
required_protocol = PROTOCOL_CHANNELS_NONE; required_protocol = PROTOCOL_CHANNELS_NONE;
@ -139,58 +139,118 @@ void setupPulsesPXX(uint8_t port)
#endif #endif
} }
void setupPulses(uint8_t port) void setupPulsesPXX2(uint8_t module)
{ {
bool init_needed = false; if (module == INTERNAL_MODULE) {
uint8_t required_protocol = getRequiredProtocol(port); 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) { void disablePulses(uint8_t port, uint8_t protocol)
init_needed = true; {
switch (s_current_protocol[port]) { // stop existing protocol hardware // stop existing protocol hardware
case PROTOCOL_CHANNELS_PXX:
disable_pxx(port); switch (protocol) {
break; case PROTOCOL_CHANNELS_PXX:
disable_pxx(port);
break;
#if defined(DSM2) #if defined(DSM2)
case PROTOCOL_CHANNELS_DSM2_LP45: case PROTOCOL_CHANNELS_DSM2_LP45:
case PROTOCOL_CHANNELS_DSM2_DSM2: case PROTOCOL_CHANNELS_DSM2_DSM2:
case PROTOCOL_CHANNELS_DSM2_DSMX: case PROTOCOL_CHANNELS_DSM2_DSMX:
disable_serial(port); disable_serial(port);
break; break;
#endif #endif
#if defined(CROSSFIRE) #if defined(CROSSFIRE)
case PROTOCOL_CHANNELS_CROSSFIRE: case PROTOCOL_CHANNELS_CROSSFIRE:
disable_module_timer(port); disable_module_timer(port);
break; break;
#endif #endif
case PROTOCOL_CHANNELS_PXX2: case PROTOCOL_CHANNELS_PXX2:
disable_module_timer(port); disable_pxx2(port);
break; break;
#if defined(MULTIMODULE) #if defined(MULTIMODULE)
case PROTOCOL_CHANNELS_MULTIMODULE: case PROTOCOL_CHANNELS_MULTIMODULE:
#endif #endif
case PROTOCOL_CHANNELS_SBUS: case PROTOCOL_CHANNELS_SBUS:
disable_serial(port); disable_serial(port);
break; break;
case PROTOCOL_CHANNELS_PPM: case PROTOCOL_CHANNELS_PPM:
disable_ppm(port); disable_ppm(port);
break; break;
default: default:
disable_no_pulses(port); disable_no_pulses(port);
break; break;
}
s_current_protocol[port] = required_protocol;
} }
}
// Set up output data here void enablePulses(uint8_t port, uint8_t protocol)
switch (required_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: case PROTOCOL_CHANNELS_PXX:
setupPulsesPXX(port); setupPulsesPXX(port);
scheduleNextMixerCalculation(port, PXX_PERIOD); scheduleNextMixerCalculation(port, PXX_PERIOD);
@ -212,7 +272,7 @@ void setupPulses(uint8_t port)
#if defined(CROSSFIRE) #if defined(CROSSFIRE)
case PROTOCOL_CHANNELS_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 * crossfire = modulePulsesData[port].crossfire.pulses;
uint8_t len; uint8_t len;
#if defined(LUA) #if defined(LUA)
@ -234,11 +294,7 @@ void setupPulses(uint8_t port)
#endif #endif
case PROTOCOL_CHANNELS_PXX2: case PROTOCOL_CHANNELS_PXX2:
// here we have to wait that telemetryInit() is called, hence this test setupPulsesPXX2(port);
if (telemetryProtocol == PROTOCOL_TELEMETRY_PXX2 && !init_needed) {
modulePulsesData[port].pxx2.setupFrame(port);
sportSendBuffer(modulePulsesData[port].pxx2.getData(), modulePulsesData[port].pxx2.getSize());
}
scheduleNextMixerCalculation(port, PXX2_PERIOD); scheduleNextMixerCalculation(port, PXX2_PERIOD);
break; break;
@ -251,7 +307,7 @@ void setupPulses(uint8_t port)
case PROTOCOL_CHANNELS_PPM: case PROTOCOL_CHANNELS_PPM:
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
case PROTOCOL_CHANNELS_NONE: case PROTOCOL_CHANNELS_NONE:
#endif #endif
setupPulsesPPMModule(port); setupPulsesPPMModule(port);
scheduleNextMixerCalculation(port, PPM_PERIOD(port)); scheduleNextMixerCalculation(port, PPM_PERIOD(port));
@ -260,49 +316,21 @@ void setupPulses(uint8_t port)
default: default:
break; break;
} }
}
if (init_needed) { void setupPulses(uint8_t module)
switch (required_protocol) { // Start new protocol hardware here {
case PROTOCOL_CHANNELS_PXX: uint8_t required_protocol = getRequiredProtocol(module);
init_pxx(port);
break;
#if defined(DSM2) heartbeat |= (HEART_TIMER_PULSES << module);
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) if (s_current_protocol[module] != required_protocol) {
case PROTOCOL_CHANNELS_CROSSFIRE: disablePulses(module, s_current_protocol[module]);
init_module_timer(port, CROSSFIRE_PERIOD, true); s_current_protocol[module] = required_protocol;
break; enablePulses(module, required_protocol);
#endif }
else {
case PROTOCOL_CHANNELS_PXX2: sendPulses(module, required_protocol);
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;
}
} }
} }

View file

@ -88,9 +88,9 @@ foreach(LANGUAGE ${TTS_LANGUAGES})
endforeach() endforeach()
set(SRC set(SRC
${SRC} ${SRC}
main_arm.cpp main.cpp
tasks_arm.cpp tasks.cpp
audio_arm.cpp audio.cpp
io/frsky_sport.cpp io/frsky_sport.cpp
telemetry/telemetry.cpp telemetry/telemetry.cpp
telemetry/telemetry_holders.cpp telemetry/telemetry_holders.cpp

View file

@ -23,40 +23,20 @@
void intmoduleStop() void intmoduleStop()
{ {
INTERNAL_MODULE_OFF(); INTERNAL_MODULE_OFF();
NVIC_DisableIRQ(INTMODULE_TIMER_IRQn);
INTMODULE_DMA_STREAM->CR &= ~DMA_SxCR_EN; // Disable DMA 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() 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(); INTERNAL_MODULE_ON();
@ -94,23 +74,6 @@ void intmodulePxxStart()
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(INTMODULE_USART, &USART_InitStructure); USART_Init(INTMODULE_USART, &USART_InitStructure);
USART_Cmd(INTMODULE_USART, ENABLE); 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) extern "C" void INTMODULE_DMA_STREAM_IRQHandler(void)
@ -124,14 +87,14 @@ extern "C" void INTMODULE_DMA_STREAM_IRQHandler(void)
void intmoduleSendNextFrame() 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_InitTypeDef DMA_InitStructure;
DMA_DeInit(INTMODULE_DMA_STREAM); DMA_DeInit(INTMODULE_DMA_STREAM);
DMA_InitStructure.DMA_Channel = INTMODULE_DMA_CHANNEL; DMA_InitStructure.DMA_Channel = INTMODULE_DMA_CHANNEL;
DMA_InitStructure.DMA_PeripheralBaseAddr = CONVERT_PTR_UINT(&INTMODULE_USART->DR); DMA_InitStructure.DMA_PeripheralBaseAddr = CONVERT_PTR_UINT(&INTMODULE_USART->DR);
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_Memory0BaseAddr = CONVERT_PTR_UINT(modulePulsesData[INTERNAL_MODULE].pxx_uart.getData()); DMA_InitStructure.DMA_Memory0BaseAddr = CONVERT_PTR_UINT(modulePulsesData[INTERNAL_MODULE].pxx2.getData());
DMA_InitStructure.DMA_BufferSize = modulePulsesData[INTERNAL_MODULE].pxx_uart.getSize(); DMA_InitStructure.DMA_BufferSize = modulePulsesData[INTERNAL_MODULE].pxx2.getSize();
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
@ -143,21 +106,7 @@ void intmoduleSendNextFrame()
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(INTMODULE_DMA_STREAM, &DMA_InitStructure); DMA_Init(INTMODULE_DMA_STREAM, &DMA_InitStructure);
DMA_Cmd(INTMODULE_DMA_STREAM, ENABLE); DMA_Cmd(INTMODULE_DMA_STREAM, ENABLE);
USART_DMACmd(INTMODULE_USART, USART_DMAReq_Tx, 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);
}

View file

@ -65,7 +65,6 @@ void extmoduleTimerStart(uint32_t period, uint8_t state)
NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7); NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7);
} }
void extmodulePpmStart() void extmodulePpmStart()
{ {
EXTERNAL_MODULE_ON(); EXTERNAL_MODULE_ON();
@ -165,6 +164,11 @@ void extmodulePxxStart()
NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7); NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7);
} }
void extmodulePxx2Start()
{
// TODO just enable the S.PORT line (or let telemetry init do it)
}
#if defined(DSM2) #if defined(DSM2)
void extmoduleSerialStart(uint32_t /*baudrate*/, uint32_t period_half_us) void extmoduleSerialStart(uint32_t /*baudrate*/, uint32_t period_half_us)
{ {

View file

@ -20,23 +20,20 @@
#include "opentx.h" #include "opentx.h"
void intmoduleStop(void); void intmoduleStop();
void extmoduleStop(void); void intmoduleTimerStart(uint32_t period, uint8_t state);
void intmodulePxxStart();
void intmoduleNoneStart(void);
void intmodulePxxStart(void);
void extmoduleStop();
void extmoduleTimerStart(uint32_t period, uint8_t state); void extmoduleTimerStart(uint32_t period, uint8_t state);
void extmodulePpmStart(void); void extmodulePpmStart();
void extmodulePxxStart(void); void extmodulePxxStart();
void extmodulePxx2Start();
void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us); void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us);
void init_no_pulses(uint32_t port) void init_no_pulses(uint32_t port)
{ {
if (port == INTERNAL_MODULE) init_module_timer(port, 18, false);
intmoduleNoneStart();
else
extmoduleTimerStart(18, false);
} }
void disable_no_pulses(uint32_t port) 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) void init_pxx(uint32_t port)
{ {
if (port == INTERNAL_MODULE) 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) 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); extmoduleTimerStart(period, state);
}
} }
void disable_module_timer(uint32_t port) void disable_module_timer(uint32_t port)
{ {
if (port == EXTERNAL_MODULE) { if (port == INTERNAL_MODULE)
intmoduleStop();
else
extmoduleStop(); extmoduleStop();
}
} }

View file

@ -119,6 +119,7 @@ elseif(PCB STREQUAL XLITES)
endif() endif()
if(PCB STREQUAL XLITE OR PCB STREQUAL XLITES) if(PCB STREQUAL XLITE OR PCB STREQUAL XLITES)
add_definitions(-DINTERNAL_MODULE_SERIAL)
if(PXX_FREQUENCY STREQUAL HIGH) if(PXX_FREQUENCY STREQUAL HIGH)
add_definitions(-DPXX_FREQUENCY_HIGH) add_definitions(-DPXX_FREQUENCY_HIGH)
endif() endif()

View file

@ -180,16 +180,19 @@ uint32_t isBootloaderStart(const uint8_t * buffer);
#else #else
#define IS_UART_MODULE(port) (false) #define IS_UART_MODULE(port) (false)
#endif #endif
void init_no_pulses(uint32_t port); void init_no_pulses(uint8_t module);
void disable_no_pulses(uint32_t port); void disable_no_pulses(uint8_t module);
void init_ppm( uint32_t module_index); void init_ppm(uint8_t module);
void disable_ppm( uint32_t module_index); void disable_ppm(uint8_t module);
void init_pxx( uint32_t module_index); void intmoduleSendNextFrame();
void disable_pxx( uint32_t module_index); void init_pxx2(uint8_t module);
void init_serial( uint32_t module_index, uint32_t baudrate, uint32_t period); void disable_pxx2(uint8_t module);
void disable_serial( uint32_t module_index); void init_pxx(uint8_t module);
void init_module_timer( uint32_t module_index, uint32_t period, uint8_t state); void disable_pxx(uint8_t module);
void disable_module_timer( uint32_t module_index); 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 // Trainer driver
#define SLAVE_MODE() (g_model.trainerData.mode == TRAINER_MODE_SLAVE) #define SLAVE_MODE() (g_model.trainerData.mode == TRAINER_MODE_SLAVE)

View file

@ -200,6 +200,11 @@ void extmodulePxxStart()
{ {
extmoduleInvertedSerialStart(EXTMODULE_USART_PXX_BAUDRATE, PXX_PERIOD_HALF_US); extmoduleInvertedSerialStart(EXTMODULE_USART_PXX_BAUDRATE, PXX_PERIOD_HALF_US);
} }
void extmodulePxx2Start()
{
extmoduleInvertedSerialStart(EXTMODULE_USART_PXX_BAUDRATE, PXX_PERIOD_HALF_US);
}
#else #else
void extmodulePxxStart() void extmodulePxxStart()
{ {
@ -234,6 +239,11 @@ void extmodulePxxStart()
NVIC_EnableIRQ(EXTMODULE_TIMER_CC_IRQn); NVIC_EnableIRQ(EXTMODULE_TIMER_CC_IRQn);
NVIC_SetPriority(EXTMODULE_TIMER_CC_IRQn, 7); NVIC_SetPriority(EXTMODULE_TIMER_CC_IRQn, 7);
} }
void extmodulePxx2Start()
{
// TODO just enable the S.PORT line (or let telemetry init do it)
}
#endif #endif
void extmoduleSendNextFrame() void extmoduleSendNextFrame()

View file

@ -32,9 +32,14 @@ void intmoduleStop()
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN; 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_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = INTMODULE_TX_GPIO_PIN; 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 GPIO_SetBits(INTMODULE_TX_GPIO, INTMODULE_TX_GPIO_PIN); // Set high
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN; INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
INTMODULE_TIMER->PSC = INTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS from 30MHz INTMODULE_TIMER->PSC = EXTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS from 30MHz
INTMODULE_TIMER->ARR = 36000; // 18mS INTMODULE_TIMER->ARR = (2000 * period);
INTMODULE_TIMER->CCR2 = 32000; // Update time INTMODULE_TIMER->CCR2 = (2000 * period) - 1000;
INTMODULE_TIMER->EGR = 1; // Restart INTMODULE_TIMER->EGR = 1; // Restart
INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; // Clear flag INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; // Clear flag
INTMODULE_TIMER->DIER |= TIM_DIER_CC2IE; // Enable this interrupt INTMODULE_TIMER->DIER |= TIM_DIER_CC2IE; // Enable this interrupt

View file

@ -20,103 +20,118 @@
#include "opentx.h" #include "opentx.h"
void intmoduleStop(void); void intmoduleStop();
void extmoduleStop(void); void intmoduleTimerStart(uint32_t period, uint8_t state);
void intmodulePxxStart();
void intmoduleNoneStart(void); void intmodulePxx2Start();
void intmodulePxxStart(void);
#if defined(TARANIS_INTERNAL_PPM) #if defined(TARANIS_INTERNAL_PPM)
void intmodulePpmStart(void); void intmodulePpmStart(void);
#endif #endif
void extmoduleStop();
void extmoduleTimerStart(uint32_t period, uint8_t state); void extmoduleTimerStart(uint32_t period, uint8_t state);
void extmodulePpmStart(void); void extmodulePpmStart();
void extmodulePxxStart(void); void extmodulePxxStart();
void extmodulePxx2Start();
void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us); void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us);
void init_pxx(uint8_t module)
void init_pxx(uint32_t port)
{ {
if (port == INTERNAL_MODULE) if (module == INTERNAL_MODULE)
intmodulePxxStart(); intmodulePxxStart();
else else
extmodulePxxStart(); 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(); intmoduleStop();
else else
extmoduleStop(); extmoduleStop();
} }
#if defined(DSM2) #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); 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(); extmoduleStop();
} }
} }
#endif #endif
void init_ppm(uint32_t port) void init_ppm(uint8_t module)
{ {
if (port == EXTERNAL_MODULE) { if (module == EXTERNAL_MODULE) {
extmodulePpmStart(); extmodulePpmStart();
} }
#if defined(TARANIS_INTERNAL_PPM) #if defined(TARANIS_INTERNAL_PPM)
else if (port == INTERNAL_MODULE) { else {
intmodulePpmStart(); intmodulePpmStart();
} }
#endif #endif
} }
void disable_ppm(uint32_t port) void disable_ppm(uint8_t module)
{ {
if (port == EXTERNAL_MODULE) { if (module == EXTERNAL_MODULE) {
extmoduleStop(); extmoduleStop();
} }
#if defined(TARANIS_INTERNAL_PPM) #if defined(TARANIS_INTERNAL_PPM)
else if (port == INTERNAL_MODULE) { else {
intmoduleStop(); intmoduleStop();
} }
#endif #endif
} }
void init_no_pulses(uint32_t port) void init_no_pulses(uint8_t module)
{ {
if (port == INTERNAL_MODULE) init_module_timer(module, 18, false);
intmoduleNoneStart();
else
extmoduleTimerStart(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(); intmoduleStop();
else else
extmoduleStop(); 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); 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(); extmoduleStop();
}
} }

View file

@ -73,6 +73,21 @@ bool isForcePowerOffRequested()
return false; 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]; uint32_t nextMixerTime[NUM_MODULES];
TASK_FUNCTION(mixerTask) TASK_FUNCTION(mixerTask)
@ -89,8 +104,9 @@ TASK_FUNCTION(mixerTask)
RTOS_WAIT_TICKS(1); RTOS_WAIT_TICKS(1);
#if defined(SIMU) #if defined(SIMU)
if (pwrCheck() == e_power_off) if (pwrCheck() == e_power_off) {
TASK_RETURN(); TASK_RETURN();
}
#else #else
if (isForcePowerOffRequested()) { if (isForcePowerOffRequested()) {
pwrOff(); pwrOff();
@ -153,7 +169,9 @@ TASK_FUNCTION(mixerTask)
} }
t0 = getTmr2MHz() - t0; t0 = getTmr2MHz() - t0;
if (t0 > maxMixerDuration) maxMixerDuration = t0 ; if (t0 > maxMixerDuration) maxMixerDuration = t0;
sendSynchronousPulses();
} }
} }
} }

View file

@ -24,7 +24,7 @@ int16_t ppmInput[MAX_TRAINER_CHANNELS];
uint8_t ppmInputValidityTimer; uint8_t ppmInputValidityTimer;
#include "audio_arm.h" #include "audio.h"
void checkTrainerSignalWarning() void checkTrainerSignalWarning()
{ {