From bfe7a2ad84dc62e2b32a2c22ef9ffb338f2c56a1 Mon Sep 17 00:00:00 2001 From: Simen Svale Skogsrud Date: Fri, 3 Jun 2011 15:42:28 +0200 Subject: [PATCH] flossed the serial module --- serial.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/serial.c b/serial.c index 01cf8c1..1d0cb41 100644 --- a/serial.c +++ b/serial.c @@ -71,13 +71,12 @@ void serial_write(uint8_t data) { tx_buffer[tx_buffer_head] = data; tx_buffer_head = next_head; - // Enable Data Register Empty Interrupt + // Enable Data Register Empty Interrupt to make sure tx-streaming is running UCSR0B |= (1 << UDRIE0); } // Data Register Empty Interrupt handler -SIGNAL(USART_UDRE_vect) { - +SIGNAL(USART_UDRE_vect) { // temporary tx_buffer_tail (to optimize for volatile) uint8_t tail = tx_buffer_tail; @@ -87,15 +86,17 @@ SIGNAL(USART_UDRE_vect) { // Update tail position tail ++; tail %= TX_BUFFER_SIZE; - tx_buffer_tail = tail; - // Turn off Data Register Empty Interrupt if this concludes the transfer + // Turn off Data Register Empty Interrupt to stop tx-streaming if this concludes the transfer if (tail == tx_buffer_head) { UCSR0B &= ~(1 << UDRIE0); } + + tx_buffer_tail = tail; } uint8_t serial_read() { if (rx_buffer_head != rx_buffer_tail) { + // Return magic number if no data pending return 0xff; } else { uint8_t data = rx_buffer[rx_buffer_tail];