Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1053 - 1
/*****************************************************************************
2
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
3
 *   taken some ideas from the C-OSD code from CaScAdE                       *
4
 *   the MK communication routines are taken from the MK source              *
5
 *    (killagreg version)                                                    *
6
 *                                                                           *
7
 *   This program is free software; you can redistribute it and/or modify    *
8
 *   it under the terms of the GNU General Public License as published by    *
9
 *   the Free Software Foundation; either version 2 of the License.          *
10
 *                                                                           *
11
 *   This program is distributed in the hope that it will be useful,         *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
14
 *   GNU General Public License for more details.                            *
15
 *                                                                           *
16
 *   You should have received a copy of the GNU General Public License       *
17
 *   along with this program; if not, write to the                           *
18
 *   Free Software Foundation, Inc.,                                         *
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
20
 *                                                                           *
21
 *****************************************************************************/
22
 
23
#ifndef _USART_H
24
#define _USART_H
25
 
26
//*****************************************************************************
27
// 
28
#ifndef FALSE
29
#define FALSE   0
30
#endif
31
#ifndef TRUE
32
#define TRUE    1
33
#endif
34
 
35
// addresses
36
#define ADDRESS_ANY     0
37
#define ADDRESS_FC      1
38
#define ADDRESS_NC      2
39
#define ADDRESS_MAG     3
40
 
41
// must be at least 4('#'+Addr+'CmdID'+'\r')+ (80 * 4)/3 = 111 bytes
42
#define TXD_BUFFER_LEN  60
43
#define RXD_BUFFER_LEN  180
44
 
45
// Baud rate of the USART
46
#define USART_BAUD 57600        
47
//#define USART_BAUD 125000     
48
 
49
//*****************************************************************************
50
// 
51
extern uint8_t buffer[30];
52
 
53
extern volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
54
extern volatile uint8_t txd_complete;
55
extern volatile uint8_t rxd_buffer[RXD_BUFFER_LEN];
56
extern volatile uint8_t rxd_buffer_locked;
57
extern volatile uint8_t ReceivedBytes;
58
extern volatile uint8_t *pRxData;
59
extern volatile uint8_t RxDataLen;
60
 
61
extern volatile uint16_t stat_crc_error;
62
extern volatile uint16_t stat_overflow_error;
63
 
64
extern volatile uint8_t rxFlag;
65
extern volatile uint8_t rx_byte;
66
//extern volatile static uint8_t *volatile rxhead, *volatile rxtail;
67
 
68
//*****************************************************************************
69
// 
70
void USART_Init (unsigned int baudrate);
71
void USART_DisableTXD (void);
72
void USART_EnableTXD (void);
73
void USART_request_mk_data (uint8_t cmd, uint8_t addr, uint8_t ms);
74
 
75
void USART_putc (char c);
76
void USART_puts (char *s);
77
void USART_puts_p (const char *s);
78
 
79
 
80
extern char USART_getc(void);
81
void SendOutData (uint8_t cmd, uint8_t addr, uint8_t numofbuffers, ...); // uint8_t *pdata, uint8_t len, ...
82
//void SendOutData(uint8_t cmd, uint8_t addr, uint8_t numofbuffers, uint8_t *pdata, uint8_t len); // uint8_t *pdata, uint8_t len, ...
83
void Decode64 (void);
84
 
85
void SwitchToNC (void);
86
void SwitchToFC (void);
87
void SwitchToMAG (void);
88
void SwitchToGPS (void);
89
void SwitchToWi232 (void);
90
void debug1(void);
91
 
92
uint8_t uart_getc_nb(uint8_t*);
93
 
94
//*****************************************************************************
95
//Anpassen der seriellen Schnittstellen Register
96
#define USART_RXC_vect USART0_RX_vect
97
//-----------------------
98
#define UCSRA           UCSR0A
99
#define UCSRB           UCSR0B
100
#define UCSRC           UCSR0C
101
#define UDR                     UDR0
102
#define UBRRL           UBRR0L
103
#define UBRRH           UBRR0H
104
 
105
// UCSRA
106
#define RXC                     RXC0
107
#define TXC                     TXC0
108
#define UDRE            UDRE0
109
#define FE                      FE0
110
#define UPE                     UPE0
111
#define U2X                     U2X0
112
#define MPCM            MPCM0
113
 
114
// UCSRB
115
#define RXCIE           RXCIE0
116
#define TXCIE           TXCIE0
117
#define UDRIE           UDRIE0
118
#define TXEN            TXEN0
119
#define RXEN            RXEN0
120
#define UCSZ2           UCSZ02
121
#define RXB8            RXB80
122
#define TXB8            TXB80
123
 
124
// UCSRC
125
#define UMSEL1  UMSEL01
126
#define UMSEL0  UMSEL00
127
#define UPM1            UPM01
128
#define UPM0            UPM00
129
#define USBS            USBS0
130
#define UCSZ1           UCSZ01
131
#define UCSZ0           UCSZ00
132
#define UCPOL           UCPOL0
133
//-----------------------
134
 
135
 
136
#endif
137