Orange TX module compilation fixes

This commit is contained in:
pascallanger 2016-09-12 21:44:30 +02:00
parent 8470f4f7fb
commit 47bae63548
3 changed files with 185 additions and 147 deletions

View File

@ -102,9 +102,15 @@ void CYRF_SetTxRxMode(uint8_t mode)
//Set the post tx/rx state //Set the post tx/rx state
CYRF_WriteRegister(CYRF_0F_XACT_CFG, mode == TX_EN ? 0x28 : 0x2C); // 4=IDLE, 8=TX, C=RX CYRF_WriteRegister(CYRF_0F_XACT_CFG, mode == TX_EN ? 0x28 : 0x2C); // 4=IDLE, 8=TX, C=RX
if(mode == TX_EN) if(mode == TX_EN)
#ifdef DSM_BLUE
CYRF_WriteRegister(CYRF_0E_GPIO_CTRL,0x20); // XOUT=1, PACTL=0
else
CYRF_WriteRegister(CYRF_0E_GPIO_CTRL,0x80); // XOUT=0, PACTL=1
#else
CYRF_WriteRegister(CYRF_0E_GPIO_CTRL,0x80); // XOUT=1, PACTL=0 CYRF_WriteRegister(CYRF_0E_GPIO_CTRL,0x80); // XOUT=1, PACTL=0
else else
CYRF_WriteRegister(CYRF_0E_GPIO_CTRL,0x20); // XOUT=0, PACTL=1 CYRF_WriteRegister(CYRF_0E_GPIO_CTRL,0x20); // XOUT=0, PACTL=1
#endif
} }
} }
/* /*

View File

@ -3,6 +3,15 @@
#define XMEGA 1 #define XMEGA 1
#define XOUT 0x80
#define PACTL 0x20
// For BLUE module use:
//#define DSM_BLUE
//#define XOUT 0x20
//#define PACTL 0x80
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
@ -25,6 +34,9 @@ extern void CC2500_Reset(void ) ;
extern uint8_t CYRF_Reset(void ) ; extern uint8_t CYRF_Reset(void ) ;
extern void CYRF_SetTxRxMode(uint8_t mode) ; extern void CYRF_SetTxRxMode(uint8_t mode) ;
extern void frskyUpdate(void) ;
extern uint16_t initDsm2(void) ;
extern uint16_t ReadDsm2(void) ;
extern uint16_t DevoInit(void) ; extern uint16_t DevoInit(void) ;
extern uint16_t devo_callback(void) ; extern uint16_t devo_callback(void) ;
@ -35,6 +47,7 @@ extern long map(long x, long in_min, long in_max, long out_min, long out_max) ;
extern uint32_t millis(void) ; extern uint32_t millis(void) ;
extern uint32_t micros(void) ; extern uint32_t micros(void) ;
extern void delayMicroseconds(uint16_t x) ; extern void delayMicroseconds(uint16_t x) ;
extern void delayMilliseconds(unsigned long ms) ;
extern void init(void) ; extern void init(void) ;
extern int analogRead(uint8_t pin) ; extern int analogRead(uint8_t pin) ;
@ -74,9 +87,9 @@ extern uint16_t ReadDsm() ;
#define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3) #define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3)
#define FRACT_MAX (1000 >> 3) #define FRACT_MAX (1000 >> 3)
volatile unsigned long timer0_overflow_count = 0; //volatile unsigned long timer0_overflow_count = 0;
volatile unsigned long timer0_millis = 0; //volatile unsigned long timer0_millis = 0;
static unsigned char timer0_fract = 0; //static unsigned char timer0_fract = 0;
@ -155,137 +168,136 @@ static unsigned char timer0_fract = 0;
//} //}
//ISR(TCC0_OVF_vect)
ISR(TCC0_OVF_vect) //{
{ // // copy these to local variables so they can be stored in registers
// copy these to local variables so they can be stored in registers // // (volatile variables must be read from memory on every access)
// (volatile variables must be read from memory on every access) // unsigned long m = timer0_millis;
unsigned long m = timer0_millis; // unsigned char f = timer0_fract;
unsigned char f = timer0_fract; //
// m += MILLIS_INC;
m += MILLIS_INC; // f += FRACT_INC;
f += FRACT_INC; // if (f >= FRACT_MAX) {
if (f >= FRACT_MAX) { // f -= FRACT_MAX;
f -= FRACT_MAX; // m += 1;
m += 1; // }
} //
// timer0_fract = f;
timer0_fract = f; // timer0_millis = m;
timer0_millis = m; // timer0_overflow_count++;
timer0_overflow_count++; //}
} //
//unsigned long millis()
unsigned long millis() //{
{ // unsigned long m;
unsigned long m; // uint8_t oldSREG = SREG;
uint8_t oldSREG = SREG; //
// // disable interrupts while we read timer0_millis or we might get an
// disable interrupts while we read timer0_millis or we might get an // // inconsistent value (e.g. in the middle of a write to timer0_millis)
// inconsistent value (e.g. in the middle of a write to timer0_millis) // cli();
cli(); // m = timer0_millis;
m = timer0_millis; // SREG = oldSREG;
SREG = oldSREG; //
// return m;
return m; //}
} //
//unsigned long micros()
unsigned long micros() //{
{ // unsigned long m;
unsigned long m; // uint8_t oldSREG = SREG, t;
uint8_t oldSREG = SREG, t; //
// cli();
cli(); // m = timer0_overflow_count;
m = timer0_overflow_count; // t = TCC0.CNT ;
t = TCC0.CNT ; //
// if ((TCC0.INTFLAGS & TC0_OVFIF_bm) && (t < 255))
if ((TCC0.INTFLAGS & TC0_OVFIF_bm) && (t < 255)) // m++;
m++; //
// SREG = oldSREG;
SREG = oldSREG; //
// return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond()); //}
} //
//void delayMilliseconds(unsigned long ms)
void delayMilliseconds(unsigned long ms) //{
{ // uint16_t start = (uint16_t)micros();
uint16_t start = (uint16_t)micros(); //
// while (ms > 0) {
while (ms > 0) { // yield();
yield(); // if (((uint16_t)micros() - start) >= 1000) {
if (((uint16_t)micros() - start) >= 1000) { // ms--;
ms--; // start += 1000;
start += 1000; // }
} // }
} //}
} //
///* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */
/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */ //void delayMicroseconds(unsigned int us)
void delayMicroseconds(unsigned int us) //{
{ // // calling avrlib's delay_us() function with low values (e.g. 1 or
// calling avrlib's delay_us() function with low values (e.g. 1 or // // 2 microseconds) gives delays longer than desired.
// 2 microseconds) gives delays longer than desired. // //delay_us(us);
//delay_us(us); //#if F_CPU >= 20000000L
#if F_CPU >= 20000000L // // for the 20 MHz clock on rare Arduino boards
// for the 20 MHz clock on rare Arduino boards //
// // for a one-microsecond delay, simply wait 2 cycle and return. The overhead
// for a one-microsecond delay, simply wait 2 cycle and return. The overhead // // of the function call yields a delay of exactly a one microsecond.
// of the function call yields a delay of exactly a one microsecond. // __asm__ __volatile__ (
__asm__ __volatile__ ( // "nop" "\n\t"
"nop" "\n\t" // "nop"); //just waiting 2 cycle
"nop"); //just waiting 2 cycle // if (--us == 0)
if (--us == 0) // return;
return; //
// // the following loop takes a 1/5 of a microsecond (4 cycles)
// the following loop takes a 1/5 of a microsecond (4 cycles) // // per iteration, so execute it five times for each microsecond of
// per iteration, so execute it five times for each microsecond of // // delay requested.
// delay requested. // us = (us<<2) + us; // x5 us
us = (us<<2) + us; // x5 us //
// // account for the time taken in the preceeding commands.
// account for the time taken in the preceeding commands. // us -= 2;
us -= 2; //
//#elif F_CPU >= 16000000L
#elif F_CPU >= 16000000L // // for the 16 MHz clock on most Arduino boards
// for the 16 MHz clock on most Arduino boards //
// // for a one-microsecond delay, simply return. the overhead
// for a one-microsecond delay, simply return. the overhead // // of the function call yields a delay of approximately 1 1/8 us.
// of the function call yields a delay of approximately 1 1/8 us. // if (--us == 0)
if (--us == 0) // return;
return; //
// // the following loop takes a quarter of a microsecond (4 cycles)
// the following loop takes a quarter of a microsecond (4 cycles) // // per iteration, so execute it four times for each microsecond of
// per iteration, so execute it four times for each microsecond of // // delay requested.
// delay requested. // us <<= 2;
us <<= 2; //
// // account for the time taken in the preceeding commands.
// account for the time taken in the preceeding commands. // us -= 2;
us -= 2; //#else
#else // // for the 8 MHz internal clock on the ATmega168
// for the 8 MHz internal clock on the ATmega168 //
// // for a one- or two-microsecond delay, simply return. the overhead of
// for a one- or two-microsecond delay, simply return. the overhead of // // the function calls takes more than two microseconds. can't just
// the function calls takes more than two microseconds. can't just // // subtract two, since us is unsigned; we'd overflow.
// subtract two, since us is unsigned; we'd overflow. // if (--us == 0)
if (--us == 0) // return;
return; // if (--us == 0)
if (--us == 0) // return;
return; //
// // the following loop takes half of a microsecond (4 cycles)
// the following loop takes half of a microsecond (4 cycles) // // per iteration, so execute it twice for each microsecond of
// per iteration, so execute it twice for each microsecond of // // delay requested.
// delay requested. // us <<= 1;
us <<= 1; //
// // partially compensate for the time taken by the preceeding commands.
// partially compensate for the time taken by the preceeding commands. // // we can't subtract any more than this or we'd overflow w/ small delays.
// we can't subtract any more than this or we'd overflow w/ small delays. // us--;
us--; //#endif
#endif //
// // busy wait
// busy wait // __asm__ __volatile__ (
__asm__ __volatile__ ( // "1: sbiw %0,1" "\n\t" // 2 cycles
"1: sbiw %0,1" "\n\t" // 2 cycles // "brne 1b" : "=w" (us) : "0" (us) // 2 cycles
"brne 1b" : "=w" (us) : "0" (us) // 2 cycles // );
); //}
}
#ifndef cbi #ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
@ -329,15 +341,15 @@ void init()
// TCC0 counts 0-255 at 4uS clock rate // TCC0 counts 0-255 at 4uS clock rate
EVSYS.CH2MUX = 0x80 + 0x07 ; // Prescaler of 128 // EVSYS.CH2MUX = 0x80 + 0x07 ; // Prescaler of 128
TCC0.CTRLB = 0 ; // TCC0.CTRLB = 0 ;
TCC0.CTRLC = 0 ; // TCC0.CTRLC = 0 ;
TCC0.CTRLD = 0 ; // TCC0.CTRLD = 0 ;
TCC0.CTRLE = 0 ; // TCC0.CTRLE = 0 ;
TCC0.INTCTRLA = 0x01 ; // TCC0.INTCTRLA = 0x01 ;
TCC0.INTCTRLB = 0 ; // TCC0.INTCTRLB = 0 ;
TCC0.PER = 0x00FF ; // TCC0.PER = 0x00FF ;
TCC0.CTRLA = 0x0A ; // TCC0.CTRLA = 0x0A ;
#if defined(ADCSRA) #if defined(ADCSRA)

