annotate cons-reg.h @ 16:3aac1bb54918

Add missing J delay for AVR.
author Daniel O'Connor <darius@dons.net.au>
date Tue, 08 Jan 2013 09:55:23 +1030
parents f0b4314b91ec
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
1 /*
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
2 * Register abstraction for console code
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
3 *
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
4 * Copyright (c) 2008-2009
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved.
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
6 *
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
7 * Redistribution and use in source and binary forms, with or without
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
8 * modification, are permitted provided that the following conditions
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
9 * are met:
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
10 * 1. Redistributions of source code must retain the above copyright
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer.
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
15 *
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
26 * SUCH DAMAGE.
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
27 */
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
28
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
29 /* Decide what registers and ISRs to use */
10
f0b4314b91ec Fix for dual UART devices.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
30 #ifdef UBRR0L
4
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
31 /* Dual UART devices (eg ATMega324p) */
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
32 #define _SETBAUD(x) do { \
10
f0b4314b91ec Fix for dual UART devices.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
33 UBRR0L = (UART_BAUD_SELECT(x, F_CPU) & 0xff); \
f0b4314b91ec Fix for dual UART devices.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
34 UBRR0H = (UART_BAUD_SELECT(x, F_CPU) << 8) & 0xff; \
4
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
35 } while(0)
10
f0b4314b91ec Fix for dual UART devices.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
36
4
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
37 #define _INITREG() do { \
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
38 UCSR0A = 0; \
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
39 UCSR0B = _BV(RXEN0) | _BV(TXEN0) | _BV(RXCIE0); \
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
40 UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); \
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
41 } while(0)
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
42 #define _UCSRA UCSR0A
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
43 #define _UDRE UDRE0
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
44 #define _RXC RXC0
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
45 #define _RXVECT USART0_RX_vect
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
46 #define _TXVECT USART0_TX_vect
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
47 #define _UDR UDR0
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
48 #else
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
49 #define _SETBAUD(x) do { \
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
50 UBRRH = UART_BAUD_SELECT(x, F_CPU) >> 8; \
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
51 UBRRH = UART_BAUD_SELECT(x, F_CPU) & 0xff; \
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
52 } while(0)
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
53 #define _INITREG() do { \
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
54 UCSRA = 0; \
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
55 UCSRB = _BV(RXEN) | _BV(TXEN) | _BV(RXCIE); \
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
56 UCSRC = _BV(UCSZ1) | _BV(UCSZ0); \
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
57 } while(0)
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
58 #define _UCSRA UCSRA
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
59 #define _UDRE UDRE
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
60 #define _RXC RXC
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
61 #define _UDR UDR
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
62
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
63 /* Handle vector name inconsistencies */
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
64 #ifdef USART_RXC_vect
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
65 #define _RXVECT USART_RXC_vect
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
66 #define _TXVECT USART_TXC_vect
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
67 #else
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
68 #define _RXVECT USART_RX_vect
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
69 #define _TXVECT USART_TX_vect
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
70 #endif
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
71 #endif
095216e8453d Hide register name abstraction in a separate file.
darius@Inchoate
parents:
diff changeset
72