Contiki-Inga 3.x
rs232_atxmega256a3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006, Technical University of Munich
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  * @(#)$$
32  */
33 
34 /**
35  * \file
36  * AVR specific definitions for the rs232 port.
37  *
38  * \author
39  * Simon Barner <barner@in.tum.de
40  */
41 
42 #ifndef __RS232_ATXMEGA256A3__
43 #define __RS232_ATXMEGA256A3__
44 /******************************************************************************/
45 /*** Includes */
46 /******************************************************************************/
47 #include <avr/io.h>
48 
49 /******************************************************************************/
50 /*** RS232 ports */
51 /******************************************************************************/
52 
53 #define RS232_0 USARTE0
54 #define RS232_1 USARTF0
55 
56 #define RS232_USARTE0 0
57 #define RS232_USARTF0 1
58 
59 #define RS232_PORT_0 0
60 #define RS232_PORT_1 1
61 
62 #define RS232_COUNT 2
63 
64 /******************************************************************************/
65 /*** Baud rates */
66 /******************************************************************************/
67 
68 #if (F_CPU == 48000000UL)
69  #define USART_BAUD_2400 0x04E1
70  #define USART_BAUD_4800 0x0270
71  #define USART_BAUD_9600 0xD9BC
72  #define USART_BAUD_14400 0xCCF5
73  #define USART_BAUD_19200 0xC9B4
74  #define USART_BAUD_28800 0xBCE5
75  #define USART_BAUD_38400 0xB9A4
76  #define USART_BAUD_57600 0xACC5
77  #define USART_BAUD_76800 0xA984
78  #define USART_BAUD_115200 0x9C85
79  #define USART_BAUD_230400 0x9603
80  #define USART_BAUD_250000 0x000B
81  #define USART_BAUD_500000 0x0005
82  #define USART_BAUD_1000000 0x0002
83 #elif (F_CPU == 32000000UL)
84 /* Single speed operation (U2X = 0)*/
85  #define USART_BAUD_2400 0x0340
86  #define USART_BAUD_4800 0xDCFD
87  #define USART_BAUD_9600 0xCCF5
88  #define USART_BAUD_14400 0xC89E
89  #define USART_BAUD_19200 0xBCE5
90  #define USART_BAUD_28800 0xB88E
91  #define USART_BAUD_38400 0xACC5
92  #define USART_BAUD_57600 0xA86E
93  #define USART_BAUD_76800 0x9C85
94  #define USART_BAUD_115200 0x982E
95  #define USART_BAUD_230400 0x93D7
96  #define USART_BAUD_250000 0x0007
97  #define USART_BAUD_500000 0x0003
98  #define USART_BAUD_1000000 0x0001
99 #elif (F_CPU == 18000000UL)
100  #define USART_BAUD_2400 0xDE9E
101  #define USART_BAUD_4800 0xCE96
102  #define USART_BAUD_9600 0xBE86
103  #define USART_BAUD_14400 0xB9A4
104  #define USART_BAUD_19200 0xAE66
105  #define USART_BAUD_28800 0xA984
106  #define USART_BAUD_38400 0x9E26
107  #define USART_BAUD_57600 0x9944
108  #define USART_BAUD_76800 0x96D3
109  #define USART_BAUD_115200 0x9462
110  #define USART_BAUD_230400 0x91F1
111  #define USART_BAUD_250000 0x91C0
112  #define USART_BAUD_500000 0x90A0
113  #define USART_BAUD_1000000 0x9010
114 #elif (F_CPU == 20000000UL)
115  #define USART_BAUD_2400 0xE81F
116  #define USART_BAUD_4800 0xD81B
117  #define USART_BAUD_9600 0xC813
118  #define USART_BAUD_14400 0xBABA
119  #define USART_BAUD_19200 0xB803
120  #define USART_BAUD_28800 0xAA9A
121  #define USART_BAUD_38400 0x9FC7
122  #define USART_BAUD_57600 0x9A5A
123  #define USART_BAUD_76800 0x97A3
124  #define USART_BAUD_115200 0x94ED
125  #define USART_BAUD_230400 0x9236
126  #define USART_BAUD_250000 0x0004
127  #define USART_BAUD_500000 0x90C0
128  #define USART_BAUD_1000000 0x9020
129 #elif (F_CPU == 16000000UL)
130 /* Single speed operation (U2X = 0)*/
131  #define USART_BAUD_2400 0xDCFD
132  #define USART_BAUD_4800 0xCCF5
133  #define USART_BAUD_9600 0xBCE5
134  #define USART_BAUD_14400 0xB88E
135  #define USART_BAUD_19200 0xACC5
136  #define USART_BAUD_28800 0xA86E
137  #define USART_BAUD_38400 0x9C85
138  #define USART_BAUD_57600 0x982E
139  #define USART_BAUD_76800 0x9603
140  #define USART_BAUD_115200 0x93D7
141  #define USART_BAUD_230400 0x91AC
142  #define USART_BAUD_250000 0x0003
143  #define USART_BAUD_500000 0x0001
144  #define USART_BAUD_1000000 0x0001
145 #elif (F_CPU == 12000000UL)
146  #define USART_BAUD_2400 0xD9BC
147  #define USART_BAUD_4800 0xC9B4
148  #define USART_BAUD_9600 0xB9A4
149  #define USART_BAUD_14400 0xACC5
150  #define USART_BAUD_19200 0xA984
151  #define USART_BAUD_28800 0x9C85
152  #define USART_BAUD_38400 0x9944
153  #define USART_BAUD_57600 0x9603
154  #define USART_BAUD_76800 0x9462
155  #define USART_BAUD_115200 0x92C1
156  #define USART_BAUD_230400 0x9121
157  #define USART_BAUD_250000 0x0002
158  #define USART_BAUD_500000 0x9040
159  #define USART_BAUD_1000000 0x9040
160 #elif (F_CPU == 8000000UL)
161 /* Single speed operation (U2X = 0)*/
162  #define USART_BAUD_2400 0xCCF5
163  #define USART_BAUD_4800 0xBCE5
164  #define USART_BAUD_9600 0xACC5
165  #define USART_BAUD_14400 0xA86E
166  #define USART_BAUD_19200 0x9C85
167  #define USART_BAUD_28800 0x982E
168  #define USART_BAUD_38400 0x9603
169  #define USART_BAUD_57600 0x93D7
170  #define USART_BAUD_76800 0x92C1
171  #define USART_BAUD_115200 0x91AC
172  #define USART_BAUD_230400 0x9096
173  #define USART_BAUD_250000 0x0001
174  #define USART_BAUD_500000 0x0001
175  #define USART_BAUD_1000000 0x0001
176 #elif (F_CPU == 6000000UL)
177  #define USART_BAUD_2400 0xC9B4
178  #define USART_BAUD_4800 0xB9A4
179  #define USART_BAUD_9600 0xA984
180  #define USART_BAUD_14400 0x9C85
181  #define USART_BAUD_19200 0x9944
182  #define USART_BAUD_28800 0x9603
183  #define USART_BAUD_38400 0x9462
184  #define USART_BAUD_57600 0x92C1
185  #define USART_BAUD_76800 0x91F1
186  #define USART_BAUD_115200 0x9121
187  #define USART_BAUD_230400 0x9050
188  #define USART_BAUD_250000 0x9040
189  #define USART_BAUD_500000 0x9040
190  #define USART_BAUD_1000000 0x9040
191 #elif (F_CPU == 4000000UL)
192  #define USART_BAUD_2400 0xBCE5
193  #define USART_BAUD_4800 0xACC5
194  #define USART_BAUD_9600 0x9C85
195  #define USART_BAUD_14400 0x982E
196  #define USART_BAUD_19200 0x9603
197  #define USART_BAUD_28800 0x93D7
198  #define USART_BAUD_38400 0x92C1
199  #define USART_BAUD_57600 0x91AC
200  #define USART_BAUD_76800 0x9121
201  #define USART_BAUD_115200 0x9096
202  #define USART_BAUD_230400 0x900B
203  #define USART_BAUD_250000 0x900B
204  #define USART_BAUD_500000 0x900B
205  #define USART_BAUD_1000000 0x900B
206 #elif (F_CPU == 2000000UL)
207  #define USART_BAUD_2400 0xACC5
208  #define USART_BAUD_4800 0x9C85
209  #define USART_BAUD_9600 0x9603
210  #define USART_BAUD_14400 0x93D7
211  #define USART_BAUD_19200 0x92C1
212  #define USART_BAUD_28800 0x91AC
213  #define USART_BAUD_38400 0x9121
214  #define USART_BAUD_57600 0x9096
215  #define USART_BAUD_76800 0x9050
216  #define USART_BAUD_115200 0x900B
217  #define USART_BAUD_230400 0x900B
218  #define USART_BAUD_250000 0x900B
219  #define USART_BAUD_500000 0x900B
220  #define USART_BAUD_1000000 0x900B
221 #else
222  #error "Please define the baud rates for your CPU clock or set the rate in contiki-conf.h"
223 #endif
224 
225 
226 /******************************************************************************/
227 /*** Interrupt settings */
228 /******************************************************************************/
229 
230 #define USART_INTERRUPT_RX_COMPLETE USART_RXCIF_bm
231 #define USART_INTERRUPT_TX_COMPLETE USART_TXCIF_bm
232 #define USART_INTERRUPT_DATA_REG_EMPTY USART_DREIF_bm
233 
234 
235 /******************************************************************************/
236 /*** Receiver / transmitter */
237 /******************************************************************************/
238 
239 #define USART_RECEIVER_ENABLE USART_RXEN_bm
240 #define USART_TRANSMITTER_ENABLE USART_TXEN_bm
241 
242 /******************************************************************************/
243 /*** Mode select */
244 /******************************************************************************/
245 
246 /* p.308 */
247 #define USART_MODE_ASYNC 0x00 /* 00XXXXXX */
248 #define USART_MODE_SYNC 0x40 /* 01XXXXXX */
249 #define USART_MODE_IRCOM 0x80 /* 10XXXXXX */
250 #define USART_MODE_MSPI 0xC0 /* 11XXXXXX */
251 
252 /******************************************************************************/
253 /*** Parity */
254 /******************************************************************************/
255 
256 /* p.308 */
257 #define USART_PARITY_NONE 0x00 /* XX00XXXX */
258 #define USART_PARITY_EVEN 0x20 /* XX10XXXX */
259 #define USART_PARITY_ODD 0x30 /* XX11XXXX */
260 
261 
262 /******************************************************************************/
263 /*** Stop bits */
264 /******************************************************************************/
265 
266 /* p.309 */
267 #define USART_STOP_BITS_1 0x00 /* XXXX0XXX */
268 #define USART_STOP_BITS_2 0x08 /* XXXX1XXX */
269 
270 /******************************************************************************/
271 /*** Character size */
272 /******************************************************************************/
273 
274 /* p.309 */
275 #define USART_DATA_BITS_5 0x00 /* XXXXX000 */
276 #define USART_DATA_BITS_6 0x01 /* XXXXX001 */
277 #define USART_DATA_BITS_7 0x02 /* XXXXX010 */
278 #define USART_DATA_BITS_8 0x03 /* XXXXX011 */
279 #define USART_DATA_BITS_9 0x07 /* XXXXX111 */
280 
281 /******************************************************************************/
282 /*** Clock polarity */
283 /******************************************************************************/
284 
285 /*
286 #define USART_RISING_XCKN_EDGE 0x00
287 #define USART_FALLING_XCKN_EDGE _BV (UCPOL0)
288 */
289 
290 #endif /* #ifndef __RS232_ATXMEGA256A3__ */