My ring/FIFO buffer implementation, for embedde applications. Tested on STM32L1, STM32F3, STM32F4 and PIC18F platforms.
My ring buffer implementation, for embedde applications. Tested on STM32L1
STM32F3, STM32F4 and PIC18F platforms. Includes unit tests.
This part explains basic usage of this ring buffer library.
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 toRingInit
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.
There are two functions used to write data to buffer. These are:
RingWriteByte
- used to write only one byte to buffer. As parameters,RingWriteMultipleBytes
- used to write one or more bytes to buffer. FirstOK
if write was succesfull, or NO_PLACE
if there wasNO_PTR
if null pointer was given as an argument.RingReadByte
- used to read one byte from given buffer.RingReadMultipleBytes
- used to read one or more bytes from buffer.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 fromFor unit teste Criterion needs to be installed in your system. It can be done by:
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