Telemetry refactoring

This commit is contained in:
bsongis
2014-05-15 18:07:52 +02:00
parent 7b1f11398d
commit b376192b61
32 changed files with 1526 additions and 1635 deletions
+39
View File
@@ -0,0 +1,39 @@
/*
* 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.
*
*/
// Telemetry driver
void telemetryPortInit();
void telemetryTransmitBuffer();
@@ -0,0 +1,142 @@
/*
* 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"
#if defined(FRSKY)
void telemetryEnableTx(void)
{
UCSR0B |= (1 << TXEN0); // enable TX
}
void telemetryEnableRx(void)
{
UCSR0B |= (1 << RXEN0); // enable RX
UCSR0B |= (1 << RXCIE0); // enable Interrupt
}
void processSerialData(uint8_t data);
extern uint8_t numPktBytes; // TODO not driver, change name
ISR(USART0_RX_vect)
{
uint8_t stat;
uint8_t data;
UCSR0B &= ~(1 << RXCIE0); // disable Interrupt
sei();
stat = UCSR0A; // USART control and Status Register 0 A
/*
bit 7 6 5 4 3 2 1 0
RxC0 TxC0 UDRE0 FE0 DOR0 UPE0 U2X0 MPCM0
RxC0: Receive complete
TXC0: Transmit Complete
UDRE0: USART Data Register Empty
FE0: Frame Error
DOR0: Data OverRun
UPE0: USART Parity Error
U2X0: Double Tx Speed
PCM0: MultiProcessor Comms Mode
*/
// rh = UCSR0B; //USART control and Status Register 0 B
/*
bit 7 6 5 4 3 2 1 0
RXCIE0 TxCIE0 UDRIE0 RXEN0 TXEN0 UCSZ02 RXB80 TXB80
RxCIE0: Receive Complete int enable
TXCIE0: Transmit Complete int enable
UDRIE0: USART Data Register Empty int enable
RXEN0: Rx Enable
TXEN0: Tx Enable
UCSZ02: Character Size bit 2
RXB80: Rx data bit 8
TXB80: Tx data bit 8
*/
data = UDR0; // USART data register 0
if (stat & ((1 << FE0) | (1 << DOR0) | (1 << UPE0))) {
// discard buffer and start fresh on any comms error
numPktBytes = 0;
}
else {
processSerialData(data);
}
cli() ;
UCSR0B |= (1 << RXCIE0); // enable Interrupt
}
void telemetryPortInit()
{
#if !defined(SIMU)
DDRE &= ~(1 << DDE0); // set RXD0 pin as input
PORTE &= ~(1 << PORTE0); // disable pullup on RXD0 pin
#undef BAUD
#define BAUD 9600
#include <util/setbaud.h>
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
UCSR0A &= ~(1 << U2X0); // disable double speed operation.
// set 8N1
UCSR0B = 0 | (0 << RXCIE0) | (0 << TXCIE0) | (0 << UDRIE0) | (0 << RXEN0) | (0 << TXEN0) | (0 << UCSZ02);
UCSR0C = 0 | (1 << UCSZ01) | (1 << UCSZ00);
while (UCSR0A & (1 << RXC0)) UDR0; // flush receive buffer
// These should be running right from power up on a FrSky enabled '9X.
telemetryEnableTx(); // enable FrSky-Telemetry emission
frskyTxBufferCount = 0; // TODO not driver code
telemetryEnableRx(); // enable FrSky-Telemetry reception
#endif
}
void telemetryTransmitBuffer()
{
UCSR0B |= (1 << UDRIE0); // enable UDRE0 interrupt
}
#endif
@@ -37,6 +37,8 @@
#ifndef board_gruvin9x_h
#define board_gruvin9x_h
#include "../common_avr/board_avr.h"
#define GPIO_BUTTON_MENU pinl
#define GPIO_BUTTON_EXIT pinl
#define GPIO_BUTTON_RIGHT pinl
@@ -37,6 +37,8 @@
#ifndef board_mega2560_h
#define board_mega2560_h
#include "../common_avr/board_avr.h"
#define GPIO_BUTTON_MENU pinl
#define GPIO_BUTTON_EXIT pinl
#define GPIO_BUTTON_RIGHT pinl
-12
View File
@@ -59,15 +59,6 @@ volatile uint32_t lcdInputs;
/** Pins description corresponding to Rxd,Txd, (UART pins) */
#define CONSOLE_PINS {PINS_UART}
/** Second serial baudrate 9600. */
#define SECOND_BAUDRATE 9600
/** Usart Hw interface used by the console (UART0). */
#define SECOND_USART USART0
/** Usart Hw ID used by the console (UART0). */
#define SECOND_ID ID_USART0
/** Pins description corresponding to Rxd,Txd, (UART pins) */
#define SECOND_PINS {PINS_USART0}
extern "C" void sam_boot( void ) ;
// Prototype
@@ -619,9 +610,6 @@ void boardInit()
#endif
init_SDcard();
UART2_Configure(9600, Master_frequency);
startPdcUsartReceive();
}
#endif
+8 -2
View File
@@ -147,6 +147,11 @@ void usbMassStorage();
#define PIN_LOW 0x000
#define PIN_HIGH 0x100
// Telemetry port
#define SECOND_USART USART0
#define SECOND_ID ID_USART0
#define SECOND_PINS {PINS_USART0}
void configure_pins( uint32_t pins, uint16_t config );
uint16_t getCurrent();
@@ -285,7 +290,8 @@ void rotencEnd();
void debugPutc(const char c);
// Telemetry driver
void UART2_Configure(uint32_t baudrate, uint32_t masterClock);
void startPdcUsartReceive();
void telemetryPortInit(uint32_t baudrate);
uint32_t telemetryTransmitPending();
void telemetryTransmitBuffer(uint8_t * buffer, uint32_t size);
#endif
+14 -3
View File
@@ -117,7 +117,7 @@ void startPdcUsartReceive()
pUsart->US_RCR = RX_UART_BUFFER_SIZE ;
pUsart->US_RNCR = RX_UART_BUFFER_SIZE ;
pUsart->US_PTCR = US_PTCR_RXTEN ;
TelemetryActiveBuffer = 0 ;
TelemetryActiveBuffer = 0;
}
void rxPdcUsart( void (*pChProcess)(uint8_t x) )
@@ -158,7 +158,7 @@ void rxPdcUsart( void (*pChProcess)(uint8_t x) )
#endif
}
uint32_t txPdcUsart( uint8_t *buffer, uint32_t size )
uint32_t txPdcUsart(uint8_t *buffer, uint32_t size)
{
register Usart *pUsart = SECOND_USART;
@@ -174,7 +174,7 @@ uint32_t txPdcUsart( uint8_t *buffer, uint32_t size )
return 0 ;
}
uint32_t txPdcPending()
uint32_t telemetryTransmitPending()
{
register Usart *pUsart = SECOND_USART;
uint32_t x ;
@@ -188,3 +188,14 @@ uint32_t txPdcPending()
return x ;
}
void telemetryPortInit(uint32_t baudrate)
{
UART2_Configure(baudrate, Master_frequency);
startPdcUsartReceive();
}
void telemetryTransmitBuffer(uint8_t * buffer, uint32_t size)
{
txPdcUsart(buffer, size);
}
+2
View File
@@ -37,6 +37,8 @@
#ifndef board_stock_h
#define board_stock_h
#include "../common_avr/board_avr.h"
#define GPIO_BUTTON_MENU pinb
#define GPIO_BUTTON_EXIT pinb
#define GPIO_BUTTON_RIGHT pinb
@@ -157,7 +157,6 @@ void boardInit()
init5msTimer();
__enable_irq();
eepromInit();
sportInit();
usbInit();
#if defined(HAPTIC)
+3 -3
View File
@@ -114,13 +114,10 @@ extern uint16_t sessionTimer;
void delaysInit(void);
#define DEBUG_BAUDRATE 115200
#define SPORT_BAUDRATE 57600
void uart3Init(unsigned int mode);
void uart3Putc(const char c);
void sportInit(void);
void delaysInit(void);
void delay_01us(uint16_t nb);
@@ -246,6 +243,9 @@ void eeWriteBlockCmp(const void *pointer_ram, uint16_t pointer_eeprom, size_t si
// Debug driver
void debugPutc(const char c);
// Telemetry driver
void telemetryPortInit(uint32_t baudrate);
// Haptic driver
void hapticInit(void);
void hapticOff(void);
@@ -38,7 +38,7 @@
extern Fifo<512> telemetryFifo;
void sportInit(void)
void telemetryPortInit(uint32_t baudrate)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
@@ -66,7 +66,7 @@ void sportInit(void)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPORT, ENABLE);
USART_InitStructure.USART_BaudRate = SPORT_BAUDRATE;
USART_InitStructure.USART_BaudRate = baudrate;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
@@ -81,7 +81,7 @@ void sportInit(void)
NVIC_SetPriority(USART2_IRQn, 6);
}
void sportPutc(const char c)
void telemetryPutc(const char c)
{
GPIO_SetBits(GPIO_PIN_SPORT_ON, PIN_SPORT_ON);
USART_SendData(SPORT, c);
+1 -1
View File
@@ -78,7 +78,7 @@ void uart3Init(unsigned int mode)
switch(mode) {
case UART_MODE_SPORT:
uart3Setup(SPORT_BAUDRATE);
uart3Setup(FRSKY_SPORT_BAUDRATE);
break;
#if defined(DEBUG)
case UART_MODE_DEBUG: