# HG changeset patch # User darius@Inchoate # Date 1236754719 -37800 # Node ID 15d89caaf516e0c4c392b90aad1dac22ae0daf33 # Parent 43d3b2bef9991862c587b69a0ab71a48af5d6538 Add support for single UART devices, although untested apart from a compile. Doesn't break dual UART ones :) Also checks for PRR before setting it. diff -r 43d3b2bef999 -r 15d89caaf516 cons.c --- a/cons.c Wed Mar 11 17:10:13 2009 +1030 +++ b/cons.c Wed Mar 11 17:28:39 2009 +1030 @@ -36,6 +36,10 @@ #define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16l)-1) +#ifdef UBRR0 +#define DUALUART +#endif + /* Receive buffer storage */ consbuf_t cmd; @@ -60,12 +64,22 @@ void cons_init(void) { +#ifdef DUALUART UBRR0 = UART_BAUD_SELECT(38400, F_CPU); /* 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 fdevopen(_putc, NULL); /* Open stdout */ fdevopen(NULL, _getc); /* Open stdin */ @@ -73,8 +87,13 @@ 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 return(0); } @@ -114,26 +133,41 @@ char cons_getc(void) { +#ifdef DUALUART while (!(UCSR0A & _BV(RXC0))) ; - return (UDR0); +#else + while (!(UCSRA & _BV(RXC))) + ; + return (UDR); +#endif } /* Rx complete */ +#ifdef DUALUART ISR(USART0_RX_vect) { - volatile char pit; +#else +ISR(USART_RXC_vect) { +#endif char c; +#ifdef DUALUART while (UCSR0A & _BV(RXC0)) { +#else + while (UCSRA & _BV(RXC)) { +#endif + +#ifdef DUALUART + c = UDR0; +#else + c = UDR; +#endif /* 255 means we're waiting for main to process the command, - just throw stuff away - */ - if (cmd.state == 255) { - pit = UDR0; + * just throw stuff away + */ + if (cmd.state == 255) continue; - } - c = UDR0; /* End of line? */ if (c == '\n' || c == '\r') { @@ -173,7 +207,10 @@ } /* Tx complete */ +#ifdef DUALUART ISR(USART0_TX_vect) { - +#else +ISR(USART_TXC_vect) { +#endif } diff -r 43d3b2bef999 -r 15d89caaf516 ds1307.c --- a/ds1307.c Wed Mar 11 17:10:13 2009 +1030 +++ b/ds1307.c Wed Mar 11 17:28:39 2009 +1030 @@ -46,9 +46,11 @@ */ int ds1307_init(void) { +#ifdef PRR PRR &= _BV(PRTWI); /* Power TWI on - note that the * datasheet says this is already 0 at * power on.. */ +#endif TWSR = 0; /* TWI Prescaler = 1 */ #if F_CPU < 3600000UL TWBR = 10; /* Smallest valid TWBR */