diff options
Diffstat (limited to 'src/avr/serial.c')
-rw-r--r-- | src/avr/serial.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/src/avr/serial.c b/src/avr/serial.c index 3aff121f..3221b6f0 100644 --- a/src/avr/serial.c +++ b/src/avr/serial.c @@ -25,29 +25,41 @@ static uint8_t transmit_pos, transmit_max; DECL_CONSTANT(SERIAL_BAUD, CONFIG_SERIAL_BAUD); +// Define serial port registers on AT90USB1286 +#if !defined(UCSR0A) && defined(UCSR1A) +#define UCSR0A UCSR1A +#define UCSR0B UCSR1B +#define UCSR0C UCSR1C +#define UBRR0 UBRR1 +#define UDR0 UDR1 +#define UCSZ01 UCSZ11 +#define UCSZ00 UCSZ10 +#define U2X0 U2X1 +#define RXEN0 RXEN1 +#define TXEN0 TXEN1 +#define RXCIE0 RXCIE1 +#define UDRIE0 UDRIE1 +#define USART0_RX_vect USART1_RX_vect +#define USART0_UDRE_vect USART1_UDRE_vect +#endif + +// Define serial port registers on atmega168 / atmega328 +#if defined(USART_RX_vect) +#define USART0_RX_vect USART_RX_vect +#define USART0_UDRE_vect USART_UDRE_vect +#endif + void serial_init(void) { - if (CONFIG_SERIAL_BAUD_U2X) { - UCSR0A = 1<<U2X0; - UBRR0 = DIV_ROUND_CLOSEST( - CONFIG_CLOCK_FREQ, 8UL * CONFIG_SERIAL_BAUD) - 1UL; - } else { - UCSR0A = 0; - UBRR0 = DIV_ROUND_CLOSEST( - CONFIG_CLOCK_FREQ, 16UL * CONFIG_SERIAL_BAUD) - 1UL; - } - + UCSR0A = CONFIG_SERIAL_BAUD_U2X ? (1<<U2X0) : 0; + uint32_t cm = CONFIG_SERIAL_BAUD_U2X ? 8 : 16; + UBRR0 = DIV_ROUND_CLOSEST(CONFIG_CLOCK_FREQ, cm * CONFIG_SERIAL_BAUD) - 1UL; UCSR0C = (1<<UCSZ01) | (1<<UCSZ00); UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0) | (1<<UDRIE0); } DECL_INIT(serial_init); -#ifdef USART_RX_vect -#define USART0_RX_vect USART_RX_vect -#define USART0_UDRE_vect USART_UDRE_vect -#endif - // Rx interrupt - data available to be read. ISR(USART0_RX_vect) { |