Mercurial > ~darius > hgwebdir.cgi > avr-lib
diff cons.c @ 4:095216e8453d
Hide register name abstraction in a separate file.
author | darius@Inchoate |
---|---|
date | Thu, 12 Mar 2009 16:30:47 +1030 |
parents | 15d89caaf516 |
children | b46f0c742316 |
line wrap: on
line diff
--- a/cons.c Wed Mar 11 17:28:39 2009 +1030 +++ b/cons.c Thu Mar 12 16:30:47 2009 +1030 @@ -1,7 +1,7 @@ /* * Console code for AVR board * - * Copyright (c) 2008 + * Copyright (c) 2008-2009 * Daniel O'Connor <darius@dons.net.au>. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,13 +33,10 @@ #include <avr/interrupt.h> #include <avr/pgmspace.h> #include "cons.h" +#include "cons-reg.h" #define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16l)-1) -#ifdef UBRR0 -#define DUALUART -#endif - /* Receive buffer storage */ consbuf_t cmd; @@ -64,36 +61,19 @@ void cons_init(void) { -#ifdef DUALUART - UBRR0 = UART_BAUD_SELECT(38400, F_CPU); + _SETBAUD(38400); /* Enable receiver and transmitter. Turn on rx interrupts */ - UCSR0A = 0; - UCSR0B = _BV(RXEN0) | _BV(TXEN0) | _BV(RXCIE0); - UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); -#else - UBRRH = UART_BAUD_SELECT(38400, F_CPU) >> 8; - UBRRL = (uint8_t)UART_BAUD_SELECT(38400, F_CPU); - - /* Enable receiver and transmitter. Turn on rx interrupts */ - UCSRA = 0; - UCSRB = _BV(RXEN) | _BV(TXEN) | _BV(RXCIE); - UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); -#endif - + _INITREG(); + fdevopen(_putc, NULL); /* Open stdout */ fdevopen(NULL, _getc); /* Open stdin */ } int cons_putc(char c) { -#ifdef DUALUART - loop_until_bit_is_set(UCSR0A, UDRE0); - UDR0 = c; -#else - loop_until_bit_is_set(UCSRA, UDRE); - UDR = c; -#endif + loop_until_bit_is_set(_UCSRA, _UDRE); + _UDR = c; return(0); } @@ -133,36 +113,17 @@ char cons_getc(void) { -#ifdef DUALUART - while (!(UCSR0A & _BV(RXC0))) + while (!(_UCSRA & _BV(_RXC))) ; - return (UDR0); -#else - while (!(UCSRA & _BV(RXC))) - ; - return (UDR); -#endif + return (_UDR); } /* Rx complete */ -#ifdef DUALUART -ISR(USART0_RX_vect) { -#else -ISR(USART_RXC_vect) { -#endif +ISR(_RXVECT) { char c; -#ifdef DUALUART - while (UCSR0A & _BV(RXC0)) { -#else - while (UCSRA & _BV(RXC)) { -#endif - -#ifdef DUALUART - c = UDR0; -#else - c = UDR; -#endif + while (_UCSRA & _BV(_RXC)) { + c = _UDR; /* 255 means we're waiting for main to process the command, * just throw stuff away */ @@ -207,10 +168,6 @@ } /* Tx complete */ -#ifdef DUALUART -ISR(USART0_TX_vect) { -#else -ISR(USART_TXC_vect) { -#endif +ISR(_TXVECT) { }