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/driver/ps2.c | |
parent | 7022f39e10551d7ab325d196884de301ddb3087e (diff) |
kernel/driver: modify the ps2/serial drivers to use ring_t
Diffstat (limited to 'src/kernel/arch/i386/driver/ps2.c')
-rw-r--r-- | src/kernel/arch/i386/driver/ps2.c | 23 |
1 files changed, 6 insertions, 17 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); } |