X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/05437fb4cdb907816a4fc3ffafa2617fcf33266a..2c60e1dc26e1f424d9673541aebe778601070838:/avr/serial.c diff --git a/avr/serial.c b/avr/serial.c index e897c84..d3aeb4e 100644 --- a/avr/serial.c +++ b/avr/serial.c @@ -1,4 +1,7 @@ /* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -12,7 +15,7 @@ static int _write(char c, FILE *stream); -static FILE mystdout = FDEV_SETUP_STREAM(_write, +static FILE mystdout = FDEV_SETUP_STREAM(_write, NULL, _FDEV_SETUP_WRITE); @@ -24,7 +27,7 @@ static FILE mystdout = FDEV_SETUP_STREAM(_write, #endif #if ((BUFFER_SIZE) > 256) -# error: BUFFER_SIZE +# error: BUFFER_SIZE #endif struct ring rx_ring; @@ -42,15 +45,14 @@ void usart0_setup(unsigned long baud) { PRR0 &= ~_BV(PRUSART0); UCSR0B = 0; + UCSR0A = 0; + UBRR0 = (F_CPU + (baud/2) + 8) / baud / 16 - 1; + UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0); + UCSR0C = 3 << UCSZ00; /* Initialize ring buffers. */ ring_init(&rx_ring, rx_ring_buffer, BUFFER_SIZE); ring_init(&tx_ring, tx_ring_buffer, BUFFER_SIZE); - - UCSR0A = 0; - UBRR0 = F_CPU / baud / 16 - 1; - UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0); - UCSR0C = 3 << UCSZ00; }; } @@ -119,5 +121,3 @@ uint_fast8_t serial_tstc(void) { return !ring_is_empty(&rx_ring); } - -