mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-07-01 01:57:52 +00:00
Orange TX module compilation fixes
This commit is contained in:
parent
8470f4f7fb
commit
47bae63548
@ -102,9 +102,15 @@ void CYRF_SetTxRxMode(uint8_t mode)
|
||||
//Set the post tx/rx state
|
||||
CYRF_WriteRegister(CYRF_0F_XACT_CFG, mode == TX_EN ? 0x28 : 0x2C); // 4=IDLE, 8=TX, C=RX
|
||||
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
|
||||
else
|
||||
CYRF_WriteRegister(CYRF_0E_GPIO_CTRL,0x20); // XOUT=0, PACTL=1
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
@ -3,6 +3,15 @@
|
||||
|
||||
#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 <string.h>
|
||||
#include <avr/interrupt.h>
|
||||
@ -25,6 +34,9 @@ extern void CC2500_Reset(void ) ;
|
||||
extern uint8_t CYRF_Reset(void ) ;
|
||||
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 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 micros(void) ;
|
||||
extern void delayMicroseconds(uint16_t x) ;
|
||||
extern void delayMilliseconds(unsigned long ms) ;
|
||||
extern void init(void) ;
|
||||
|
||||
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_MAX (1000 >> 3)
|
||||
|
||||
volatile unsigned long timer0_overflow_count = 0;
|
||||
volatile unsigned long timer0_millis = 0;
|
||||
static unsigned char timer0_fract = 0;
|
||||
//volatile unsigned long timer0_overflow_count = 0;
|
||||
//volatile unsigned long timer0_millis = 0;
|
||||
//static unsigned char timer0_fract = 0;
|
||||
|
||||
|
||||
|
||||
@ -155,137 +168,136 @@ static unsigned char timer0_fract = 0;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
ISR(TCC0_OVF_vect)
|
||||
{
|
||||
// copy these to local variables so they can be stored in registers
|
||||
// (volatile variables must be read from memory on every access)
|
||||
unsigned long m = timer0_millis;
|
||||
unsigned char f = timer0_fract;
|
||||
|
||||
m += MILLIS_INC;
|
||||
f += FRACT_INC;
|
||||
if (f >= FRACT_MAX) {
|
||||
f -= FRACT_MAX;
|
||||
m += 1;
|
||||
}
|
||||
|
||||
timer0_fract = f;
|
||||
timer0_millis = m;
|
||||
timer0_overflow_count++;
|
||||
}
|
||||
|
||||
unsigned long millis()
|
||||
{
|
||||
unsigned long m;
|
||||
uint8_t oldSREG = SREG;
|
||||
|
||||
// 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)
|
||||
cli();
|
||||
m = timer0_millis;
|
||||
SREG = oldSREG;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
unsigned long micros()
|
||||
{
|
||||
unsigned long m;
|
||||
uint8_t oldSREG = SREG, t;
|
||||
|
||||
cli();
|
||||
m = timer0_overflow_count;
|
||||
t = TCC0.CNT ;
|
||||
|
||||
if ((TCC0.INTFLAGS & TC0_OVFIF_bm) && (t < 255))
|
||||
m++;
|
||||
|
||||
SREG = oldSREG;
|
||||
|
||||
return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
|
||||
}
|
||||
|
||||
void delayMilliseconds(unsigned long ms)
|
||||
{
|
||||
uint16_t start = (uint16_t)micros();
|
||||
|
||||
while (ms > 0) {
|
||||
yield();
|
||||
if (((uint16_t)micros() - start) >= 1000) {
|
||||
ms--;
|
||||
start += 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */
|
||||
void delayMicroseconds(unsigned int us)
|
||||
{
|
||||
// calling avrlib's delay_us() function with low values (e.g. 1 or
|
||||
// 2 microseconds) gives delays longer than desired.
|
||||
//delay_us(us);
|
||||
#if F_CPU >= 20000000L
|
||||
// for the 20 MHz clock on rare Arduino boards
|
||||
|
||||
// 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.
|
||||
__asm__ __volatile__ (
|
||||
"nop" "\n\t"
|
||||
"nop"); //just waiting 2 cycle
|
||||
if (--us == 0)
|
||||
return;
|
||||
|
||||
// the following loop takes a 1/5 of a microsecond (4 cycles)
|
||||
// per iteration, so execute it five times for each microsecond of
|
||||
// delay requested.
|
||||
us = (us<<2) + us; // x5 us
|
||||
|
||||
// account for the time taken in the preceeding commands.
|
||||
us -= 2;
|
||||
|
||||
#elif F_CPU >= 16000000L
|
||||
// for the 16 MHz clock on most Arduino boards
|
||||
|
||||
// for a one-microsecond delay, simply return. the overhead
|
||||
// of the function call yields a delay of approximately 1 1/8 us.
|
||||
if (--us == 0)
|
||||
return;
|
||||
|
||||
// the following loop takes a quarter of a microsecond (4 cycles)
|
||||
// per iteration, so execute it four times for each microsecond of
|
||||
// delay requested.
|
||||
us <<= 2;
|
||||
|
||||
// account for the time taken in the preceeding commands.
|
||||
us -= 2;
|
||||
#else
|
||||
// for the 8 MHz internal clock on the ATmega168
|
||||
|
||||
// for a one- or two-microsecond delay, simply return. the overhead of
|
||||
// the function calls takes more than two microseconds. can't just
|
||||
// subtract two, since us is unsigned; we'd overflow.
|
||||
if (--us == 0)
|
||||
return;
|
||||
if (--us == 0)
|
||||
return;
|
||||
|
||||
// the following loop takes half of a microsecond (4 cycles)
|
||||
// per iteration, so execute it twice for each microsecond of
|
||||
// delay requested.
|
||||
us <<= 1;
|
||||
|
||||
// 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.
|
||||
us--;
|
||||
#endif
|
||||
|
||||
// busy wait
|
||||
__asm__ __volatile__ (
|
||||
"1: sbiw %0,1" "\n\t" // 2 cycles
|
||||
"brne 1b" : "=w" (us) : "0" (us) // 2 cycles
|
||||
);
|
||||
}
|
||||
//ISR(TCC0_OVF_vect)
|
||||
//{
|
||||
// // copy these to local variables so they can be stored in registers
|
||||
// // (volatile variables must be read from memory on every access)
|
||||
// unsigned long m = timer0_millis;
|
||||
// unsigned char f = timer0_fract;
|
||||
//
|
||||
// m += MILLIS_INC;
|
||||
// f += FRACT_INC;
|
||||
// if (f >= FRACT_MAX) {
|
||||
// f -= FRACT_MAX;
|
||||
// m += 1;
|
||||
// }
|
||||
//
|
||||
// timer0_fract = f;
|
||||
// timer0_millis = m;
|
||||
// timer0_overflow_count++;
|
||||
//}
|
||||
//
|
||||
//unsigned long millis()
|
||||
//{
|
||||
// unsigned long m;
|
||||
// uint8_t oldSREG = SREG;
|
||||
//
|
||||
// // 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)
|
||||
// cli();
|
||||
// m = timer0_millis;
|
||||
// SREG = oldSREG;
|
||||
//
|
||||
// return m;
|
||||
//}
|
||||
//
|
||||
//unsigned long micros()
|
||||
//{
|
||||
// unsigned long m;
|
||||
// uint8_t oldSREG = SREG, t;
|
||||
//
|
||||
// cli();
|
||||
// m = timer0_overflow_count;
|
||||
// t = TCC0.CNT ;
|
||||
//
|
||||
// if ((TCC0.INTFLAGS & TC0_OVFIF_bm) && (t < 255))
|
||||
// m++;
|
||||
//
|
||||
// SREG = oldSREG;
|
||||
//
|
||||
// return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
|
||||
//}
|
||||
//
|
||||
//void delayMilliseconds(unsigned long ms)
|
||||
//{
|
||||
// uint16_t start = (uint16_t)micros();
|
||||
//
|
||||
// while (ms > 0) {
|
||||
// yield();
|
||||
// if (((uint16_t)micros() - start) >= 1000) {
|
||||
// ms--;
|
||||
// start += 1000;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
///* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */
|
||||
//void delayMicroseconds(unsigned int us)
|
||||
//{
|
||||
// // calling avrlib's delay_us() function with low values (e.g. 1 or
|
||||
// // 2 microseconds) gives delays longer than desired.
|
||||
// //delay_us(us);
|
||||
//#if F_CPU >= 20000000L
|
||||
// // for the 20 MHz clock on rare Arduino boards
|
||||
//
|
||||
// // 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.
|
||||
// __asm__ __volatile__ (
|
||||
// "nop" "\n\t"
|
||||
// "nop"); //just waiting 2 cycle
|
||||
// if (--us == 0)
|
||||
// return;
|
||||
//
|
||||
// // the following loop takes a 1/5 of a microsecond (4 cycles)
|
||||
// // per iteration, so execute it five times for each microsecond of
|
||||
// // delay requested.
|
||||
// us = (us<<2) + us; // x5 us
|
||||
//
|
||||
// // account for the time taken in the preceeding commands.
|
||||
// us -= 2;
|
||||
//
|
||||
//#elif F_CPU >= 16000000L
|
||||
// // for the 16 MHz clock on most Arduino boards
|
||||
//
|
||||
// // for a one-microsecond delay, simply return. the overhead
|
||||
// // of the function call yields a delay of approximately 1 1/8 us.
|
||||
// if (--us == 0)
|
||||
// return;
|
||||
//
|
||||
// // the following loop takes a quarter of a microsecond (4 cycles)
|
||||
// // per iteration, so execute it four times for each microsecond of
|
||||
// // delay requested.
|
||||
// us <<= 2;
|
||||
//
|
||||
// // account for the time taken in the preceeding commands.
|
||||
// us -= 2;
|
||||
//#else
|
||||
// // for the 8 MHz internal clock on the ATmega168
|
||||
//
|
||||
// // for a one- or two-microsecond delay, simply return. the overhead of
|
||||
// // the function calls takes more than two microseconds. can't just
|
||||
// // subtract two, since us is unsigned; we'd overflow.
|
||||
// if (--us == 0)
|
||||
// return;
|
||||
// if (--us == 0)
|
||||
// return;
|
||||
//
|
||||
// // the following loop takes half of a microsecond (4 cycles)
|
||||
// // per iteration, so execute it twice for each microsecond of
|
||||
// // delay requested.
|
||||
// us <<= 1;
|
||||
//
|
||||
// // 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.
|
||||
// us--;
|
||||
//#endif
|
||||
//
|
||||
// // busy wait
|
||||
// __asm__ __volatile__ (
|
||||
// "1: sbiw %0,1" "\n\t" // 2 cycles
|
||||
// "brne 1b" : "=w" (us) : "0" (us) // 2 cycles
|
||||
// );
|
||||
//}
|
||||
|
||||
#ifndef cbi
|
||||
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
|
||||
@ -329,15 +341,15 @@ void init()
|
||||
|
||||
|
||||
// TCC0 counts 0-255 at 4uS clock rate
|
||||
EVSYS.CH2MUX = 0x80 + 0x07 ; // Prescaler of 128
|
||||
TCC0.CTRLB = 0 ;
|
||||
TCC0.CTRLC = 0 ;
|
||||
TCC0.CTRLD = 0 ;
|
||||
TCC0.CTRLE = 0 ;
|
||||
TCC0.INTCTRLA = 0x01 ;
|
||||
TCC0.INTCTRLB = 0 ;
|
||||
TCC0.PER = 0x00FF ;
|
||||
TCC0.CTRLA = 0x0A ;
|
||||
// EVSYS.CH2MUX = 0x80 + 0x07 ; // Prescaler of 128
|
||||
// TCC0.CTRLB = 0 ;
|
||||
// TCC0.CTRLC = 0 ;
|
||||
// TCC0.CTRLD = 0 ;
|
||||
// TCC0.CTRLE = 0 ;
|
||||
// TCC0.INTCTRLA = 0x01 ;
|
||||
// TCC0.INTCTRLB = 0 ;
|
||||
// TCC0.PER = 0x00FF ;
|
||||
// TCC0.CTRLA = 0x0A ;
|
||||
|
||||
|
||||
#if defined(ADCSRA)
|
||||
|
@ -95,9 +95,10 @@ uint8_t protocol_flags=0,protocol_flags2=0;
|
||||
// PPM variable
|
||||
volatile uint16_t PPM_data[NUM_CHN];
|
||||
|
||||
#ifndef XMEGA
|
||||
//Random variable
|
||||
volatile uint32_t gWDT_entropy=0;
|
||||
|
||||
#endif
|
||||
// Serial variables
|
||||
#ifdef INVERT_TELEMETRY
|
||||
// enable bit bash for serial
|
||||
@ -183,8 +184,8 @@ void setup()
|
||||
// Timer1 config
|
||||
TCCR1A = 0;
|
||||
TCCR1B = (1 << CS11); //prescaler8, set timer1 to increment every 0.5us(16Mhz) and start timer
|
||||
random_init();
|
||||
#endif
|
||||
random_init();
|
||||
|
||||
// Set Chip selects
|
||||
A7105_CS_on;
|
||||
@ -225,8 +226,10 @@ void setup()
|
||||
//Init RF modules
|
||||
modules_reset();
|
||||
|
||||
#ifndef XMEGA
|
||||
//Init the seed with a random value created from watchdog timer for all protocols requiring random values
|
||||
randomSeed(random_value());
|
||||
#endif
|
||||
|
||||
// Read or create protocol id
|
||||
MProtocol_id_master=random_id(10,false);
|
||||
@ -419,7 +422,9 @@ inline void tx_resume()
|
||||
if(!IS_TX_PAUSE_on)
|
||||
{
|
||||
#ifdef XMEGA
|
||||
cli() ;
|
||||
USARTC0.CTRLA = (USARTC0.CTRLA & 0xFC) | 0x01 ; // Resume telemetry by enabling transmitter interrupt
|
||||
sei() ;
|
||||
#else
|
||||
#ifndef BASH_SERIAL
|
||||
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
|
||||
}
|
||||
|
||||
#ifndef XMEGA
|
||||
static void random_init(void)
|
||||
{
|
||||
cli(); // Temporarily turn off interrupts, until WDT configured
|
||||
@ -879,6 +885,7 @@ static uint32_t random_value(void)
|
||||
while (!gWDT_entropy);
|
||||
return gWDT_entropy;
|
||||
}
|
||||
#endif
|
||||
|
||||
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()
|
||||
// These work polled, no interrupts
|
||||
// micros() MUST be called at least once every 32 milliseconds
|
||||
#ifndef XMEGA
|
||||
uint16_t MillisPrecount ;
|
||||
uint16_t lastTimerValue ;
|
||||
uint32_t TotalMicros ;
|
||||
@ -1052,12 +1058,24 @@ void delayMicroseconds(unsigned int us)
|
||||
return;
|
||||
us <<= 2; // * 4
|
||||
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
|
||||
"brne 1b" : "=w" (us) : "0" (us) // 2 cycles
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef XMEGA
|
||||
void init()
|
||||
{
|
||||
// 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
|
||||
|
||||
#ifndef XMEGA
|
||||
// Random interrupt service routine called every time the WDT interrupt is triggered.
|
||||
// It is only enabled at startup to generate a seed.
|
||||
ISR(WDT_vect)
|
||||
@ -1204,3 +1223,4 @@ ISR(WDT_vect)
|
||||
WDTCSR = 0; // Disable Watchdog interrupt
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user