Contiki 2.5
rs232_atmega128.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_ATMEGA128__
43 #define __RS232_ATMEGA128__
44 /******************************************************************************/
45 /*** Includes */
46 /******************************************************************************/
47 #include <avr/io.h>
48 
49 /******************************************************************************/
50 /*** RS232 ports */
51 /******************************************************************************/
52 #define RS232_PORT_0 0
53 #define RS232_PORT_1 1
54 
55 /******************************************************************************/
56 /*** Baud rates */
57 /******************************************************************************/
58 #if (F_CPU == 16000000UL)
59 /* Single speed operation (U2X = 0)*/
60 #define USART_BAUD_2400 416
61 #define USART_BAUD_4800 207
62 #define USART_BAUD_9600 103
63 #define USART_BAUD_14400 68
64 #define USART_BAUD_19200 51
65 #define USART_BAUD_28800 34
66 #define USART_BAUD_38400 25
67 #define USART_BAUD_57600 16
68 #define USART_BAUD_76800 12
69 #define USART_BAUD_115200 8
70 #define USART_BAUD_230400 3
71 #define USART_BAUD_250000 3
72 #define USART_BAUD_500000 1
73 #define USART_BAUD_1000000 0
74 #elif (F_CPU == 14745600UL)
75 /* Single speed operation (U2X = 0)*/
76 #define USART_BAUD_2400 383
77 #define USART_BAUD_4800 191
78 #define USART_BAUD_9600 95
79 #define USART_BAUD_14400 63
80 #define USART_BAUD_19200 47
81 #define USART_BAUD_28800 31
82 #define USART_BAUD_38400 23
83 #define USART_BAUD_57600 15
84 #define USART_BAUD_76800 11
85 #define USART_BAUD_115200 7
86 #define USART_BAUD_230400 3
87 #define USART_BAUD_250000 3
88 #define USART_BAUD_500000 1
89 #define USART_BAUD_1000000 0
90 #elif (F_CPU == 8000000UL)
91 /* Single speed operation (U2X = 0)*/
92 #define USART_BAUD_2400 207
93 #define USART_BAUD_4800 103
94 #define USART_BAUD_9600 51
95 #define USART_BAUD_14400 34
96 #define USART_BAUD_19200 25
97 #define USART_BAUD_28800 16
98 #define USART_BAUD_38400 12
99 #define USART_BAUD_57600 8
100 #define USART_BAUD_76800 6
101 #define USART_BAUD_115200 3
102 #define USART_BAUD_230400 1
103 #define USART_BAUD_250000 1
104 #define USART_BAUD_500000 0
105 /* For Micaz the MCU clock rate is 7.3728 MHz*/
106 #elif (F_CPU == 7372800UL)
107 /* Single speed operation (U2X = 0)*/
108 #define USART_BAUD_2400 191
109 #define USART_BAUD_4800 95
110 #define USART_BAUD_9600 47
111 #define USART_BAUD_14400 31
112 #define USART_BAUD_19200 23
113 #define USART_BAUD_28800 15
114 #define USART_BAUD_38400 11
115 #define USART_BAUD_57600 7
116 #define USART_BAUD_76800 5
117 #define USART_BAUD_115200 3
118 #define USART_BAUD_230400 1
119 #define USART_BAUD_250000 1
120 #define USART_BAUD_500000 0
121 #else
122 #error "Please define the baud rates for your CPU clock: ATmega128 handbook p. \
123 195-198 or set the rate in contiki-conf.h"
124 #endif
125 
126 
127 /******************************************************************************/
128 /*** Interrupt settings */
129 /******************************************************************************/
130 #define USART_INTERRUPT_RX_COMPLETE _BV (RXCIE)
131 #define USART_INTERRUPT_TX_COMPLETE _BV (TXCIE)
132 #define USART_INTERRUPT_DATA_REG_EMPTY _BV (UDRIE)
133 
134 /******************************************************************************/
135 /*** Receiver / transmitter */
136 /******************************************************************************/
137 #define USART_RECEIVER_ENABLE _BV (RXEN)
138 #define USART_TRANSMITTER_ENABLE _BV (TXEN)
139 
140 /******************************************************************************/
141 /*** Mode select */
142 /******************************************************************************/
143 #define USART_MODE_ASYNC 0x00
144 #define USART_MODE_SYNC _BV (UMSEL)
145 
146 /******************************************************************************/
147 /*** Parity */
148 /******************************************************************************/
149 #define USART_PARITY_NONE 0x00
150 #define USART_PARITY_EVEN _BV (UPM1)
151 #define USART_PARITY_ODD _BV (UPM1) | _BV (UPM0)
152 
153 /******************************************************************************/
154 /*** Stop bits */
155 /******************************************************************************/
156 #define USART_STOP_BITS_1 0x00
157 #define USART_STOP_BITS_2 _BV (USBS)
158 
159 /******************************************************************************/
160 /*** Character size */
161 /******************************************************************************/
162 #define USART_DATA_BITS_5 0x00
163 #define USART_DATA_BITS_6 _BV (UCSZ0)
164 #define USART_DATA_BITS_7 _BV (UCSZ1)
165 #define USART_DATA_BITS_8 _BV (UCSZ1) | _BV (UCSZ0)
166 // #define USART_DATA_BITS_9 (needs also UCSZ2 bit in UCSRnB)
167 
168 /******************************************************************************/
169 /*** Clock polarity */
170 /******************************************************************************/
171 #define USART_RISING_XCKN_EDGE 0x00
172 #define USART_FALLING_XCKN_EDGE _BV (UCPOL)
173 
174 #endif /* #ifndef __RS232_ATMEGA128__ */