Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 1200 → Rev 1201

/branches/V0.72p Code Redesign killagreg/dsl.h
3,15 → 3,11
 
#include <inttypes.h>
 
// Received signal strength indicator
extern uint8_t dsl_RSSI;
extern uint8_t dsl_RSSI; // Received signal strength indicator
extern uint8_t dsl_Battery; // Battery voltage (0-255 [0V - 8.2V])
extern uint8_t dsl_Allocation; // Frequency allocation (35,40,72)
 
// Battery voltage (0-255 [0V - 8.2V])
extern uint8_t dsl_Battery;
 
// Frequency allocation (35,40,72)
extern uint8_t dsl_Allocation;
 
#define USART1_BAUD 38400
// this function should be called within the UART RX ISR
extern void dsl_parser(uint8_t c);
 
/branches/V0.72p Code Redesign killagreg/spectrum.c
2,57 → 2,10
Decodieren eines RC Summen Signals oder Spektrum Empfänger-Satellit
#######################################################################################*/
 
#include "Spectrum.h"
#include "main.h"
#include "spectrum.h"
#include rc.h
 
//############################################################################
// zum Decodieren des Spektrum Satelliten wird USART1 benutzt.
// USART1 initialisation from killagreg
void Uart1Init(void)
//############################################################################
{
// -- Start of USART1 initialisation for Spekturm seriell-mode
// USART1 Control and Status Register A, B, C and baud rate register
uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * 115200) - 1);
// disable RX-Interrupt
UCSR1B &= ~(1 << RXCIE1);
// disable TX-Interrupt
UCSR1B &= ~(1 << TXCIE1);
// disable DRE-Interrupt
UCSR1B &= ~(1 << UDRIE1);
// set direction of RXD1 and TXD1 pins
// set RXD1 (PD2) as an input pin
PORTD |= (1 << PORTD2);
DDRD &= ~(1 << DDD2);
// USART0 Baud Rate Register
// set clock divider
UBRR1H = (uint8_t)(ubrr>>8);
UBRR1L = (uint8_t)ubrr;
// enable double speed operation
UCSR1A |= (1 << U2X1);
// enable receiver and transmitter
//UCSR1B = (1<<RXEN1)|(1<<TXEN1);
UCSR1B = (1<<RXEN1);
// set asynchronous mode
UCSR1C &= ~(1 << UMSEL11);
UCSR1C &= ~(1 << UMSEL10);
// no parity
UCSR1C &= ~(1 << UPM11);
UCSR1C &= ~(1 << UPM10);
// 1 stop bit
UCSR1C &= ~(1 << USBS1);
// 8-bit
UCSR1B &= ~(1 << UCSZ12);
UCSR1C |= (1 << UCSZ11);
UCSR1C |= (1 << UCSZ10);
// flush receive buffer explicit
while(UCSR1A & (1<<RXC1)) UDR1;
// enable RX-interrupts at the end
UCSR1B |= (1 << RXCIE1);
// -- End of USART1 initialisation
return;
}
 
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Copyright (c) Rainer Walther
// + RC-routines from original MK rc.c (c) H&I
100,7 → 53,7
// byte9: and byte10: channel data
// byte11: and byte12: channel data
// byte13: and byte14: channel data
// byte15: and byte16: channel data
// byte15: and byte16: channel data
// 2nd Frame:
// byte1: unknown
// byte2: unknown
123,24 → 76,20
//
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
//############################################################################
//Diese Routine startet und inizialisiert den USART1 für seriellen Spektrum satellite reciever
SIGNAL(USART1_RX_vect)
//############################################################################
 
void spectrum_parser(uint8_t c)
 
