ring  1.1
A Flexible Ring Buffer in C.
ring.h File Reference

Implementation of a ring buffer in C. More...

#include <stdint.h>

Data Structures

struct  ring_t
 Struct for ring buffer. More...
 

Functions

static ring_tringCreate (unsigned int tsize, unsigned int size)
 Create ring struct and buffer. More...
 
static void ringFree (ring_t *r)
 Free ring struct and buffer. More...
 
static unsigned int ringGetCount (ring_t *r)
 Get number of used elements in ring buffer. More...
 
static unsigned int ringGetFreeCount (ring_t *r)
 Get number of free elements in ring buffer. More...
 
static int ringIsEmpty (ring_t *r)
 Check if ring buffer is empty. More...
 
static int ringIsFull (ring_t *r)
 Check if ring buffer is full. More...
 
static unsigned int ringWrite (ring_t *r, uint8_t *pData)
 Write one element to ring buffer. More...
 
static uint8_t * ringRead (ring_t *r, uint8_t *pData)
 Read one element from ring buffer. More...
 
static uint8_t * ringPeek (ring_t *r, uint8_t *pData)
 Peek next element of the ring buffer Read next element but keep this element in the ring buffer. More...
 
static uint8_t * ringSearchToken (ring_t *r, uint8_t token)
 Search one byte (element) in ring buffer. More...
 
static uint8_t * ringGetLine (ring_t *r, uint8_t *pLine)
 Get a complete line from the ring buffer. More...
 
static void ringPrintInfo (ring_t *r)
 Print information to stdout about the ring buffer. More...
 
static void ringPrintBuffer (ring_t *r)
 Print the content in the ring buffer to stdout. More...
 

Detailed Description

Implementation of a ring buffer in C.

Author
Wim Dolman (w.e.dolman@hva.nl)
Date
27-05-2021
Version
1.1

The compleet ring buffer is descripted in this header file. There is no accompanying c file. This ring buffer uses a struct with information about the ring buffer. The ring buffer can contain elements of any size. Multiple ring buffers can be used in the same project.

Function Documentation

◆ ringCreate()

static ring_t* ringCreate ( unsigned int  tsize,
unsigned int  size 
)
inlinestatic

Create ring struct and buffer.

Parameters
[in]tsizedatatype size of elements in ring buffer
[in]sizetotal number of elements in ring buffer
Returns
if alright a pointer to the ring structure is returned else NULL

◆ ringFree()

static void ringFree ( ring_t r)
inlinestatic

Free ring struct and buffer.

Parameters
[in]rPointer to ring structure
Returns
Void

◆ ringGetCount()

static unsigned int ringGetCount ( ring_t r)
inlinestatic

Get number of used elements in ring buffer.

Parameters
[in]rPointer to ring structure
Returns
Number of used elements

◆ ringGetFreeCount()

static unsigned int ringGetFreeCount ( ring_t r)
inlinestatic

Get number of free elements in ring buffer.

Parameters
[in]rPointer to ring structure
Returns
Number of free elements

◆ ringGetLine()

static uint8_t* ringGetLine ( ring_t r,
uint8_t *  pLine 
)
inlinestatic

Get a complete line from the ring buffer.

Parameters
[in]rPointer to ring structure
[out]pLinePointer to a line buffer where data must be written to
Note
Only suitable for a ring buffer of tsize is 1 e.g. the type char
The line buffer needs to be large enough to contain the data
Returns
If line is found a pointer to location of the line buffer is returned else NULL

◆ ringIsEmpty()

static int ringIsEmpty ( ring_t r)
inlinestatic

Check if ring buffer is empty.

Parameters
[in]rPointer to ring structure
Returns
1 when ring buffer is empty and 0 when ring buffer is not empty

◆ ringIsFull()

static int ringIsFull ( ring_t r)
inlinestatic

Check if ring buffer is full.

Parameters
[in]rPointer to ring structure
Returns
1 when ring buffer is empty and 0 when ring buffer is not empty

◆ ringPeek()

static uint8_t* ringPeek ( ring_t r,
uint8_t *  pData 
)
inlinestatic

Peek next element of the ring buffer Read next element but keep this element in the ring buffer.

Parameters
[in]rPointer to ring structure
[out]pDataPointer to location where element must be written
Returns
Pointer to location where element must be written

◆ ringPrintBuffer()

static void ringPrintBuffer ( ring_t r)
inlinestatic

Print the content in the ring buffer to stdout.

Parameters
[in]rPointer to ring structure
Note
Only suitable for a ring buffer of tsize is 1 e.g. the type char
Returns
Void

◆ ringPrintInfo()

static void ringPrintInfo ( ring_t r)
inlinestatic

Print information to stdout about the ring buffer.

Parameters
[in]rPointer to ring structure
Returns
Void

◆ ringRead()

static uint8_t* ringRead ( ring_t r,
uint8_t *  pData 
)
inlinestatic

Read one element from ring buffer.

Parameters
[in]rPointer to ring structure
[in]pDataPointer to location where value of element must be written
Returns
Pointer to location where value of element must be written

◆ ringSearchToken()

static uint8_t* ringSearchToken ( ring_t r,
uint8_t  token 
)
inlinestatic

Search one byte (element) in ring buffer.

Parameters
[in]rPointer to ring structure
[in]tokenToken to be searched
Note
Only suitable for a ringbuffer of tsize is 1 e.g. the type char
Returns
If token is found a pointer to the location is returned else NULL

◆ ringWrite()

static unsigned int ringWrite ( ring_t r,
uint8_t *  pData 
)
inlinestatic

Write one element to ring buffer.

Parameters
[in]rPointer to ring structure
[out]pDataPointer to element to be written
Returns
returns 1 upon success else 0