/** * @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 /** Ringbuffer sturcutre */ typedef volatile struct ringbuffer_struct { uint32_t size; uint32_t front; uint32_t back; uint8_t *data; }ringbuffer; /** Create a new fifo/ringbuffer of given size (in blocks) */ ringbuffer ringbuffer_init(uint32_t blocks); /** 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); /** 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