diff options
author | dzwdz | 2022-04-10 17:37:33 +0200 |
---|---|---|
committer | dzwdz | 2022-04-10 17:37:33 +0200 |
commit | 0ed2c976cc0bf569a3901be686a467150c089896 (patch) | |
tree | fc9389db2dc2950957fcd7c59ab9565c503f81d6 /src/kernel/arch/i386 | |
parent | 7022f39e10551d7ab325d196884de301ddb3087e (diff) |
kernel/driver: modify the ps2/serial drivers to use ring_t
Diffstat (limited to 'src/kernel/arch/i386')
-rw-r--r-- | src/kernel/arch/i386/driver/ps2.c | 23 | ||||
-rw-r--r-- | src/kernel/arch/i386/driver/serial.c | 24 |
2 files changed, 12 insertions, 35 deletions
diff --git a/src/kernel/arch/i386/driver/ps2.c b/src/kernel/arch/i386/driver/ps2.c index 5121b9e..4b7eae4 100644 --- a/src/kernel/arch/i386/driver/ps2.c +++ b/src/kernel/arch/i386/driver/ps2.c @@ -1,31 +1,20 @@ #include <kernel/arch/i386/driver/ps2.h> #include <kernel/arch/i386/interrupts/irq.h> +#include <shared/container/ring.h> #include <shared/mem.h> #define BACKLOG_CAPACITY 64 - -static volatile uint8_t backlog[BACKLOG_CAPACITY] = {}; -static volatile size_t backlog_size = 0; +static volatile uint8_t backlog_buf[BACKLOG_CAPACITY]; +static volatile ring_t backlog = {(void*)backlog_buf, BACKLOG_CAPACITY, 0, 0}; bool ps2_ready(void) { - return backlog_size > 0; + return ring_size((void*)&backlog) > 0; } void ps2_recv(uint8_t s) { - if (backlog_size >= BACKLOG_CAPACITY) return; - backlog[backlog_size++] = s; + ring_put1b((void*)&backlog, s); } size_t ps2_read(uint8_t *buf, size_t len) { - if (backlog_size <= len) - len = backlog_size; - backlog_size -= len; /* guaranteed to never be < 0 */ - memcpy(buf, (void*)backlog, len); - - /* move rest of buffer back on partial reads */ - // TODO assumes that memcpy()ing into an overlapping buffer is fine, outside spec - if (backlog_size > 0) - memcpy((void*)backlog, (void*)backlog + len, backlog_size); - - return len; + return ring_get((void*)&backlog, buf, len); } diff --git a/src/kernel/arch/i386/driver/serial.c b/src/kernel/arch/i386/driver/serial.c index 56a2f62..40d4a77 100644 --- a/src/kernel/arch/i386/driver/serial.c +++ b/src/kernel/arch/i386/driver/serial.c @@ -2,13 +2,13 @@ #include <kernel/arch/i386/interrupts/irq.h> #include <kernel/arch/i386/port_io.h> #include <kernel/panic.h> +#include <shared/container/ring.h> #include <shared/mem.h> #include <stdint.h> - #define BACKLOG_CAPACITY 64 -static volatile uint8_t backlog[BACKLOG_CAPACITY] = {}; -static volatile size_t backlog_size = 0; +static volatile uint8_t backlog_buf[BACKLOG_CAPACITY]; +static volatile ring_t backlog = {(void*)backlog_buf, BACKLOG_CAPACITY, 0, 0}; static const int COM1 = 0x3f8; @@ -38,27 +38,15 @@ void serial_init(void) { bool serial_ready(void) { - return backlog_size > 0; + return ring_size((void*)&backlog) > 0; } void serial_irq(void) { - if (backlog_size >= BACKLOG_CAPACITY) return; - backlog[backlog_size++] = port_in8(COM1); + ring_put1b((void*)&backlog, port_in8(COM1)); } size_t serial_read(char *buf, size_t len) { - // copied from ps2, maybe could be made into a shared function? TODO FIFO lib - if (backlog_size <= len) - len = backlog_size; - backlog_size -= len; /* guaranteed to never be < 0 */ - memcpy(buf, (void*)backlog, len); - - /* move rest of buffer back on partial reads */ - // TODO assumes that memcpy()ing into an overlapping buffer is fine, outside spec - if (backlog_size > 0) - memcpy((void*)backlog, (void*)backlog + len, backlog_size); - - return len; + return ring_get((void*)&backlog, buf, len); } |