Code for telemetry splitted

This commit is contained in:
bsongis
2014-05-13 22:31:51 +02:00
parent 216ecc636a
commit c13d71c620
5 changed files with 202 additions and 192 deletions
+3 -9
View File
@@ -590,7 +590,7 @@ ifeq ($(PCB), $(filter $(PCB), SKY9X 9XRPRO))
EEPROMSRC = eeprom_common.cpp eeprom_raw.cpp eeprom_conversions.cpp
PULSESSRC = protocols/pulses_arm.cpp protocols/ppm_arm.cpp protocols/pxx_arm.cpp protocols/dsm2_arm.cpp
CPPSRC += audio_arm.cpp haptic.cpp gui/view_about.cpp
CPPSRC += targets/sky9x/pwr_driver.cpp targets/sky9x/adc_driver.cpp targets/sky9x/eeprom_driver.cpp targets/sky9x/pulses_driver.cpp targets/sky9x/keys_driver.cpp targets/sky9x/audio_driver.cpp targets/sky9x/buzzer_driver.cpp targets/sky9x/haptic_driver.cpp targets/sky9x/sdcard_driver.cpp targets/sky9x/massstorage.cpp
CPPSRC += targets/sky9x/telemetry_driver.cpp targets/sky9x/pwr_driver.cpp targets/sky9x/adc_driver.cpp targets/sky9x/eeprom_driver.cpp targets/sky9x/pulses_driver.cpp targets/sky9x/keys_driver.cpp targets/sky9x/audio_driver.cpp targets/sky9x/buzzer_driver.cpp targets/sky9x/haptic_driver.cpp targets/sky9x/sdcard_driver.cpp targets/sky9x/massstorage.cpp
CPPSRC += loadboot.cpp
ifeq ($(SDCARD), YES)
@@ -820,7 +820,6 @@ ifeq ($(FRSKY_STICKS), YES)
CPPDEFS += -DFRSKY_STICKS
endif
ifeq ($(DBLKEYS), YES)
ifeq ($(PCB), $(filter $(PCB), 9XR 9XR128 9XR2561))
$(warning Sorry, DBLKEYS doesnt work on 9XR)
@@ -930,13 +929,8 @@ endif
ifeq ($(EXT), $(filter $(EXT), FRSKY TELEMETREZ))
CPPDEFS += -DFRSKY
ifeq ($(PCB), TARANIS)
TELEMETRY_PROTO = $(shell sh -c "if test -f telemetry/frsky_sport.cpp; then echo SPORT; else echo FRSKY; fi")
ifeq ($(TELEMETRY_PROTO), SPORT)
CPPSRC += telemetry/frsky_sport.cpp
CPPDEFS += -DFRSKY_SPORT
else
CPPSRC += telemetry/frsky.cpp
endif
CPPSRC += telemetry/frsky_sport.cpp
CPPDEFS += -DFRSKY_SPORT
else
CPPSRC += telemetry/frsky.cpp
endif
+3 -178
View File
@@ -171,38 +171,6 @@ void UART3_Stop()
NVIC_DisableIRQ(UART1_IRQn) ;
}
// USART0 configuration
// Work in Progress, UNTESTED
// Uses PA5 and PA6 (RXD and TXD)
inline void UART2_Configure( uint32_t baudrate, uint32_t masterClock)
{
//// const Pin pPins[] = CONSOLE_PINS;
register Usart *pUsart = SECOND_USART;
/* Configure PIO */
configure_pins( (PIO_PA5 | PIO_PA6), PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA | PIN_NO_PULLUP ) ;
// /* Configure PMC */
PMC->PMC_PCER0 = 1 << SECOND_ID;
// /* Reset and disable receiver & transmitter */
pUsart->US_CR = US_CR_RSTRX | US_CR_RSTTX
| US_CR_RXDIS | US_CR_TXDIS;
// /* Configure mode */
pUsart->US_MR = 0x000008C0 ; // NORMAL, No Parity, 8 bit
// /* Configure baudrate */
// /* Asynchronous, no oversampling */
pUsart->US_BRGR = (masterClock / baudrate) / 16;
// /* Disable PDC channel */
pUsart->US_PTCR = US_PTCR_RXTDIS | US_PTCR_TXTDIS;
// /* Enable receiver and transmitter */
pUsart->US_CR = US_CR_RXEN | US_CR_TXEN;
}
// Starts TIMER0 at full speed (MCK/2) for delay timing
// @ 36MHz this is 18MHz
// This was 6 MHz, we may need to slow it to TIMER_CLOCK2 (MCK/8=4.5 MHz)
@@ -631,7 +599,6 @@ void boardInit()
PMC->PMC_PCK[2] = 2 ; // PCK2 is PLLA
DEBUG_UART_Configure( 9600, Master_frequency ) ;
UART2_Configure( 9600, Master_frequency ) ; // Testing
UART3_Configure( 9600, Master_frequency ) ; // TODO not needed, done after ...
start_timer2() ;
@@ -652,118 +619,15 @@ void boardInit()
#endif
init_SDcard();
UART2_Configure(9600, Master_frequency);
startPdcUsartReceive();
}
#endif
uint8_t temperature = 0; // Raw temp reading
uint8_t maxTemperature = 0 ; // Raw temp reading
#define RX_UART_BUFFER_SIZE 32
struct t_rxUartBuffer
{
uint8_t fifo[RX_UART_BUFFER_SIZE] ;
uint8_t *outPtr ;
} ;
struct t_rxUartBuffer TelemetryInBuffer[2] ;
uint32_t TelemetryActiveBuffer ;
void startPdcUsartReceive()
{
register Usart *pUsart = SECOND_USART;
TelemetryInBuffer[0].outPtr = TelemetryInBuffer[0].fifo ;
TelemetryInBuffer[1].outPtr = TelemetryInBuffer[1].fifo ;
#ifndef SIMU
// TODO because of the 64bits cast ...
pUsart->US_RPR = (uint32_t)TelemetryInBuffer[0].fifo ;
pUsart->US_RNPR = (uint32_t)TelemetryInBuffer[1].fifo ;
#endif
pUsart->US_RCR = RX_UART_BUFFER_SIZE ;
pUsart->US_RNCR = RX_UART_BUFFER_SIZE ;
pUsart->US_PTCR = US_PTCR_RXTEN ;
TelemetryActiveBuffer = 0 ;
}
void endPdcUsartReceive()
{
register Usart *pUsart = SECOND_USART;
pUsart->US_PTCR = US_PTCR_RXTDIS ;
}
void rxPdcUsart( void (*pChProcess)(uint8_t x) )
{
#if !defined(SIMU)
register Usart *pUsart = SECOND_USART;
uint8_t *ptr ;
uint8_t *endPtr ;
// uint32_t bufIndex ;
// uint32_t i ;
uint32_t j ;
//Find out where the DMA has got to
__disable_irq() ;
pUsart->US_PTCR = US_PTCR_RXTDIS ; // Freeze DMA
ptr = (uint8_t *)pUsart->US_RPR ;
j = pUsart->US_RNCR ;
pUsart->US_PTCR = US_PTCR_RXTEN ; // DMA active again
__enable_irq() ;
endPtr = ptr - 1 ;
ptr = TelemetryInBuffer[TelemetryActiveBuffer].outPtr ;
if ( j == 0 ) // First buf is full
{
endPtr = &TelemetryInBuffer[TelemetryActiveBuffer].fifo[RX_UART_BUFFER_SIZE-1] ; // last byte
}
while ( ptr <= endPtr )
{
(*pChProcess)(*ptr++) ;
}
TelemetryInBuffer[TelemetryActiveBuffer].outPtr = ptr ;
if ( j == 0 ) // First buf is full
{
TelemetryInBuffer[TelemetryActiveBuffer].outPtr = TelemetryInBuffer[TelemetryActiveBuffer].fifo ;
pUsart->US_RNPR = (uint32_t)TelemetryInBuffer[TelemetryActiveBuffer].fifo ;
pUsart->US_RNCR = RX_UART_BUFFER_SIZE ;
TelemetryActiveBuffer ^= 1 ; // Other buffer is active
rxPdcUsart( pChProcess ) ; // Get any chars from second buffer
}
#endif
}
uint32_t txPdcUsart( uint8_t *buffer, uint32_t size )
{
register Usart *pUsart = SECOND_USART;
if ( pUsart->US_TNCR == 0 )
{
#ifndef SIMU
pUsart->US_TNPR = (uint32_t)buffer ;
#endif
pUsart->US_TNCR = size ;
pUsart->US_PTCR = US_PTCR_TXTEN ;
return 1 ;
}
return 0 ;
}
uint32_t txPdcPending()
{
register Usart *pUsart = SECOND_USART;
uint32_t x ;
__disable_irq() ;
pUsart->US_PTCR = US_PTCR_TXTDIS ; // Freeze DMA
x = pUsart->US_TNCR ; // Total
x += pUsart->US_TCR ; // Still to send
pUsart->US_PTCR = US_PTCR_TXTEN ; // DMA active again
__enable_irq() ;
return x ;
}
void end_bt_tx_interrupt()
{
Uart *pUart = BT_USART ;
@@ -771,45 +635,6 @@ void end_bt_tx_interrupt()
NVIC_DisableIRQ(UART1_IRQn) ;
}
void usbBootloader()
{
// This might be replaced by a software reset
// Any interrupts that have been enabled must be disabled here
// BEFORE calling sam_boot()
#if defined(ROTARY_ENCODERS)
rotencEnd();
#endif
endPdcUsartReceive() ; // Terminate any serial reception
end_bt_tx_interrupt() ;
stop_trainer_capture() ;
end_spi() ;
audioEnd() ;
TC0->TC_CHANNEL[2].TC_IDR = TC_IDR0_CPCS ;
TC0->TC_CHANNEL[0].TC_CCR = TC_CCR0_CLKDIS ;
TC0->TC_CHANNEL[1].TC_CCR = TC_CCR0_CLKDIS ;
TC0->TC_CHANNEL[2].TC_CCR = TC_CCR0_CLKDIS ;
TC1->TC_CHANNEL[0].TC_CCR = TC_CCR0_CLKDIS ;
TC1->TC_CHANNEL[1].TC_CCR = TC_CCR0_CLKDIS ;
TC1->TC_CHANNEL[2].TC_CCR = TC_CCR0_CLKDIS ;
PWM->PWM_DIS = PWM_DIS_CHID0 | PWM_DIS_CHID1 | PWM_DIS_CHID2 | PWM_DIS_CHID3 ; // Disable all
NVIC_DisableIRQ(TC2_IRQn) ;
disable_ppm(0);
disable_ppm(1);
// PWM->PWM_IDR1 = PWM_IDR1_CHID3 ;
// NVIC_DisableIRQ(PWM_IRQn) ;
disable_ssc() ;
#if !defined(SIMU)
DEBUG_UART_Stop();
UART3_Stop();
#endif
sam_boot() ;
}
#if !defined(REVA)
uint16_t getCurrent()
{
+190
View File
@@ -0,0 +1,190 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "../../opentx.h"
#define RX_UART_BUFFER_SIZE 32
struct t_rxUartBuffer
{
uint8_t fifo[RX_UART_BUFFER_SIZE] ;
uint8_t *outPtr ;
};
struct t_rxUartBuffer TelemetryInBuffer[2] ;
uint32_t TelemetryActiveBuffer;
uint16_t DsmRxTimeout;
// USART0 configuration
// Work in Progress, UNTESTED
// Uses PA5 and PA6 (RXD and TXD)
void UART2_Configure(uint32_t baudrate, uint32_t masterClock)
{
register Usart *pUsart = SECOND_USART;
// Configure PIO
configure_pins( (PIO_PA5 | PIO_PA6), PIN_PERIPHERAL | PIN_INPUT | PIN_PER_A | PIN_PORTA | PIN_NO_PULLUP ) ;
// Configure PMC
PMC->PMC_PCER0 = 1 << SECOND_ID;
// Reset and disable receiver & transmitter */
pUsart->US_CR = US_CR_RSTRX | US_CR_RSTTX | US_CR_RXDIS | US_CR_TXDIS;
// Configure mode
pUsart->US_MR = 0x000008C0 ; // NORMAL, No Parity, 8 bit
// Configure baudrate
// Asynchronous, no oversampling
pUsart->US_BRGR = (masterClock / baudrate) / 16;
// Disable PDC channel
pUsart->US_PTCR = US_PTCR_RXTDIS | US_PTCR_TXTDIS;
// Enable receiver and transmitter
pUsart->US_CR = US_CR_RXEN | US_CR_TXEN;
}
void UART2_timeout_enable()
{
register Usart *pUsart = SECOND_USART;
pUsart->US_CR = US_CR_STTTO ;
pUsart->US_RTOR = 115 ; // Bits @ 115200 ~= 1mS
pUsart->US_IER = US_IER_TIMEOUT ;
DsmRxTimeout = 0 ;
NVIC_EnableIRQ(USART0_IRQn);
}
void UART2_timeout_disable()
{
register Usart *pUsart = SECOND_USART;
pUsart->US_RTOR = 0 ;
pUsart->US_IDR = US_IDR_TIMEOUT ;
NVIC_DisableIRQ(USART0_IRQn);
}
extern "C" void USART0_IRQHandler()
{
register Usart *pUsart = SECOND_USART;
pUsart->US_CR = US_CR_STTTO ; // Clears timeout bit
DsmRxTimeout = 1;
}
void startPdcUsartReceive()
{
register Usart *pUsart = SECOND_USART;
TelemetryInBuffer[0].outPtr = TelemetryInBuffer[0].fifo ;
TelemetryInBuffer[1].outPtr = TelemetryInBuffer[1].fifo ;
#ifndef SIMU
// TODO because of the 64bits cast ...
pUsart->US_RPR = (uint32_t)TelemetryInBuffer[0].fifo ;
pUsart->US_RNPR = (uint32_t)TelemetryInBuffer[1].fifo ;
#endif
pUsart->US_RCR = RX_UART_BUFFER_SIZE ;
pUsart->US_RNCR = RX_UART_BUFFER_SIZE ;
pUsart->US_PTCR = US_PTCR_RXTEN ;
TelemetryActiveBuffer = 0 ;
}
void rxPdcUsart( void (*pChProcess)(uint8_t x) )
{
#if !defined(SIMU)
register Usart *pUsart = SECOND_USART;
uint8_t *ptr ;
uint8_t *endPtr ;
uint32_t j ;
// Find out where the DMA has got to
__disable_irq() ;
pUsart->US_PTCR = US_PTCR_RXTDIS ; // Freeze DMA
ptr = (uint8_t *)pUsart->US_RPR ;
j = pUsart->US_RNCR ;
pUsart->US_PTCR = US_PTCR_RXTEN ; // DMA active again
__enable_irq() ;
endPtr = ptr - 1 ;
ptr = TelemetryInBuffer[TelemetryActiveBuffer].outPtr ;
if ( j == 0 ) // First buf is full
{
endPtr = &TelemetryInBuffer[TelemetryActiveBuffer].fifo[RX_UART_BUFFER_SIZE-1] ; // last byte
}
while ( ptr <= endPtr )
{
(*pChProcess)(*ptr++) ;
}
TelemetryInBuffer[TelemetryActiveBuffer].outPtr = ptr ;
if ( j == 0 ) // First buf is full
{
TelemetryInBuffer[TelemetryActiveBuffer].outPtr = TelemetryInBuffer[TelemetryActiveBuffer].fifo ;
pUsart->US_RNPR = (uint32_t)TelemetryInBuffer[TelemetryActiveBuffer].fifo ;
pUsart->US_RNCR = RX_UART_BUFFER_SIZE ;
TelemetryActiveBuffer ^= 1 ; // Other buffer is active
rxPdcUsart( pChProcess ) ; // Get any chars from second buffer
}
#endif
}
uint32_t txPdcUsart( uint8_t *buffer, uint32_t size )
{
register Usart *pUsart = SECOND_USART;
if ( pUsart->US_TNCR == 0 )
{
#ifndef SIMU
pUsart->US_TNPR = (uint32_t)buffer ;
#endif
pUsart->US_TNCR = size ;
pUsart->US_PTCR = US_PTCR_TXTEN ;
return 1 ;
}
return 0 ;
}
uint32_t txPdcPending()
{
register Usart *pUsart = SECOND_USART;
uint32_t x ;
__disable_irq() ;
pUsart->US_PTCR = US_PTCR_TXTDIS ; // Freeze DMA
x = pUsart->US_TNCR ; // Total
x += pUsart->US_TCR ; // Still to send
pUsart->US_PTCR = US_PTCR_TXTEN ; // DMA active again
__enable_irq() ;
return x ;
}
+1 -5
View File
@@ -820,11 +820,7 @@ void FRSKY_Init(void)
// clear frsky variables
resetTelemetry();
#if defined(PCBTARANIS)
// TODO
#elif defined(PCBSKY9X)
startPdcUsartReceive() ;
#elif !defined(SIMU)
#if !defined(CPUARM) && !defined(SIMU)
DDRE &= ~(1 << DDE0); // set RXD0 pin as input
PORTE &= ~(1 << PORTE0); // disable pullup on RXD0 pin
+5
View File
@@ -541,9 +541,11 @@ void processSerialData(uint8_t data)
btPushByte(data);
#endif
#if defined(PCBTARANIS)
if (g_eeGeneral.uart3Mode == UART_MODE_SPORT) {
uart3Putc(data);
}
#endif
if (data == START_STOP) {
dataState = STATE_DATA_IN_FRAME;
@@ -676,11 +678,14 @@ void telemetryWakeup()
alarmsCheckTime = get_tmr10ms() + 100; /* next check in 1second */
if (alarmsCheckStep == 0) {
#if defined(PCBTARANIS)
// TODO not only Taranis!
if ((IS_MODULE_XJT(0) || IS_MODULE_XJT(1)) && frskyData.swr.value > 0x33) {
AUDIO_SWR_RED();
POPUP_WARNING(STR_ANTENNAPROBLEM);
alarmsCheckTime = get_tmr10ms() + 300; /* next check in 3seconds */
}
#endif
}
else if (TELEMETRY_STREAMING()) {
if (alarmsCheckStep == 1) {