generic circular buffer implementation in C
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
Circular byte buffer
|
|
|
|
====================
|
|
|
|
|
|
|
|
This is a circular buffer implementation, useful for embedded systems (buffer for UART RX queue etc).
|
|
|
|
|
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
|
|
|
|
```c
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
uint8_t buffer[32]; // array backing the buffer
|
|
|
|
|
|
|
|
CircularBuffer cb; // buffer instance
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
cbuf_init(&cb, buffer, 32); // init the buffer
|
|
|
|
|
|
|
|
// now it's ready for use!
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Many function return success flag, so make sure to check the return values.
|
|
|
|
|
|
|
|
False is returned on buffer overflow / underflow, attempted read past available data size etc. See the header file for details.
|
|
|
|
|
|
|
|
|
|
|
|
License
|
|
|
|
-------
|
|
|
|
|
|
|
|
Do whatever you want with the code.
|