30 #if defined(CONFIG_AVR_UART_AVAILABLE) && defined(CONFIG_AVR_UART_ENABLE) 32 volatile uint8_t g_uart_put_ptr = 0;
34 static uint8_t s_uart_get_ptr = 0;
35 static uint8_t s_uart_interrupt = 0;
43 #include <util/setbaud.h> 44 static const uint8_t ubrr0h_115200 = UBRRH_VALUE;
45 static const uint8_t ubrr0l_115200 = UBRRL_VALUE;
47 static const uint8_t u2x0_115200 = 1;
49 static const uint8_t u2x0_115200 = 0;
54 #include <util/setbaud.h> 55 static const uint8_t ubrr0h_57600 = UBRRH_VALUE;
56 static const uint8_t ubrr0l_57600 = UBRRL_VALUE;
58 static const uint8_t u2x0_57600 = 1;
60 static const uint8_t u2x0_57600 = 0;
65 #include <util/setbaud.h> 66 static const uint8_t ubrr0h_38400 = UBRRH_VALUE;
67 static const uint8_t ubrr0l_38400 = UBRRL_VALUE;
69 static const uint8_t u2x0_38400 = 1;
71 static const uint8_t u2x0_38400 = 0;
76 #include <util/setbaud.h> 77 static const uint8_t ubrr0h_19200 = UBRRH_VALUE;
78 static const uint8_t ubrr0l_19200 = UBRRL_VALUE;
80 static const uint8_t u2x0_19200 = 1;
82 static const uint8_t u2x0_19200 = 0;
85 void uart_init_internal(uint32_t baud, uint8_t interrupt)
87 s_uart_interrupt = interrupt;
91 UBRR0H = ubrr0h_19200;
92 UBRR0L = ubrr0l_19200;
93 if (u2x0_19200) UCSR0A |= _BV(U2X0);
else UCSR0A &= ~(_BV(U2X0));
96 UBRR0H = ubrr0h_38400;
97 UBRR0L = ubrr0l_38400;
98 if (u2x0_38400) UCSR0A |= _BV(U2X0);
else UCSR0A &= ~(_BV(U2X0));
101 UBRR0H = ubrr0h_57600;
102 UBRR0L = ubrr0l_57600;
103 if (u2x0_57600) UCSR0A |= _BV(U2X0);
else UCSR0A &= ~(_BV(U2X0));
106 UBRR0H = ubrr0h_115200;
107 UBRR0L = ubrr0l_115200;
108 if (u2x0_115200) UCSR0A |= _BV(U2X0);
else UCSR0A &= ~(_BV(U2X0));
113 UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
114 UCSR0B = _BV(RXEN0) | _BV(TXEN0) | (s_uart_interrupt ? _BV(RXCIE0) : 0);
119 loop_until_bit_is_set(UCSR0A, UDRE0);
123 static inline uint8_t uart_byte_available_direct(
void)
125 return bit_is_set(UCSR0A, RXC0);
130 if (!s_uart_interrupt)
132 while (uart_byte_available_direct()) __uart_read_byte();
134 return g_uart_put_ptr != s_uart_get_ptr;
139 uint8_t data = g_uart_buf[s_uart_get_ptr];
uint8_t uart_read_byte(void)
Reads byte from UART RX buffer.
uint8_t uart_byte_available(void)
Returns non-zero code if there are bytes in RX buffer.
void uart_send_byte(uint8_t c)
Sends single byte over UART.