From cd50c8d1047832bbb0798b368fde0428ef749422 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sat, 15 Sep 2018 17:53:27 +0200 Subject: improved in-kernel alloc/dealloc. addded colorless logging and struggling with mouse and kb --- kernel/ringbuffer.h | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'kernel/ringbuffer.h') diff --git a/kernel/ringbuffer.h b/kernel/ringbuffer.h index bb2b875..1ec88c8 100644 --- a/kernel/ringbuffer.h +++ b/kernel/ringbuffer.h @@ -1,28 +1,56 @@ +/** + * @file + * + * FIFO Buffers + * ============ + * + * Simple FIRST IN FIRST OUT + * + * Requires + * -------- + * Requires kballoc/kbfree - block allocation + * + * Thread + * ------ + * This is __not__ threadsafe. It is your job to lock accesses to + * reads/writes. + * + * Todo + * ---- + * provide soemthing to read large blocks faster? + */ + #ifndef RINGBUFFER_H #define RINGBUFFER_H #include #include -// Simple FIRST IN FIRST OUT -// requires kballoc - block allocation - +/** Ringbuffer sturcutre */ typedef volatile struct ringbuffer_struct { uint32_t size; uint32_t front; uint32_t back; - - uint8_t *data; - + uint8_t *data; }ringbuffer; -// create new fifo/ringbuffer of given size (in blocks) +/** Create a new fifo/ringbuffer of given size (in blocks) */ ringbuffer ringbuffer_init(uint32_t blocks); -// true on success +/** Deallocate buffer */ +void ringbuffer_free(ringbuffer *f); + +/** Put one _char_ into buffer. Returns true on success (i.e. buffer not full) */ bool ringbuffer_put(ringbuffer*,uint8_t); -uint8_t ringbuffer_get(ringbuffer*); // non-blocking please check first -bool ringbuffer_has(ringbuffer*); // check if somehting waiting? + +/** Get a single _char_ from the buffer, + * Return value __0__ might indicate that the buffer is empty. + * check with _ringbuffer_has()_ to be sure. + */ +uint8_t ringbuffer_get(ringbuffer*); + +/** Check if buffer is not empty */ +bool ringbuffer_has(ringbuffer*); #endif -- cgit v1.2.3