Whitespace.
This commit is contained in:
parent
7aa4de63c6
commit
55056f94f0
@ -16,15 +16,15 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct tx_ring {
|
struct tx_ring {
|
||||||
int buffer[UART_TX_BUFFER_SIZE];
|
int buffer[UART_TX_BUFFER_SIZE];
|
||||||
int start;
|
int start;
|
||||||
int end;
|
int end;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct rx_ring {
|
struct rx_ring {
|
||||||
int buffer[UART_RX_BUFFER_SIZE];
|
int buffer[UART_RX_BUFFER_SIZE];
|
||||||
int start;
|
int start;
|
||||||
int end;
|
int end;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct tx_ring tx_buffer;
|
static struct tx_ring tx_buffer;
|
||||||
@ -46,48 +46,48 @@ int uart_putchar(char c, FILE *stream) {
|
|||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
uart_putchar('\r', stream);
|
uart_putchar('\r', stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
int write_pointer = (tx_buffer.end + 1) % UART_TX_BUFFER_SIZE;
|
int write_pointer = (tx_buffer.end + 1) % UART_TX_BUFFER_SIZE;
|
||||||
|
|
||||||
if (write_pointer != tx_buffer.start){
|
if (write_pointer != tx_buffer.start){
|
||||||
tx_buffer.buffer[tx_buffer.end] = c;
|
tx_buffer.buffer[tx_buffer.end] = c;
|
||||||
tx_buffer.end = write_pointer;
|
tx_buffer.end = write_pointer;
|
||||||
|
|
||||||
/* Data available. Enable the transmit interrupt for serial port 0. */
|
/* Data available. Enable the transmit interrupt for serial port 0. */
|
||||||
UCSR0B |= _BV(UDRIE0);
|
UCSR0B |= _BV(UDRIE0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uart_getchar(FILE *stream) {
|
int uart_getchar(FILE *stream) {
|
||||||
int read_pointer = (rx_buffer.start + 1) % UART_RX_BUFFER_SIZE;
|
int read_pointer = (rx_buffer.start + 1) % UART_RX_BUFFER_SIZE;
|
||||||
|
|
||||||
rx_buffer.start = read_pointer;
|
rx_buffer.start = read_pointer;
|
||||||
return rx_buffer.buffer[read_pointer];
|
return rx_buffer.buffer[read_pointer];
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(USART_RX_vect) {
|
ISR(USART_RX_vect) {
|
||||||
int write_pointer = (rx_buffer.end + 1) % UART_RX_BUFFER_SIZE;
|
int write_pointer = (rx_buffer.end + 1) % UART_RX_BUFFER_SIZE;
|
||||||
|
|
||||||
/* Add next byte to ringbuffer if it has space available. */
|
/* Add next byte to ringbuffer if it has space available. */
|
||||||
if (write_pointer != rx_buffer.start){
|
if (write_pointer != rx_buffer.start){
|
||||||
rx_buffer.buffer[rx_buffer.end] = UDR0;
|
rx_buffer.buffer[rx_buffer.end] = UDR0;
|
||||||
rx_buffer.end = write_pointer;
|
rx_buffer.end = write_pointer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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. */
|
/* Transit 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;
|
||||||
} else {
|
} else {
|
||||||
/* Nothing to send. Disable the transmit interrupt for serial port 0. */
|
/* Nothing to send. Disable the transmit interrupt for serial port 0. */
|
||||||
UCSR0B &= ~_BV(UDRIE0);
|
UCSR0B &= ~_BV(UDRIE0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user