Factor uart code into separate driver code

This commit is contained in:
Nero 2018-01-29 00:50:22 +00:00 committed by Nero
parent 24ee77720d
commit 122c0e6c35
5 changed files with 31 additions and 14 deletions

10
drivers/uart.c Normal file
View file

@ -0,0 +1,10 @@
#include "uart.h"
#include <avr/io.h>
#define BAUD_PRESCALE (((F_CPU/(BAUDRATE*8UL)))-1)
void __attribute__ ((naked)) __attribute__ ((section (".init5"))) uart_init() {
UCSR0A = (1<<U2X0);
UCSR0C = (1<<UCSZ00) | (1<<UCSZ01); // 8N1
UBRR0 = BAUD_PRESCALE;
}

0
drivers/uart.h Normal file
View file

16
drivers/uart_rx_async.c Normal file
View file

@ -0,0 +1,16 @@
#include "uart_rx_async.h"
#include "uart.h"
#include <avr/io.h>
#include <avr/interrupt.h>
void __attribute__ ((naked)) __attribute__ ((section (".init6"))) uart_rx_async_init() {
UCSR0B = (1<<RXEN0) | (1<<RXCIE0);
}
void __attribute__ ((naked)) __attribute__ ((section (".init8"))) uart_rx_sei() {
sei();
}
ISR(USART_RX_vect) {
uart_process(UDR0);
}

3
drivers/uart_rx_async.h Normal file
View file

@ -0,0 +1,3 @@
#include <stdint.h>
extern void uart_process(uint8_t c);