Subversion Repositories Projects

Rev

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

Rev Author Line No. Line
724 woggle 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
 
48
//*****************************************************************************
49
// 
50
extern uint8_t buffer[30];
51
 
52
extern volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
53
extern volatile uint8_t txd_complete;
54
extern volatile uint8_t rxd_buffer[RXD_BUFFER_LEN];
55
extern volatile uint8_t rxd_buffer_locked;
56
extern volatile uint8_t ReceivedBytes;
57
extern volatile uint8_t *pRxData;
58
extern volatile uint8_t RxDataLen;
59
 
60
extern volatile uint16_t stat_crc_error;
61
extern volatile uint16_t stat_overflow_error;
62
 
63
//*****************************************************************************
64
// 
65
void USART_Init (void);
66
 
67
void USART_DisableTXD (void);
68
void USART_EnableTXD (void);
69
void USART_request_mk_data (uint8_t cmd, uint8_t addr, uint8_t ms);
70
 
71
void USART_putc (char c);
72
void USART_puts (char *s);
73
void USART_puts_p (const char *s);
74
 
75
void SendOutData (uint8_t cmd, uint8_t addr, uint8_t numofbuffers, ...); // uint8_t *pdata, uint8_t len, ...
76
//void SendOutData(uint8_t cmd, uint8_t addr, uint8_t numofbuffers, uint8_t *pdata, uint8_t len); // uint8_t *pdata, uint8_t len, ...
77
void Decode64 (void);
78
 
79
void SwitchToNC (void);
80
void SwitchToFC (void);
81
void SwitchToMAG (void);
82
void SwitchToGPS (void);
83
 
84
//*****************************************************************************
85
//Anpassen der seriellen Schnittstellen Register
86
#if defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega168__)
87
#define USART_RXC_vect USART0_RX_vect
88
//-----------------------
89
#define UCSRA           UCSR0A
90
#define UCSRB           UCSR0B
91
#define UCSRC           UCSR0C
92
#define UDR                     UDR0
93
#define UBRRL           UBRR0L
94
#define UBRRH           UBRR0H
95
 
96
// UCSRA
97
#define RXC                     RXC0
98
#define TXC                     TXC0
99
#define UDRE            UDRE0
100
#define FE                      FE0
101
#define UPE                     UPE0
102
#define U2X                     U2X0
103
#define MPCM            MPCM0
104
 
105
// UCSRB
106
#define RXCIE           RXCIE0
107
#define TXCIE           TXCIE0
108
#define UDRIE           UDRIE0
109
#define TXEN            TXEN0
110
#define RXEN            RXEN0
111
#define UCSZ2           UCSZ02
112
#define RXB8            RXB80
113
#define TXB8            TXB80
114
 
115
// UCSRC
116
#define UMSEL1  UMSEL01
117
#define UMSEL0  UMSEL00
118
#define UPM1            UPM01
119
#define UPM0            UPM00
120
#define USBS            USBS0
121
#define UCSZ1           UCSZ01
122
#define UCSZ0           UCSZ00
123
#define UCPOL           UCPOL0
124
//-----------------------
125
#endif
126
 
127
#endif