diff options
Diffstat (limited to 'src/components/uart/simple_uart.c')
| -rw-r--r-- | src/components/uart/simple_uart.c | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/src/components/uart/simple_uart.c b/src/components/uart/simple_uart.c deleted file mode 100644 index 1528a70..0000000 --- a/src/components/uart/simple_uart.c +++ /dev/null @@ -1,54 +0,0 @@ -#include <stdio.h> -#include <gran/uart/simple_uart.h> - -struct simple_uart { - struct component component; - - struct component *send; - struct packet pkt; - bool busy; -}; - -static stat simple_uart_clock(struct simple_uart *uart) -{ - if (!uart->busy) - return OK; - - stat r = SEND(uart, uart->send, uart->pkt); - if (r == EBUSY) - return OK; - - uart->busy = false; - return OK; -} - -static stat simple_uart_receive(struct simple_uart *uart, struct component *from, struct packet pkt) -{ - if (uart->busy) - return EBUSY; - - uart->busy = true; - uart->send = from; - uart->pkt = response(pkt); - - size_t size = packet_convsize(&pkt); - if (size != 1) { - set_flags(&uart->pkt, PACKET_ERROR); - return OK; - } - - putchar(packet_convu8(&pkt)); - set_flags(&uart->pkt, PACKET_DONE); - return OK; -} - -struct component *create_simple_uart() -{ - struct simple_uart *uart = calloc(1, sizeof(struct simple_uart)); - if (!uart) - return NULL; - - uart->component.receive = (receive_callback)simple_uart_receive; - uart->component.clock = (clock_callback)simple_uart_clock; - return (struct component *)uart; -} |
