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
+3 -3
View File
@@ -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
@@ -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);
}
+5 -1
View File
@@ -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)
{
+22 -15
View File
@@ -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();
}
}
+1
View File
@@ -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()
+13 -10
View File
@@ -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)
@@ -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()
@@ -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
+50 -35
View File
@@ -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();
}
}