# RingBuffer
**Repository Path**: ccmgc/RingBuffer
## Basic Information
- **Project Name**: RingBuffer
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: GPL-3.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2026-01-16
- **Last Updated**: 2026-01-16
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# RingBuffer

[](https://www.gnu.org/licenses/gpl-3.0)
### Short description
My ring buffer implementation, for embedde applications. Tested on STM32L1
STM32F3, STM32F4 and PIC18F platforms. Includes unit tests.
* Src - folder containing source code.
* Unit_test - Unit tests source files.
* Docs - Documentation files.
* unity - Unit tests framework.
# Usage
This part explains basic usage of this ring buffer library.
## Initialization
If user uses fixed size arrays mode, function `RingInit` takes only one argument,
which is pointer to `RingBuffer_t` structure.
If variable arrays mode is used, user should declare array of type `uint8_t`,
with desired size. This array and its size should be given as parameters to
`RingInit` function.
If inputs parameters given are valid, function should return `OK`. Now the
buffer is ready to use.
Note: there could be more than one buffer declared.
## Writing to buffer
There are two functions used to write data to buffer. These are:
* `RingWriteByte` - used to write only one byte to buffer. As parameters,
function takse pointer to buffer handler, and as second argument, one byte of
data to be written.
* `RingWriteMultipleBytes` - used to write one or more bytes to buffer. First
parameter is pointer to buffer handler, second is pointer to data to be written,
and the third is length of data to write.
Both functions return `OK` if write was succesfull, or `NO_PLACE` if there was
not enough space in buffer, or `NO_PTR` if null pointer was given as an argument.
## Reading from buffer
As before, to read from buffer, there are two functions provided.
* `RingReadByte` - used to read one byte from given buffer.
* `RingReadMultipleBytes` - used to read one or more bytes from buffer.
## Additional functions
* `RingGetHead` - returns next array index to write.
* `RingGetTail` - returns index of the next element from array that will be read.
* `RingGetMaxSize` - returns buffer size in bytes.
* `RingGetSpace` - retuns free spce in buffer.
* `RingGetDataCnt` - returns number of unread bytes in buffer.
* `RingGetLastElement` - returns last element from buffer without taking it from
buffer. Could be usable for example when using as UART receive buffer, for
waiting if received data string was terminated with specific value.
# To do:
- [x] Add makefile for unit tests
- [x] Add unit tests files
- [x] Generate doxygen docs
- [x] Provide examples
# Unit tests
For unit teste Criterion needs to be installed in your system. It can be done by:
```bash
wget -qO- https://github.com/Snaipe/Criterion/releases/download/v2.3.3/criterion-v2.3.3-linux-x86_64.tar.bz2 | tar -xjvf -
sudo cp -a criterion-v2.3.3/lib/. /usr/lib
sudo cp -a criterion-v2.3.3/include/. /usr/include
```