{
static unsigned int Sync=0, FrameCnt=0, ByteHigh=0, ReSync=1, Frame2=0, FrameTimer;
static unsigned int Sync=0, FrameCnt=0, ByteHigh=0, ReSync=1, Frame2=0, FrameTimer;
unsigned int Channel, index;
signed int signal, tmp;
int bCheckDelay;
uint8_t c;
c = UDR1; // get data byte
 
if (ReSync == 1)
{
// wait for beginning of new frame
ReSync = 0;
 
FrameTimer = SetDelay(7); // minimum 7ms zwischen den frames
FrameCnt = 0;
Sync = 0;
147,7 → 96,7
ByteHigh = 0;
}
else
{
{
bCheckDelay = CheckDelay(FrameTimer);
if ( Sync == 0 )
{
174,7 → 123,7
{
// Datenbyte high
ByteHigh = c;
 
if (FrameCnt == 2)
{
// is 1st Byte of Channel-data
185,7 → 134,7
// DS9: Frame 2 with Channel 8-9 comming next
Frame2 = 1;
}
}
}
Sync = 3;
FrameCnt ++;
}
192,11 → 141,11
else if((Sync == 3) && !bCheckDelay)
{
// Datenbyte low
 
// High-Byte for next channel comes next
Sync = 2;
FrameCnt ++;
 
index = (ByteHigh >> 2) & 0x0f;
index ++;
Channel = (ByteHigh << 8) | c;
203,15 → 152,15
signal = Channel & 0x3ff;
signal -= 0x200; // Offset, range 0x000..0x3ff?
signal = signal/3; // scaling to fit PPM resolution
 
if(index >= 0 && index <= 10)
{
// Stabiles Signal
if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;}
tmp = (3 * (PPM_in[index]) + signal) / 4;
tmp = (3 * (PPM_in[index]) + signal) / 4;
if(tmp > signal+1) tmp--; else
if(tmp < signal-1) tmp++;
if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
if(tmp < signal-1) tmp++;
if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
else PPM_diff[index] = 0;
PPM_in[index] = tmp;
}
223,7 → 172,7
FrameCnt = 0;
Frame2 = 0;
}
 
// 16 Bytes per frame
if(FrameCnt >= 16)
{
232,9 → 181,9
{
// Null bedeutet: Neue Daten
// nur beim ersten Frame (CH 0-7) setzen
NewPpmData = 0;
NewPpmData = 0;
}
 
// new frame next, nach fruehestens 7ms erwartet
FrameCnt = 0;
Frame2 = 0;
243,6 → 192,6
// Zeit bis zum nächsten Zeichen messen
FrameTimer = SetDelay(7);
}
}
}
 
 
/branches/V0.72p Code Redesign killagreg/spectrum.h
1,8 → 1,10
/*#######################################################################################
Dekodieren eines Spectrum Signals
#######################################################################################*/
 
#ifndef _SPECTRUM_H
#define _SPECTRUM_H
void Uart1Init(void);
#endif //_RC_H
 
#include <inttypes.h>
 
#define USART1_BAUD 115200
// this function should be called within the UART RX ISR
extern void spectrum_parser(uint8_t c);
 
#endif //_SPECTRUM_H
/branches/V0.72p Code Redesign killagreg/uart1.c
54,15 → 54,12
#include "uart1.h"
#if defined (USE_KILLAGREG) || defined (USE_MK3MAG)
#include "ubx.h"
#define USART1_BAUD 57600
#else
#ifdef USE_RC_DSL
#include "dsl.h"
#define USART1_BAUD 38400
#endif
#ifdef USE_RC_SPECTRUM
#include "spectrum.h"
#define USART1_BAUD 115200
#endif
#endif
 
131,10 → 128,8
// enable DRE interrupt
//UCSR1B |= (1 << UDRIE1);
 
 
// restore global interrupt flags
SREG = sreg;
 
}
 
 
/branches/V0.72p Code Redesign killagreg/ubx.h
53,6 → 53,8
// this variable should be decremted by the application
extern volatile uint8_t GPSTimeout; // is reset to 255 if a new UBX msg was received
 
 
#define USART1_BAUD 57600
// this function should be called within the UART RX ISR
extern void ubx_parser(uint8_t c);