diff options
Diffstat (limited to 'kernel/ringbuffer.h')
| -rw-r--r-- | kernel/ringbuffer.h | 48 |
1 files changed, 38 insertions, 10 deletions
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 <stdint.h> #include <stdbool.h> -// 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 |
