Reset ringbuffer when calling uart_init()
This commit is contained in:
parent
55056f94f0
commit
91025af29e
@ -3,6 +3,9 @@ int uart_getchar(FILE *stream);
|
|||||||
|
|
||||||
void uart_init(void);
|
void uart_init(void);
|
||||||
|
|
||||||
|
struct rx_ring;
|
||||||
|
struct tx_ring;
|
||||||
|
|
||||||
/* http://www.ermicro.com/blog/?p=325 */
|
/* http://www.ermicro.com/blog/?p=325 */
|
||||||
|
|
||||||
FILE uart_output = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
|
FILE uart_output = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
/* Based on Atmel Application Note AVR 306 */
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -33,6 +35,13 @@ static struct rx_ring rx_buffer;
|
|||||||
/* http://www.cs.mun.ca/~rod/Winter2007/4723/notes/serial/serial.html */
|
/* http://www.cs.mun.ca/~rod/Winter2007/4723/notes/serial/serial.html */
|
||||||
|
|
||||||
void uart_init(void) {
|
void uart_init(void) {
|
||||||
|
|
||||||
|
tx_buffer.start = 0;
|
||||||
|
tx_buffer.end = 0;
|
||||||
|
|
||||||
|
rx_buffer.start = 0;
|
||||||
|
rx_buffer.end = 0;
|
||||||
|
|
||||||
UBRR0H = UBRRH_VALUE;
|
UBRR0H = UBRRH_VALUE;
|
||||||
UBRR0L = UBRRL_VALUE;
|
UBRR0L = UBRRL_VALUE;
|
||||||
|
|
||||||
@ -80,7 +89,7 @@ ISR(USART_RX_vect) {
|
|||||||
ISR(USART_UDRE_vect){
|
ISR(USART_UDRE_vect){
|
||||||
int read_pointer = (tx_buffer.start + 1) % UART_TX_BUFFER_SIZE;
|
int read_pointer = (tx_buffer.start + 1) % UART_TX_BUFFER_SIZE;
|
||||||
|
|
||||||
/* Transit next byte if data available in ringbuffer. */
|
/* Transmit next byte if data available in ringbuffer. */
|
||||||
if (read_pointer != tx_buffer.end) {
|
if (read_pointer != tx_buffer.end) {
|
||||||
UDR0 = tx_buffer.buffer[read_pointer];
|
UDR0 = tx_buffer.buffer[read_pointer];
|
||||||
tx_buffer.start = read_pointer;
|
tx_buffer.start = read_pointer;
|
||||||
|
Loading…
Reference in New Issue
Block a user