36 lines
590 B
C
36 lines
590 B
C
#include <avr/io.h>
|
|
#include <stdlib.h>
|
|
#include "usart.h"
|
|
#include "conf.h"
|
|
#include "ringbuffer.h"
|
|
|
|
volatile ringbuffer_t usart_buffer;
|
|
|
|
|
|
void
|
|
usart_init(void)
|
|
{
|
|
usart_buffer = ringbuffer_new(USART_BUFFER_SIZE);
|
|
UBRRH = (unsigned char)(UBRR_VALUE >> 8);
|
|
UBRRL = (unsigned char)UBRR_VALUE;
|
|
UCSRB = _BV(TXEN) | _BV(TXCIE);
|
|
UCSRC = _BV(USBS) | _BV(UCSZ0) | _BV(UCSZ1);
|
|
}
|
|
|
|
int
|
|
usart_putc(char c)
|
|
{
|
|
return ringbuffer_put_char(usart_buffer, c);
|
|
}
|
|
|
|
|
|
|
|
ISR(USART_TX_vect)
|
|
{
|
|
if(ringbuffer_nonempty(usart_buffer))
|
|
{
|
|
while(!(UCSRA & UDRE));
|
|
UDR = ringbuffer_get_char(usart_buffer);
|
|
}
|
|
}
|