diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-09-24 16:51:51 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-09-24 18:47:13 +0300 |
| commit | fecb86f6093c1e8aed6ab05c29c5af9d0cb93157 (patch) | |
| tree | 10171c839d77167fc98fbae0b315d2c87aa13fa5 /src/components/uart/simple_uart.c | |
| parent | b1d67364b4b4832b8efed112f7b0ead1a0b3cd3b (diff) | |
| download | gran-fecb86f6093c1e8aed6ab05c29c5af9d0cb93157.tar.gz gran-fecb86f6093c1e8aed6ab05c29c5af9d0cb93157.zip | |
initial work towards message passing interface
+ As they are currently implemented, grid *may* get stuck if two nodes
try to send to eachother at the same time, I should probably add in
some kind of input buffer as well
Diffstat (limited to 'src/components/uart/simple_uart.c')
| -rw-r--r-- | src/components/uart/simple_uart.c | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/src/components/uart/simple_uart.c b/src/components/uart/simple_uart.c index 5c97ccd..1528a70 100644 --- a/src/components/uart/simple_uart.c +++ b/src/components/uart/simple_uart.c @@ -3,17 +3,42 @@ struct simple_uart { struct component component; + + struct component *send; + struct packet pkt; + bool busy; }; -static stat simple_uart_write(struct simple_uart *uart, struct packet *pkt) +static stat simple_uart_clock(struct simple_uart *uart) { - (void)uart; - size_t size = packet_size(pkt); - if (size != 1) - return EBUS; + 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(*(uint8_t *)packet_data(pkt)); - packet_set_state(pkt, PACKET_DONE); + putchar(packet_convu8(&pkt)); + set_flags(&uart->pkt, PACKET_DONE); return OK; } @@ -23,6 +48,7 @@ struct component *create_simple_uart() if (!uart) return NULL; - uart->component.write = (write_callback)simple_uart_write; + uart->component.receive = (receive_callback)simple_uart_receive; + uart->component.clock = (clock_callback)simple_uart_clock; return (struct component *)uart; } |
