diff options
Diffstat (limited to 'platforms/avr/drivers')
-rw-r--r-- | platforms/avr/drivers/uart.c | 26 | ||||
-rw-r--r-- | platforms/avr/drivers/uart.h | 8 |
2 files changed, 25 insertions, 9 deletions
diff --git a/platforms/avr/drivers/uart.c b/platforms/avr/drivers/uart.c index c6abcb6fe..01cf6b1fb 100644 --- a/platforms/avr/drivers/uart.c +++ b/platforms/avr/drivers/uart.c | |||
@@ -100,7 +100,7 @@ void uart_init(uint32_t baud) { | |||
100 | } | 100 | } |
101 | 101 | ||
102 | // Transmit a byte | 102 | // Transmit a byte |
103 | void uart_putchar(uint8_t c) { | 103 | void uart_write(uint8_t data) { |
104 | uint8_t i; | 104 | uint8_t i; |
105 | 105 | ||
106 | i = tx_buffer_head + 1; | 106 | i = tx_buffer_head + 1; |
@@ -110,27 +110,39 @@ void uart_putchar(uint8_t c) { | |||
110 | while (tx_buffer_tail == i) | 110 | while (tx_buffer_tail == i) |
111 | ; // wait until space in buffer | 111 | ; // wait until space in buffer |
112 | // cli(); | 112 | // cli(); |
113 | tx_buffer[i] = c; | 113 | tx_buffer[i] = data; |
114 | tx_buffer_head = i; | 114 | tx_buffer_head = i; |
115 | UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn) | (1 << UDRIEn); | 115 | UCSRnB = (1 << RXENn) | (1 << TXENn) | (1 << RXCIEn) | (1 << UDRIEn); |
116 | // sei(); | 116 | // sei(); |
117 | } | 117 | } |
118 | 118 | ||
119 | // Receive a byte | 119 | // Receive a byte |
120 | uint8_t uart_getchar(void) { | 120 | uint8_t uart_read(void) { |
121 | uint8_t c, i; | 121 | uint8_t data, i; |
122 | 122 | ||
123 | while (rx_buffer_head == rx_buffer_tail) | 123 | while (rx_buffer_head == rx_buffer_tail) |
124 | ; // wait for character | 124 | ; // wait for character |
125 | i = rx_buffer_tail + 1; | 125 | i = rx_buffer_tail + 1; |
126 | if (i >= RX_BUFFER_SIZE) i = 0; | 126 | if (i >= RX_BUFFER_SIZE) i = 0; |
127 | c = rx_buffer[i]; | 127 | data = rx_buffer[i]; |
128 | rx_buffer_tail = i; | 128 | rx_buffer_tail = i; |
129 | return c; | 129 | return data; |
130 | } | ||
131 | |||
132 | void uart_transmit(const uint8_t *data, uint16_t length) { | ||
133 | for (uint16_t i = 0; i < length; i++) { | ||
134 | uart_write(data[i]); | ||
135 | } | ||
136 | } | ||
137 | |||
138 | void uart_receive(uint8_t *data, uint16_t length) { | ||
139 | for (uint16_t i = 0; i < length; i++) { | ||
140 | data[i] = uart_read(); | ||
141 | } | ||
130 | } | 142 | } |
131 | 143 | ||
132 | // Return whether the number of bytes waiting in the receive buffer is nonzero. | 144 | // Return whether the number of bytes waiting in the receive buffer is nonzero. |
133 | // Call this before uart_getchar() to check if it will need | 145 | // Call this before uart_read() to check if it will need |
134 | // to wait for a byte to arrive. | 146 | // to wait for a byte to arrive. |
135 | bool uart_available(void) { | 147 | bool uart_available(void) { |
136 | uint8_t head, tail; | 148 | uint8_t head, tail; |
diff --git a/platforms/avr/drivers/uart.h b/platforms/avr/drivers/uart.h index 602eb3d8b..9cb7652b0 100644 --- a/platforms/avr/drivers/uart.h +++ b/platforms/avr/drivers/uart.h | |||
@@ -28,8 +28,12 @@ | |||
28 | 28 | ||
29 | void uart_init(uint32_t baud); | 29 | void uart_init(uint32_t baud); |
30 | 30 | ||
31 | void uart_putchar(uint8_t c); | 31 | void uart_write(uint8_t data); |
32 | 32 | ||
33 | uint8_t uart_getchar(void); | 33 | uint8_t uart_read(void); |
34 | |||
35 | void uart_transmit(const char *data, uint16_t length); | ||
36 | |||
37 | void uart_receive(char *data, uint16_t length); | ||
34 | 38 | ||
35 | bool uart_available(void); | 39 | bool uart_available(void); |