The ring buffer library implements ring (circular) buffer where bytes can be read and written independently.
A ring buffer is particularly useful in device drivers where data can come in through interrupts.
Data Structures | |
struct | ringbuf |
Structure that holds the state of a ring buffer. More... | |
Files | |
file | ringbuf.h |
Header file for the ring buffer library | |
Functions | |
int | ringbuf_elements (struct ringbuf *r) |
Get the number of elements currently in the ring buffer. More... | |
int | ringbuf_get (struct ringbuf *r) |
Get a byte from the ring buffer. More... | |
void | ringbuf_init (struct ringbuf *r, uint8_t *a, uint8_t size_power_of_two) |
Initialize a ring buffer. More... | |
int | ringbuf_put (struct ringbuf *r, uint8_t c) |
Insert a byte into the ring buffer. More... | |
int | ringbuf_size (struct ringbuf *r) |
Get the size of a ring buffer. More... | |
Variables | |
uint8_t * | ringbuf::data |
uint8_t | ringbuf::get_ptr |
uint8_t | ringbuf::mask |
uint8_t | ringbuf::put_ptr |
int ringbuf_elements | ( | struct ringbuf * | r | ) |
int ringbuf_get | ( | struct ringbuf * | r | ) |
Get a byte from the ring buffer.
r | A pointer to a struct ringbuf to hold the state of the ring buffer |
This function removes a byte from the ring buffer. It is safe to call this function from an interrupt handler.
References c, data, get_ptr, mask, and put_ptr.
Referenced by PROCESS_THREAD().
void ringbuf_init | ( | struct ringbuf * | r, |
uint8_t * | a, | ||
uint8_t | size_power_of_two | ||
) |
Initialize a ring buffer.
r | A pointer to a struct ringbuf to hold the state of the ring buffer |
a | A pointer to an array to hold the data in the buffer |
size_power_of_two | The size of the ring buffer, which must be a power of two This function initiates a ring buffer. The data in the buffer is stored in an external array, to which a pointer must be supplied. The size of the ring buffer must be a power of two and cannot be larger than 128 bytes. |
References data, get_ptr, mask, and put_ptr.
Referenced by serial_line_init().
int ringbuf_put | ( | struct ringbuf * | r, |
uint8_t | c | ||
) |
Insert a byte into the ring buffer.
r | A pointer to a struct ringbuf to hold the state of the ring buffer |
c | The byte to be written to the buffer |
This function inserts a byte into the ring buffer. It is safe to call this function from an interrupt handler.
References c, data, get_ptr, mask, and put_ptr.
Referenced by serial_line_input_byte().
int ringbuf_size | ( | struct ringbuf * | r | ) |
Get the size of a ring buffer.
r | A pointer to a struct ringbuf to hold the state of the ring buffer |
References mask.
uint8_t* ringbuf::data |
Referenced by ringbuf_get(), ringbuf_init(), and ringbuf_put().
uint8_t ringbuf::get_ptr |
Referenced by ringbuf_elements(), ringbuf_get(), ringbuf_init(), and ringbuf_put().
uint8_t ringbuf::mask |
Referenced by ringbuf_elements(), ringbuf_get(), ringbuf_init(), ringbuf_put(), and ringbuf_size().
uint8_t ringbuf::put_ptr |
Referenced by ringbuf_elements(), ringbuf_get(), ringbuf_init(), and ringbuf_put().