XMEGA /STM32 cleaning add layer

This commit is contained in:
midelic 2016-09-02 22:08:09 +01:00 committed by GitHub
parent b661fc014b
commit d279ef7490
5 changed files with 97 additions and 290 deletions

View File

@ -20,26 +20,14 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>. along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define STM32_board
//#undef __cplusplus
#if defined STM32_board
#include "Multiprotocol_STM32.h"
#include <EEPROM.h>
#include <libmaple/usart.h>
#include <libmaple/timer.h>
#include <SPI.h>
uint16_t OCR1A = 0;
uint16_t TCNT1=0;
HardwareTimer timer(2);
#else
#include <avr/eeprom.h>
#include <util/delay.h>
#include "Multiprotocol.h"
#endif
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include "_Config.h" #include "_Config.h"
#include "TX_Def.h" #include "TX_Def.h"
#ifdef STM32_board
HardwareTimer timer(2);
#endif
#ifdef XMEGA #ifdef XMEGA
#undef ENABLE_PPM // Disable PPM for orange module #undef ENABLE_PPM // Disable PPM for orange module
@ -65,9 +53,6 @@ uint16_t Servo_data[NUM_CHN];
uint8_t Servo_AUX; uint8_t Servo_AUX;
uint16_t servo_max_100,servo_min_100,servo_max_125,servo_min_125; uint16_t servo_max_100,servo_min_100,servo_max_125,servo_min_125;
#ifndef STM32_board
uint16_t servo_max_100,servo_min_100,servo_max_125,servo_min_125;
#endif
// Protocol variables // Protocol variables
uint8_t cyrfmfg_id[6];//for dsm2 and devo uint8_t cyrfmfg_id[6];//for dsm2 and devo
uint8_t rx_tx_addr[5]; uint8_t rx_tx_addr[5];
@ -214,7 +199,7 @@ void setup()
start_timer2();//0.5us start_timer2();//0.5us
#else #else
DDRD = (1<<CS_pin)|(1<<SDI_pin)|(1<<SCLK_pin)|(1<<CS_pin)|(1<< CC25_CSN_pin); DDRD = (1<<CS_pin)|(1<<SDI_pin)|(1<<SCLK_pin)|(1<<CS_pin)|(1<< CC25_CSN_pin);
DDRC = (1<<CTRL1)|(1<<CTRL2); //output DDRC = (1<<CTRL1_pin)|(1<<CTRL2_pin); //output
DDRC |= (1<<5);//RST pin A5(C5) CYRF output DDRC |= (1<<5);//RST pin A5(C5) CYRF output
DDRB = _BV(0)|_BV(1); DDRB = _BV(0)|_BV(1);
PORTB = _BV(2)|_BV(3)|_BV(4)|_BV(5);//pullup 10,11,12 and bind button PORTB = _BV(2)|_BV(3)|_BV(4)|_BV(5);//pullup 10,11,12 and bind button
@ -348,16 +333,6 @@ void loop()
} }
while(remote_callback==0); while(remote_callback==0);
} }
#ifdef XMEGA
if( (TCC1.INTFLAGS & TC1_CCAIF_bm) != 0)
{
cli(); // disable global int
TCC1.CCA = TCC1.CNT ; // Callback should already have been called... Use "now" as new sync point.
sei(); // enable global int
}
else
while((TCC1.INTFLAGS & TC1_CCAIF_bm) == 0); // wait before callback
#else
#if defined STM32_board #if defined STM32_board
if((TIMER2_BASE->SR & TIMER_SR_CC1IF)!=0){ if((TIMER2_BASE->SR & TIMER_SR_CC1IF)!=0){
cli(); cli();
@ -368,15 +343,14 @@ void loop()
else else
while((TIMER2_BASE->SR & TIMER_SR_CC1IF )==0);//walit till compare match while((TIMER2_BASE->SR & TIMER_SR_CC1IF )==0);//walit till compare match
#else #else
if( (TIFR1 & (1<<OCF1A)) != 0) if( (TIFR1 & OCF1A_bm) != 0)
{ {
cli(); // disable global int cli(); // disable global int
OCR1A=TCNT1; // Callback should already have been called... Use "now" as new sync point. OCR1A=TCNT1; // Callback should already have been called... Use "now" as new sync point.
sei(); // enable global int sei(); // enable global int
} }
else else
while((TIFR1 & (1<<OCF1A)) == 0); // wait before callback while((TIFR1 & OCF1A_bm) == 0); // wait before callback
#endif
#endif #endif
do do
{ {
@ -394,66 +368,41 @@ void loop()
while(next_callback>4000) while(next_callback>4000)
{ // start to wait here as much as we can... { // start to wait here as much as we can...
next_callback-=2000; next_callback-=2000;
#ifdef XMEGA
cli(); // disable global int
TCC1.CCA +=2000*2; // set compare A for callback
TCC1.INTFLAGS = TC1_CCAIF_bm ; // clear compare A=callback flag
sei(); // enable global int
Update_All();
if(IS_CHANGE_PROTOCOL_FLAG_on)
break; // Protocol has been changed
while((TCC1.INTFLAGS & TC1_CCAIF_bm) == 0); // wait 2ms...
#else
#if defined STM32_board #if defined STM32_board
cli(); cli();
OCR1A+=2000*2;// clear compare A=callback flag OCR1A+=2000*2;// clear compare A=callback flag
TIMER2_BASE->CCR1=OCR1A;
TCNT1 = TIMER2_BASE->CNT;
TIMER2_BASE->SR &= ~TIMER_SR_CC1IF; //clear compare Flag TIMER2_BASE->SR &= ~TIMER_SR_CC1IF; //clear compare Flag
sei(); sei();
Update_All(); Update_All();
if(IS_CHANGE_PROTOCOL_FLAG_on) if(IS_CHANGE_PROTOCOL_FLAG_on)
break; // Protocol has been changed break; // Protocol has been changed
while((TIMER2_BASE->SR &TIMER_SR_CC1IF)==0);//2ms wait while((TIMER2_BASE->SR & TIMER_SR_CC1IF)==0);//2ms wait
#else #else
cli(); cli();
OCR1A+=2000*2; // clear compare A=callback flag OCR1A+=2000*2; // clear compare A=callback flag
TIFR1=(1<<OCF1A); // clear compare A=callback flag TIFR1=OCF1A_bm; // clear compare A=callback flag
sei(); // enable global int sei(); // enable global int
Update_All(); Update_All();
if(IS_CHANGE_PROTOCOL_FLAG_on) if(IS_CHANGE_PROTOCOL_FLAG_on)
break; // Protocol has been changed break; // Protocol has been changed
while((TIFR1 & (1<<OCF1A)) == 0); // wait 2ms... while((TIFR1 & OCF1A_bm) == 0); // wait 2ms...
#endif
#endif #endif
} }
// at this point we have between 2ms and 4ms in next_callback // at this point we have between 2ms and 4ms in next_callback
next_callback *= 2 ; // disable global int next_callback *= 2 ; // disable global int
#ifdef XMEGA
cli();
TCC1.CCA +=next_callback; // set compare A for callback
TCC1.INTFLAGS = TC1_CCAIF_bm ; // clear compare A=callback flag
diff=TCC1.CCA-TCC1.CNT; // compare timer and comparator
sei();// enable global int
#else
#if defined STM32_board #if defined STM32_board
OCR1A+=next_callback;
cli(); cli();
TIMER2_BASE->CCR1 = OCR1A; OCR1A+=next_callback;
TCNT1 = TIMER2_BASE->CNT;
TIMER2_BASE->SR &= ~TIMER_SR_CC1IF;//clear compare Flag write zero TIMER2_BASE->SR &= ~TIMER_SR_CC1IF;//clear compare Flag write zero
diff=OCR1A-TCNT1; // compare timer and comparator diff=OCR1A-TCNT1; // compare timer and comparator
sei(); sei();
#else #else
cli(); cli();
OCR1A+=next_callback; // set compare A for callback OCR1A+=next_callback; // set compare A for callback
TIFR1=(1<<OCF1A); // clear compare A=callback flag TIFR1=OCF1A_bm; // clear compare A=callback flag
diff=OCR1A-TCNT1; // compare timer and comparator diff=OCR1A-TCNT1; // compare timer and comparator
sei(); // enable global int sei(); // enable global int
#endif #endif
#endif
} }
while(diff&0x8000); // Callback did not took more than requested time for next callback while(diff&0x8000); // Callback did not took more than requested time for next callback
// so we can launch Update_All before next callback // so we can launch Update_All before next callback
@ -463,12 +412,6 @@ void loop()
void Update_All() void Update_All()
{ {
#ifndef STM32_board
TX_ON;
NOP();
TX_OFF;
#endif
#ifdef ENABLE_SERIAL #ifdef ENABLE_SERIAL
if(mode_select==MODE_SERIAL && IS_RX_FLAG_on) // Serial mode and something has been received if(mode_select==MODE_SERIAL && IS_RX_FLAG_on) // Serial mode and something has been received
{ {
@ -505,11 +448,6 @@ void Update_All()
if( (protocol==MODE_FRSKY) || (protocol==MODE_HUBSAN) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM2) ) if( (protocol==MODE_FRSKY) || (protocol==MODE_HUBSAN) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM2) )
TelemetryUpdate(); TelemetryUpdate();
#endif #endif
#ifndef STM32_board
TX_ON;
NOP();
TX_OFF;
#endif
} }
@ -596,103 +534,7 @@ void start_timer2(){
timer.resume(); timer.resume();
} }
#endif #endif
/*
// Protocol scheduler
static void CheckTimer(uint16_t (*cb)(void))
{
uint16_t next_callback,diff;
#ifdef XMEGA
if( (TCC1.INTFLAGS & TC1_CCAIF_bm) != 0)
{
cli(); // disable global int
TCC1.CCA = TCC1.CNT ; // Callback should already have been called... Use "now" as new sync point.
sei(); // enable global int
}
else
while((TCC1.INTFLAGS & TC1_CCAIF_bm) == 0); // wait before callback
#else
#if defined STM32_board
if((TIMER2_BASE->SR & TIMER_SR_CC1IF)!=0){
cli();
OCR1A = TIMER2_BASE->CNT;
TIMER2_BASE->CCR1=OCR1A;
sei();
}
else
while((TIMER2_BASE->SR & TIMER_SR_CC1IF )==0);//walit till compare match
#else
if( (TIFR1 & (1<<OCF1A)) != 0)
{
cli(); // disable global int
OCR1A=TCNT1; // Callback should already have been called... Use "now" as new sync point.
sei(); // enable global int
}
else
while((TIFR1 & (1<<OCF1A)) == 0); // wait before callback
#endif
#endif
do
{
next_callback=cb();
while(next_callback>4000)
{ // start to wait here as much as we can...
next_callback=next_callback-2000;
#ifdef XMEGA
cli(); // disable global int
TCC1.CCA +=2000*2; // set compare A for callback
TCC1.INTFLAGS = TC1_CCAIF_bm ; // clear compare A=callback flag
sei(); // enable global int
while((TCC1.INTFLAGS & TC1_CCAIF_bm) == 0); // wait 2ms...
#else
#if defined STM32_board
cli();
OCR1A+=2000*2;// clear compare A=callback flag
TIMER2_BASE->CCR1=OCR1A;
TCNT1 = TIMER2_BASE->CNT;
TIMER2_BASE->SR &= ~TIMER_SR_CC1IF; //clear compare Flag
sei();
while((TIMER2_BASE->SR &TIMER_SR_CC1IF)==0);//2ms wait
#else
cli();
OCR1A+=2000*2; // clear compare A=callback flag
TIFR1=(1<<OCF1A); // clear compare A=callback flag
sei(); // enable global int
while((TIFR1 & (1<<OCF1A)) == 0); // wait 2ms...
#endif
#endif
}
// at this point we have between 2ms and 4ms in next_callback
next_callback *= 2 ; // disable global int
#ifdef XMEGA
cli();
TCC1.CCA +=next_callback; // set compare A for callback
TCC1.INTFLAGS = TC1_CCAIF_bm ; // clear compare A=callback flag
diff=TCC1.CCA-TCC1.CNT; // compare timer and comparator
sei();// enable global int
#else
#if defined STM32_board
OCR1A+=next_callback;
cli();
TIMER2_BASE->CCR1 = OCR1A;
TCNT1 = TIMER2_BASE->CNT;
TIMER2_BASE->SR &= ~TIMER_SR_CC1IF;//clear compare Flag write zero
diff=OCR1A-TCNT1; // compare timer and comparator
sei();
#else
cli();
OCR1A+=next_callback; // set compare A for callback
TIFR1=(1<<OCF1A); // clear compare A=callback flag
diff=OCR1A-TCNT1; // compare timer and comparator
sei(); // enable global int
#endif
#endif
}
while(diff&0x8000); // Callback did not took more than requested time for next callback
// so we can let main do its stuff before next callback
}
*/
// Protocol start // Protocol start
static void protocol_init() static void protocol_init()
{ {
@ -749,6 +591,14 @@ static void protocol_init()
remote_callback = ReadFrSky_2way; remote_callback = ReadFrSky_2way;
break; break;
#endif #endif
#if defined(FRSKY1_CC2500_INO)
case MODE_FRSKY1:
CTRL1_off; //antenna RF2
CTRL2_on;
next_callback = initFRSKY1();
remote_callback = ReadFRSKY1;
break;
#endif
#if defined(FRSKYX_CC2500_INO) #if defined(FRSKYX_CC2500_INO)
case MODE_FRSKYX: case MODE_FRSKYX:
CTRL1_off; //antenna RF2 CTRL1_off; //antenna RF2
@ -912,29 +762,20 @@ static void protocol_init()
if(next_callback>32000) if(next_callback>32000)
{ // next_callback should not be more than 32767 so we will wait here... { // next_callback should not be more than 32767 so we will wait here...
uint16_t temp=(next_callback>>10)-2; uint16_t temp=(next_callback>>10)-2;
delay(temp); delayMilliseconds(temp);
next_callback-=temp<<10; // between 2-3ms left at this stage next_callback-=temp<<10; // between 2-3ms left at this stage
} }
#ifdef XMEGA
cli(); // disable global int
TCC1.CCA = TCC1.CNT + next_callback*2; // set compare A for callback
sei(); // enable global int
TCC1.INTFLAGS = TC1_CCAIF_bm ; // clear compare A flag
#else
#if defined STM32_board #if defined STM32_board
cli(); // disable global int cli(); // disable global int
TCNT1 = TIMER2_BASE->CNT;
OCR1A=TCNT1+next_callback*2; OCR1A=TCNT1+next_callback*2;
TIMER2_BASE->CCR1 = OCR1A;
sei(); sei();
TIMER2_BASE->SR &= ~TIMER_SR_CC1IF;//clear compare Flag write zero TIMER2_BASE->SR &= ~TIMER_SR_CC1IF;//clear compare Flag write zero
#else #else
cli(); // disable global int cli(); // disable global int
OCR1A=TCNT1+next_callback*2; // set compare A for callback OCR1A = TCNT1 + next_callback*2; // set compare A for callback
sei(); // enable global int sei(); // enable global int
TIFR1=(1<<OCF1A); // clear compare A flag TIFR1 = OCF1A_bm ; // clear compare A flag
#endif
#endif #endif
BIND_BUTTON_FLAG_off; // do not bind/reset id anymore even if protocol change BIND_BUTTON_FLAG_off; // do not bind/reset id anymore even if protocol change
} }
@ -971,6 +812,7 @@ static void update_serial_data()
if( ((rx_ok_buff[0]&0x80)!=0) && ((cur_protocol[0]&0x80)==0) ) // Bind flag has been set if( ((rx_ok_buff[0]&0x80)!=0) && ((cur_protocol[0]&0x80)==0) ) // Bind flag has been set
CHANGE_PROTOCOL_FLAG_on; //restart protocol with bind CHANGE_PROTOCOL_FLAG_on; //restart protocol with bind
else else
CHANGE_PROTOCOL_FLAG_off; //no need to restart
cur_protocol[0] = rx_ok_buff[0]; //store current protocol cur_protocol[0] = rx_ok_buff[0]; //store current protocol
// decode channel values // decode channel values
@ -992,13 +834,8 @@ static void update_serial_data()
#ifdef XMEGA #ifdef XMEGA
cli(); cli();
#else #else
#ifdef STM32_board
//here code fro RX intrurpt disable
USART3_BASE->CR1 &= ~ USART_CR1_RXNEIE;//disable
#else
UCSR0B &= ~(1<<RXCIE0); // RX interrupt disable UCSR0B &= ~(1<<RXCIE0); // RX interrupt disable
#endif #endif
#endif
if(IS_RX_MISSED_BUFF_on) // If the buffer is still valid if(IS_RX_MISSED_BUFF_on) // If the buffer is still valid
{ memcpy((void*)rx_ok_buff,(const void*)rx_buff,RXBUFFER_SIZE);// Duplicate the buffer { memcpy((void*)rx_ok_buff,(const void*)rx_buff,RXBUFFER_SIZE);// Duplicate the buffer
RX_FLAG_on; // data to be processed next time... RX_FLAG_on; // data to be processed next time...
@ -1007,13 +844,8 @@ static void update_serial_data()
#ifdef XMEGA #ifdef XMEGA
sei(); sei();
#else #else
#ifdef STM32_board
//here code fro RX intrurpt enable
USART3_BASE->CR1 |= USART_CR1_RXNEIE ;//disable
#else
UCSR0B |= (1<<RXCIE0) ; // RX interrupt enable UCSR0B |= (1<<RXCIE0) ; // RX interrupt enable
#endif #endif
#endif
} }
void modules_reset() void modules_reset()
@ -1099,9 +931,6 @@ uint16_t limit_channel_100(uint8_t ch)
return Servo_data[ch]; return Servo_data[ch];
} }
// void Serial_write(uint8_t data){
// return;
// }
static void Mprotocol_serial_init() static void Mprotocol_serial_init()
{ {
@ -1117,7 +946,10 @@ static void Mprotocol_serial_init()
USARTC0.CTRLB = 0x18 ; USARTC0.CTRLB = 0x18 ;
USARTC0.CTRLA = (USARTC0.CTRLA & 0xCF) | 0x10 ; USARTC0.CTRLA = (USARTC0.CTRLA & 0xCF) | 0x10 ;
USARTC0.CTRLC = 0x2B ; USARTC0.CTRLC = 0x2B ;
USARTC0.DATA ; UDR0 ;
#ifdef INVERT_TELEMETRY
PORTC.PIN3CTRL |= 0x40 ;
#endif
#else #else
#if defined STM32_board #if defined STM32_board
@ -1137,13 +969,11 @@ static void Mprotocol_serial_init()
UDR0; UDR0;
//enable reception and RC complete interrupt //enable reception and RC complete interrupt
UCSR0B = (1<<RXEN0)|(1<<RXCIE0);//rx enable and interrupt UCSR0B = (1<<RXEN0)|(1<<RXCIE0);//rx enable and interrupt
#ifdef DEBUG_TX #ifndef DEBUG_TX
TX_SET_OUTPUT;
#else
#if defined(TELEMETRY) #if defined(TELEMETRY)
initTXSerial( SPEED_100K ) ; initTXSerial( SPEED_100K ) ;
#endif //TELEMETRY #endif //TELEMETRY
#endif #endif //DEBUG_TX
#endif #endif
#endif #endif
} }
@ -1350,7 +1180,7 @@ ISR(PORTD_INT0_vect)
#ifdef STM32_board #ifdef STM32_board
void PPM_decode() void PPM_decode()
#else #else
ISR(INT1_vect) ISR(INT1_vect,ISR_NOBLOCK)
#endif #endif
#endif #endif
{ // Interrupt on PPM pin { // Interrupt on PPM pin
@ -1358,16 +1188,8 @@ ISR(INT1_vect)
static uint16_t Prev_TCNT1=0; static uint16_t Prev_TCNT1=0;
uint16_t Cur_TCNT1; uint16_t Cur_TCNT1;
#ifdef XMEGA
Cur_TCNT1 = TCC1.CNT - Prev_TCNT1 ; // Capture current Timer1 value
#else
#if defined STM32_board
uint16_t time=TIMER2_BASE->CNT;
Cur_TCNT1=time-Prev_TCNT1; // Capture current Timer1 value
#else
Cur_TCNT1=TCNT1-Prev_TCNT1; // Capture current Timer1 value Cur_TCNT1=TCNT1-Prev_TCNT1; // Capture current Timer1 value
#endif
#endif
if(Cur_TCNT1<1000) if(Cur_TCNT1<1000)
chan=-1; // bad frame chan=-1; // bad frame
else else
@ -1409,9 +1231,7 @@ extern "C" {
#ifdef XMEGA #ifdef XMEGA
if((USARTC0.STATUS & 0x1C)==0) // Check frame error, data overrun and parity error if((USARTC0.STATUS & 0x1C)==0) // Check frame error, data overrun and parity error
#else #else
#ifndef STM32_board
UCSR0B &= ~_BV(RXCIE0) ; // RX interrupt disable UCSR0B &= ~_BV(RXCIE0) ; // RX interrupt disable
#endif
sei(); sei();
#if defined STM32_board #if defined STM32_board
if(USART2_BASE->SR & USART_SR_RXNE) { if(USART2_BASE->SR & USART_SR_RXNE) {
@ -1424,33 +1244,17 @@ extern "C" {
if(idx==0||discard_frame==1) if(idx==0||discard_frame==1)
{ // Let's try to sync at this point { // Let's try to sync at this point
idx=0;discard_frame=0; idx=0;discard_frame=0;
#ifdef XMEGA
if(USARTC0.DATA==0x55) // If 1st byte is 0x55 it looks ok
#else
#if defined STM32_board
if(USART2_BASE->DR==0x55)
#else
if(UDR0==0x55) // If 1st byte is 0x55 it looks ok if(UDR0==0x55) // If 1st byte is 0x55 it looks ok
#endif
#endif
{ {
#ifdef XMEGA
TCC1.CCB = TCC1.CNT+(6500L) ; // Full message should be received within timer of 3250us
TCC1.INTFLAGS = TC1_CCBIF_bm ; // clear OCR1B match flag
TCC1.INTCTRLB = (TCC1.INTCTRLB & 0xF3) | 0x04 ; // enable interrupt on compare B match
#else
#if defined STM32_board #if defined STM32_board
uint16_t OCR1B = TIMER2_BASE->CNT; uint16_t OCR1B;
OCR1B +=6500L; OCR1B =TCNT1+6500L;
timer.setCompare(TIMER_CH2,OCR1B); timer.setCompare(TIMER_CH2,OCR1B);
timer.attachCompare2Interrupt(ISR_COMPB); timer.attachCompare2Interrupt(ISR_COMPB);
#else #else
OCR1B=TCNT1+6500L; // Full message should be received within timer of 3250us OCR1B=TCNT1+6500L; // Full message should be received within timer of 3250us
TIFR1=(1<<OCF1B); // clear OCR1B match flag TIFR1 = OCF1B_bm ; // clear OCR1B match flag
TIMSK1 |=(1<<OCIE1B); // enable interrupt on compare B match SET_TIMSK1_OCIE1B ; // enable interrupt on compare B match
#endif
#endif #endif
idx++; idx++;
} }
@ -1458,17 +1262,7 @@ extern "C" {
else else
{ {
RX_MISSED_BUFF_off; // if rx_buff was good it's not anymore... RX_MISSED_BUFF_off; // if rx_buff was good it's not anymore...
#ifdef XMEGA
rx_buff[(idx++)-1]=USARTC0.DATA; // Store received byte
#else
#if defined STM32_board
rx_buff[(idx++)-1]=USART2_BASE->DR&0xff; // Store received byte
#else
rx_buff[(idx++)-1]=UDR0; // Store received byte rx_buff[(idx++)-1]=UDR0; // Store received byte
#endif
#endif
if(idx>RXBUFFER_SIZE) if(idx>RXBUFFER_SIZE)
{ // A full frame has been received { // A full frame has been received
@ -1485,40 +1279,24 @@ extern "C" {
} }
else else
{ {
#ifdef XMEGA
idx = USARTC0.DATA ; // Dummy read
#else
#if defined STM32_board
idx=USART2_BASE->DR&0xff;
#else
idx=UDR0; // Dummy read idx=UDR0; // Dummy read
#endif
#endif
discard_frame=1; // Error encountered discard full frame... discard_frame=1; // Error encountered discard full frame...
} }
if(discard_frame==1) if(discard_frame==1)
{ {
#ifdef XMEGA
TCC1.INTCTRLB &=0xF3; // disable interrupt on compare B match
#else
#if defined STM32_board #if defined STM32_board
detachInterrupt(2);//disable interrupt on ch2 detachInterrupt(2);//disable interrupt on ch2
#else #else
TIMSK1 &=~(1<<OCIE1B); // disable interrupt on compare B match CLR_TIMSK1_OCIE1B; // Disable interrupt on compare B match
#endif
#endif
#ifndef STM32_board
#ifndef XMEGA
TX_RX_PAUSE_off; TX_RX_PAUSE_off;
tx_resume(); tx_resume();
#endif #endif
#endif
} }
#ifndef STM32_board)
#ifndef XMEGA
cli() ; cli() ;
UCSR0B |= _BV(RXCIE0) ; // RX interrupt enable UCSR0B |= _BV(RXCIE0) ; // RX interrupt enable
#endif #endif
#if defined STM32_board //If activated telemetry it doesn't work activated #if defined STM32_board //If activated telemetry it doesn't work activated
} }
@ -1543,14 +1321,10 @@ ISR(TIMER1_COMPB_vect,ISR_NOBLOCK)
{ // Timer1 compare B interrupt { // Timer1 compare B interrupt
discard_frame=1; // Error encountered discard full frame... discard_frame=1; // Error encountered discard full frame...
#ifdef XMEGA
TCC1.INTCTRLB &=0xF3; // Disable interrupt on compare B match
#else
#ifdef STM32_board #ifdef STM32_board
detachInterrupt(2);//disable interrupt on ch2 detachInterrupt(2);//disable interrupt on ch2
#else #else
TIMSK1 &=~(1<<OCIE1B); // Disable interrupt on compare B match CLR_TIMSK1_OCIE1B; // Disable interrupt on compare B match
#endif
#endif #endif
#ifndef STM32_board #ifndef STM32_board
tx_resume(); tx_resume();

View File

@ -43,7 +43,8 @@ enum PROTOCOLS
MODE_SFHSS=21, // =>CC2500 MODE_SFHSS=21, // =>CC2500
MODE_J6PRO=22, // =>CYRF6936 MODE_J6PRO=22, // =>CYRF6936
MODE_FQ777=23, // =>NRF24L01 MODE_FQ777=23, // =>NRF24L01
MODE_ASSAN=24 // =>NRF24L01 MODE_ASSAN=24, // =>NRF24L01
MODE_FRSKY1 = 25 // =>CC2500
}; };
enum Flysky enum Flysky
@ -125,13 +126,29 @@ enum FRSKYX
#define AUTOBIND 1 #define AUTOBIND 1
#define NO_AUTOBIND 0 #define NO_AUTOBIND 0
struct PPM_Parameters
{
uint8_t protocol : 5;
uint8_t sub_proto : 3;
uint8_t rx_num : 4;
uint8_t power : 1;
uint8_t autobind : 1;
uint8_t option;
};
//******************* //*******************
//*** Pinouts *** //*** Pinouts ***
//******************* //*******************
#if defined STM32_board #if defined STM32_board
#define OCR1A TIMER2_BASE->CCR1
#define TCNT1 TIMER2_BASE->CNT
#define UDR0 USART2_BASE->DR
#define UCSR0B USART2_BASE->CR1
#define RXCIE0 USART_CR1_RXNEIE_BIT
#define TXCIE0 USART_CR1_TXEIE_BIT
//#define TIFR1 TIMER2_BASE->SR
//******************** //********************
#define BIND_pin PA0 #define BIND_pin PA0
#define LED_pin PA1 #define LED_pin PA1
@ -172,6 +189,9 @@ enum FRSKYX
#define CS_on digitalWrite(CS_pin,HIGH) #define CS_on digitalWrite(CS_pin,HIGH)
#define CS_off digitalWrite(CS_pin,LOW) #define CS_off digitalWrite(CS_pin,LOW)
#define NRF_CE_on
#define NRF_CE_off
#define SCK_on digitalWrite(SCK_pin,HIGH) #define SCK_on digitalWrite(SCK_pin,HIGH)
#define SCK_off digitalWrite(SCK_pin,LOW) #define SCK_off digitalWrite(SCK_pin,LOW)

View File

@ -5,7 +5,7 @@ based on arduino maple library
*/ */
#ifdef STM32_board
SPIClass SPI_2(2); //Create an instance of the SPI Class called SPI_2 that uses the 2nd SPI Port SPIClass SPI_2(2); //Create an instance of the SPI Class called SPI_2 that uses the 2nd SPI Port
@ -20,7 +20,7 @@ void initSPI2() {
SPI_2.setClockDivider(SPI_CLOCK_DIV8); //// Slow speed (36 / 8 = 4.5 MHz SPI_2 speed) SPI_2.setClockDivider(SPI_CLOCK_DIV8); //// Slow speed (36 / 8 = 4.5 MHz SPI_2 speed)
} }
#endif
#ifdef XMEGA #ifdef XMEGA
#define XNOP() NOP() #define XNOP() NOP()

View File

@ -540,26 +540,18 @@ void initTXSerial( uint8_t speed)
{ {
if(++tx_tail>=TXBUFFER_SIZE)//head if(++tx_tail>=TXBUFFER_SIZE)//head
tx_tail=0; tx_tail=0;
#ifdef XMEGA
USARTC0.DATA = tx_buff[tx_tail] ;
#else
#if defined STM32_board #if defined STM32_board
USART3_BASE->DR=tx_buff[tx_tail];//clears TXE bit USART3_BASE->DR=tx_buff[tx_tail];//clears TXE bit
#else #else
UDR0=tx_buff[tx_tail]; UDR0=tx_buff[tx_tail];
#endif #endif
#endif
} }
if (tx_tail == tx_head) if (tx_tail == tx_head)
#ifdef XMEGA
USARTC0.CTRLA &= ~0x03 ;
#else
#if defined STM32_board #if defined STM32_board
USART3_BASE->CR1 &= ~USART_CR1_TXEIE;//disable interrupt USART3_BASE->CR1 &= ~USART_CR1_TXEIE;//disable interrupt
} }
#else #else
UCSR0B &= ~(1<<UDRIE0); // Check if all data is transmitted . if yes disable transmitter UDRE interrupt tx_pause(); // Check if all data is transmitted . if yes disable transmitter UDRE interrupt
#endif
#endif #endif
} }
@ -571,6 +563,7 @@ void initTXSerial( uint8_t speed)
#endif #endif
#ifdef BASH_SERIAL #ifdef BASH_SERIAL
// Routines for bit-bashed serial output // Routines for bit-bashed serial output

View File

@ -13,6 +13,26 @@
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>. along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
*/ */
/**Board selection**/
#define STM32_board
//#define XMEGA
/*******************/
#ifdef STM32_board
//#undef __cplusplus
#include "Multiprotocol_STM32.h"
#include <EEPROM.h>
#include <libmaple/usart.h>
#include <libmaple/timer.h>
#include <SPI.h>
#else
#include <avr/eeprom.h>
#include <util/delay.h>
#include "Multiprotocol.h"
#endif
/** Multiprotocol module configuration file ***/ /** Multiprotocol module configuration file ***/
/*******************/ /*******************/
@ -124,7 +144,7 @@
#define PPM_MIN_125 1000 // 125% #define PPM_MIN_125 1000 // 125%
#endif #endif
/*
struct PPM_Parameters struct PPM_Parameters
{ {
uint8_t protocol : 5; uint8_t protocol : 5;
@ -134,7 +154,7 @@ struct PPM_Parameters
uint8_t autobind : 1; uint8_t autobind : 1;
uint8_t option; uint8_t option;
}; };
*/
//Update this table to set which protocol and all associated settings are called for the corresponding dial number //Update this table to set which protocol and all associated settings are called for the corresponding dial number
const PPM_Parameters PPM_prot[15]= { const PPM_Parameters PPM_prot[15]= {
// Dial Protocol Sub protocol RX_Num Power Auto Bind Option // Dial Protocol Sub protocol RX_Num Power Auto Bind Option