49#define TSRB_INIT(BUF) { (BUF), sizeof (BUF), 0, 0 }
62 assert((bufsize != 0) && ((bufsize & (~bufsize + 1)) == bufsize));
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
MAYBE_INLINE void irq_restore(unsigned state)
This function restores the IRQ disable bit in the status register to the value contained within passe...
MAYBE_INLINE unsigned irq_disable(void)
This function sets the IRQ disable bit in the status register.
int tsrb_peek(tsrb_t *rb, uint8_t *dst, size_t n)
Get bytes from ringbuffer, without removing them.
int tsrb_get(tsrb_t *rb, uint8_t *dst, size_t n)
Get bytes from ringbuffer.
int tsrb_add(tsrb_t *rb, const uint8_t *src, size_t n)
Add bytes to ringbuffer.
int tsrb_drop(tsrb_t *rb, size_t n)
Drop bytes from ringbuffer.
static unsigned int tsrb_free(const tsrb_t *rb)
Get free space in ringbuffer.
static unsigned int tsrb_avail(const tsrb_t *rb)
Get number of bytes available for reading.
int tsrb_get_one(tsrb_t *rb)
Get a byte from ringbuffer.
struct tsrb tsrb_t
thread-safe ringbuffer struct
static void tsrb_clear(tsrb_t *rb)
Clear a tsrb.
int tsrb_add_one(tsrb_t *rb, uint8_t c)
Add a byte to ringbuffer.
int tsrb_peek_one(tsrb_t *rb)
Get a byte from ringbuffer, without removing it.
static void tsrb_init(tsrb_t *rb, uint8_t *buffer, unsigned bufsize)
Initialize a tsrb.
static int tsrb_full(const tsrb_t *rb)
Test if the tsrb is full.
static int tsrb_empty(const tsrb_t *rb)
Test if the tsrb is empty.
thread-safe ringbuffer struct
unsigned writes
total number of writes
unsigned reads
total number of reads
uint8_t * buf
Buffer to operate on.
unsigned int size
Size of buffer, must be power of 2.