Defines | |
#define | BUFFER_FULL(buf) (buffer_nbytes(buf) == ((buf)->size - 1)) |
#define | BUFFER_EMPTY(buf) ((buf)->front == (buf)->back) |
Functions | |
void | buffer_add (BUFFER *buf, char val) |
BUFFER * | buffer_create (uint16_t size) |
void | buffer_flush (BUFFER *buf) |
uint16_t | buffer_nbytes (BUFFER *buf) |
char | buffer_remove (BUFFER *buf) |
void | buffer_reset (BUFFER *buf, uint16_t front, uint16_t back) |
int8_t | buffer_state (BUFFER *buf) |
#define BUFFER_EMPTY | ( | buf | ) | ((buf)->front == (buf)->back) |
Indicate whether the buffer is empty
buf | A pointer to an existing and initialized BUFFER structure. |
Referenced by buffer_flush(), buffer_remove(), and buffer_state().
#define BUFFER_FULL | ( | buf | ) | (buffer_nbytes(buf) == ((buf)->size - 1)) |
Indicate whether the buffer is full
buf | A pointer to an existing and initialized BUFFER structure. |
Referenced by buffer_add(), and buffer_state().
void buffer_add | ( | BUFFER * | buf, | |
char | val | |||
) |
Add a byte to the buffer. Will busy wait if there is no room in the buffer.
buf | A pointer to an existing and initialized BUFFER structure. | |
val | A character value to insert into the buffer. |
References BUFFER::back, BUFFER::buffer, BUFFER_FULL, and BUFFER::size.
BUFFER* buffer_create | ( | uint16_t | size | ) |
Create and initialize a circular buffer object. Allocates the buffer object space from the heap.
size | The number of bytes in the circular buffer. Note that a full buffer has size-1 bytes in it. |
References BUFFER::back, BUFFER::buffer, BUFFER::front, and BUFFER::size.
void buffer_flush | ( | BUFFER * | buf | ) |
Remove all elements in the specified buffer
buf | A pointer to an existing and initialized BUFFER structure. |
References BUFFER_EMPTY, and buffer_remove().
uint16_t buffer_nbytes | ( | BUFFER * | buf | ) |
Return the number of bytes that are currently stored in the buffer.
buf | A pointer to an existing and initialized BUFFER structure. |
References BUFFER::back, BUFFER::front, and BUFFER::size.
char buffer_remove | ( | BUFFER * | buf | ) |
Return the next element in the buffer. Will busy wait until there is something to return
buf | A pointer to an existing and initialized BUFFER structure. |
References BUFFER::buffer, BUFFER_EMPTY, BUFFER::front, and BUFFER::size.
Referenced by buffer_flush().
void buffer_reset | ( | BUFFER * | buf, | |
uint16_t | front, | |||
uint16_t | back | |||
) |
Reset the state of the buffer indices (for internal use). Note: must guarantee that no reader or writer is currently accessing this object (such as an ISR)
buf | A pointer to an existing and initialized BUFFER structure. | |
front | The index of the next byte in the buffer (0 ... size-1) | |
back | The index of the next avaiable space in the buffer (0 ... size-1). |
References BUFFER::back, and BUFFER::front.
int8_t buffer_state | ( | BUFFER * | buf | ) |
Return the state of the specified buffer.
buf | A pointer to an existing and initialized BUFFER structure. |
References BUFFER_EMPTY, and BUFFER_FULL.