View File

@ -95,9 +95,10 @@ uint8_t protocol_flags=0,protocol_flags2=0;
// PPM variable // PPM variable
volatile uint16_t PPM_data[NUM_CHN]; volatile uint16_t PPM_data[NUM_CHN];
#ifndef XMEGA
//Random variable //Random variable
volatile uint32_t gWDT_entropy=0; volatile uint32_t gWDT_entropy=0;
#endif
// Serial variables // Serial variables
#ifdef INVERT_TELEMETRY #ifdef INVERT_TELEMETRY
// enable bit bash for serial // enable bit bash for serial
@ -183,8 +184,8 @@ void setup()
// Timer1 config // Timer1 config
TCCR1A = 0; TCCR1A = 0;
TCCR1B = (1 << CS11); //prescaler8, set timer1 to increment every 0.5us(16Mhz) and start timer TCCR1B = (1 << CS11); //prescaler8, set timer1 to increment every 0.5us(16Mhz) and start timer
random_init();
#endif #endif
random_init();
// Set Chip selects // Set Chip selects
A7105_CS_on; A7105_CS_on;
@ -225,8 +226,10 @@ void setup()
//Init RF modules //Init RF modules
modules_reset(); modules_reset();
#ifndef XMEGA
//Init the seed with a random value created from watchdog timer for all protocols requiring random values //Init the seed with a random value created from watchdog timer for all protocols requiring random values
randomSeed(random_value()); randomSeed(random_value());
#endif
// Read or create protocol id // Read or create protocol id
MProtocol_id_master=random_id(10,false); MProtocol_id_master=random_id(10,false);
@ -419,7 +422,9 @@ inline void tx_resume()
if(!IS_TX_PAUSE_on) if(!IS_TX_PAUSE_on)
{ {
#ifdef XMEGA #ifdef XMEGA
cli() ;
USARTC0.CTRLA = (USARTC0.CTRLA & 0xFC) | 0x01 ; // Resume telemetry by enabling transmitter interrupt USARTC0.CTRLA = (USARTC0.CTRLA & 0xFC) | 0x01 ; // Resume telemetry by enabling transmitter interrupt
sei() ;
#else #else
#ifndef BASH_SERIAL #ifndef BASH_SERIAL
UCSR0B |= _BV(UDRIE0); // Resume telemetry by enabling transmitter interrupt UCSR0B |= _BV(UDRIE0); // Resume telemetry by enabling transmitter interrupt
@ -865,6 +870,7 @@ static void set_rx_tx_addr(uint32_t id)
rx_tx_addr[4] = 0xC1; // for YD717: always uses first data port rx_tx_addr[4] = 0xC1; // for YD717: always uses first data port
} }
#ifndef XMEGA
static void random_init(void) static void random_init(void)
{ {
cli(); // Temporarily turn off interrupts, until WDT configured cli(); // Temporarily turn off interrupts, until WDT configured
@ -879,6 +885,7 @@ static uint32_t random_value(void)
while (!gWDT_entropy); while (!gWDT_entropy);
return gWDT_entropy; return gWDT_entropy;
} }
#endif
static uint32_t random_id(uint16_t adress, uint8_t create_new) static uint32_t random_id(uint16_t adress, uint8_t create_new)
{ {
@ -963,7 +970,6 @@ uint8_t SPI_Read(void)
// replacement millis() and micros() // replacement millis() and micros()
// These work polled, no interrupts // These work polled, no interrupts
// micros() MUST be called at least once every 32 milliseconds // micros() MUST be called at least once every 32 milliseconds
#ifndef XMEGA
uint16_t MillisPrecount ; uint16_t MillisPrecount ;
uint16_t lastTimerValue ; uint16_t lastTimerValue ;
uint32_t TotalMicros ; uint32_t TotalMicros ;
@ -1052,12 +1058,24 @@ void delayMicroseconds(unsigned int us)
return; return;
us <<= 2; // * 4 us <<= 2; // * 4
us -= 2; // - 2 us -= 2; // - 2
__asm__ __volatile__ ( #ifdef XMEGA
__asm__ __volatile__ (
"1: sbiw %0,1" "\n\t" // 2 cycles
"nop \n"
"nop \n"
"nop \n"
"nop \n"
"brne 1b" : "=w" (us) : "0" (us) // 2 cycles
);
#else
__asm__ __volatile__ (
"1: sbiw %0,1" "\n\t" // 2 cycles "1: sbiw %0,1" "\n\t" // 2 cycles
"brne 1b" : "=w" (us) : "0" (us) // 2 cycles "brne 1b" : "=w" (us) : "0" (us) // 2 cycles
); );
#endif
} }
#ifndef XMEGA
void init() void init()
{ {
// this needs to be called before setup() or some functions won't work there // this needs to be called before setup() or some functions won't work there
@ -1180,6 +1198,7 @@ ISR(TIMER1_COMPB_vect, ISR_NOBLOCK )
} }
#endif //ENABLE_SERIAL #endif //ENABLE_SERIAL
#ifndef XMEGA
// Random interrupt service routine called every time the WDT interrupt is triggered. // Random interrupt service routine called every time the WDT interrupt is triggered.
// It is only enabled at startup to generate a seed. // It is only enabled at startup to generate a seed.
ISR(WDT_vect) ISR(WDT_vect)
@ -1204,3 +1223,4 @@ ISR(WDT_vect)
WDTCSR = 0; // Disable Watchdog interrupt WDTCSR = 0; // Disable Watchdog interrupt
} }
} }
#endif