forked from fizmasoft/fizmasoft_fingerprint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuart_quirks.h
217 lines (200 loc) · 6.64 KB
/
uart_quirks.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
Copyright (c) 2010, Jeremy Cole <[email protected]>
Copyright (c) 2006, Peter Fleury <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef UART_QUIRKS_H
#define UART_QUIRKS_H
#include <avr/io.h>
/*
* Old AVR AT90 classic or ATmega103 with one UART.
* - Status/Control Registers: Split USR/UCR
* - Numeric Suffixes on Regs: No
* - Numeric Suffixes on ISRs: No
*/
#if defined(__AVR_AT90S2313__) \
|| defined(__AVR_AT90S4414__) \
|| defined(__AVR_AT90S4434__) \
|| defined(__AVR_AT90S8515__) \
|| defined(__AVR_AT90S8535__) \
|| defined(__AVR_ATmega103__)
#define UART0_PRESENT 1
#define UART0_RXC_INT UART_RX_vect
#define UART0_TXC_INT UART_TX_vect
#define UART0_DRE_INT UART_UDRE_vect
#define UART0_STATUS USR
#define UART0_CONTROL UCR
#define UART0_DATA UDR
#define UART0_UBRRL UBRR
#undef UART0_UBRRH
#define UART0_UDRIE _BV(UDRIE)
#undef UART0_U2X
#undef UART0_ENABLE
#define UART0_FORMAT_8N1 (_BV(UCSZ01) | _BV(UCSZ00))
#define UART0_ERROR_FE _BV(FE)
#define UART0_ERROR_DOR _BV(DOR)
/*
* Old AVR AT90 classic with one UART.
* - Status/Control Registers: Combined A/B
* - Numeric Suffixes on Regs: No
* - Numeric Suffixes on ISRs: No
*/
#elif defined(__AVR_AT90S2333__) \
|| defined(__AVR_AT90S4433__)
#define UART0_RXC_INT UART_RX_vect
#define UART0_TXC_INT UART_TX_vect
#define UART0_DRE_INT UART_UDRE_vect
#define UART0_STATUS UCSRA
#define UART0_CONTROL UCSRB
#define UART0_FORMAT UCSRC
#define UART0_DATA UDR
#define UART0_UBRRL UBRR
#undef UART0_UBRRH
#define UART0_UDRIE _BV(UDRIE)
#undef UART0_U2X
#undef UART0_ENABLE
#define UART0_FORMAT_8N1 (_BV(UCSZ1) | _BV(UCSZ0))
#define UART0_ERROR_FE _BV(FE)
#define UART0_ERROR_DOR _BV(DOR)
/* ATmega with one UART/USART
* - Status/Control Registers: Combined A/B
* - Numeric Suffixes on Regs: No
* - Numeric Suffixes on ISRs: No
*/
#elif defined(__AVR_ATmega8__) \
|| defined(__AVR_ATmega16__) \
|| defined(__AVR_ATmega32__) \
|| defined(__AVR_ATmega323__) \
|| defined(__AVR_ATmega8515__) \
|| defined(__AVR_ATmega8535__) \
|| defined(__AVR_ATtiny2313__) \
|| defined(__AVR_ATmega163__) \
|| defined(__AVR_ATmega169__)
#undef UART0_RXC_INT
#undef UART0_TXC_INT
#undef UART0_DRE_INT
#define UART0_STATUS UCSRA
#define UART0_CONTROL UCSRB
#define UART0_FORMAT UCSRC
#define UART0_DATA UDR
#if defined(UBRRHI)
/* This is a UART, not a USART */
#define UART0_UBRRL UBRR
#define UART0_UBRRH UBRRHI
#else
#define UART0_UBRRL UBRRL
#define UART0_UBRRH UBRRH
#endif
#define UART0_UDRIE _BV(UDRIE)
#define UART0_U2X _BV(U2X)
#define UART0_ENABLE (_BV(RXCIE) | _BV(RXEN)| _BV(TXEN))
#define UART0_FORMAT_8N1 (_BV(UCSZ1) | _BV(UCSZ0))
#define UART0_ERROR_FE _BV(FE)
#define UART0_ERROR_DOR _BV(DOR)
/* ATmega with one USART
* - Status/Control Registers: Combined A/B
* - Numeric Suffixes on Regs: Yes
* - Numeric Suffixes on ISRs: Yes
*/
#elif defined(__AVR_ATmega48__) \
|| defined(__AVR_ATmega88__) \
|| defined(__AVR_ATmega168__) \
|| defined(__AVR_ATmega329__) \
|| defined(__AVR_ATmega3290__) \
|| defined(__AVR_ATmega649__) \
|| defined(__AVR_ATmega6490__) \
|| defined(__AVR_ATmega325__) \
|| defined(__AVR_ATmega3250__) \
|| defined(__AVR_ATmega645__) \
|| defined(__AVR_ATmega6450__) \
|| defined(__AVR_ATmega644__)
#undef UART0_RXC_INT
#undef UART0_TXC_INT
#undef UART0_DRE_INT
#define UART0_STATUS UCSR0A
#define UART0_CONTROL UCSR0B
#define UART0_FORMAT UCSR0C
#define UART0_DATA UDR0
#define UART0_UBRRL UBRR0L
#define UART0_UBRRH UBRR0H
#define UART0_UDRIE _BV(UDRIE0)
#define UART0_U2X _BV(U2X0)
#define UART0_ENABLE (_BV(RXCIE0) | _BV(RXEN0)| _BV(TXEN0))
#define UART0_FORMAT_8N1 (_BV(UCSZ01) | _BV(UCSZ00))
#define UART0_ERROR_FE _BV(FE0)
#define UART0_ERROR_DOR _BV(DOR0)
/* ATmega with two USART */
#elif defined(__AVR_ATmega162__) \
|| defined(__AVR_ATmega64__) \
|| defined(__AVR_ATmega128__) \
|| defined(__AVR_ATmega2560__) \
|| defined(__AVR_ATmega1280__) \
|| defined(__AVR_ATmega640__) \
|| defined(__AVR_ATmega164P__) \
|| defined(__AVR_ATmega324P__) \
|| defined(__AVR_ATmega644P__) \
|| defined(__AVR_ATmega1284P__)
#undef UART0_RXC_INT
#undef UART0_TXC_INT
#undef UART0_DRE_INT
#define UART0_STATUS UCSR0A
#define UART0_CONTROL UCSR0B
#define UART0_FORMAT UCSR0C
#define UART0_DATA UDR0
#define UART0_UBRRL UBRR0L
#define UART0_UBRRH UBRR0H
#define UART0_UDRIE _BV(UDRIE0)
#define UART0_U2X _BV(U2X0)
#define UART0_ENABLE (_BV(RXCIE0) | _BV(RXEN0)| _BV(TXEN0))
#define UART0_FORMAT_8N1 (_BV(UCSZ01) | _BV(UCSZ00))
#define UART0_ERROR_FE _BV(FE0)
#define UART0_ERROR_DOR _BV(DOR0)
#else
#error "No UART definition for MCU available"
#endif
#if !defined(USART0_RXC_INT)
#if defined(USART0_RX_vect)
#define UART0_RXC_INT USART0_RX_vect
#elif defined(USART_RX_vect)
#define UART0_RXC_INT USART_RX_vect
#elif defined(UART0_RXC_vect)
#define UART0_RXC_INT USART0_RXC_vect
#elif defined(UART_RXC_vect)
#define UART0_RXC_INT USART_RXC_vect
#else
#error "Couldn't find a usable interrupt vector for UART0_RXC_INT!"
#endif
#endif
#if !defined(USART0_TXC_INT)
#if defined(USART0_TX_vect)
#define UART0_TXC_INT USART0_TX_vect
#elif defined(USART_TX_vect)
#define UART0_TXC_INT USART_TX_vect
#elif defined(UART0_TXC_vect)
#define UART0_TXC_INT USART0_TXC_vect
#elif defined(UART_TXC_vect)
#define UART0_TXC_INT USART_TXC_vect
#else
#error "Couldn't find a usable interrupt vector for UART0_TXC_INT!"
#endif
#endif
#if !defined(USART0_DRE_INT)
#if defined(USART0_UDRE_vect)
#define UART0_DRE_INT USART0_UDRE_vect
#elif defined(USART_UDRE_vect)
#define UART0_DRE_INT USART_UDRE_vect
#else
#error "Couldn't find a usable interrupt vector for UART0_DRE_INT!"
#endif
#endif
#endif /* UART_QUIRKS_H */