ring_buf
Loading...
Searching...
No Matches
Modules | Data Structures | Macros | Functions
Ring Buffer
Collaboration diagram for Ring Buffer:

Modules

 Contiguous Ring Buffer Access
 Functions for contiguous access to ring buffer data.
 
 Discontiguous Ring Buffer Access
 Functions for discontiguous access to ring buffer data.
 

Data Structures

struct  ring_buf
 Ring buffer instance. More...
 

Macros

#define RING_BUF_DEFINE_STATIC(_name_, _size_)
 Defines a static ring buffer.
 

Functions

static ring_buf_size_t ring_buf_used_space (const struct ring_buf *buf)
 Calculates used space in the ring buffer.
 
static bool ring_buf_is_empty (const struct ring_buf *buf)
 Checks if the ring buffer is empty.
 
static ring_buf_size_t ring_buf_free_space (const struct ring_buf *buf)
 Calculates free space in the ring buffer.
 
static bool ring_buf_is_full (const struct ring_buf *buf)
 Checks if the ring buffer is full.
 
void ring_buf_reset (struct ring_buf *buf, ring_buf_ptrdiff_t base)
 Resets a ring buffer.
 

Detailed Description

Macro Definition Documentation

◆ RING_BUF_DEFINE_STATIC

#define RING_BUF_DEFINE_STATIC (   _name_,
  _size_ 
)
Value:
static uint8_t _ring_buf_space_##_name_[_size_]; \
static struct ring_buf _name_ = {.space = _ring_buf_space_##_name_, \
.size = _size_}
Ring buffer instance.
Definition ring_buf.h:128
ring_buf_size_t size
Size of the ring buffer.
Definition ring_buf.h:139
void * space
Pointer to the buffer's data space.
Definition ring_buf.h:133

Defines a static ring buffer.

This macro creates a ring buffer with the specified name and size. It statically allocates the ring buffer's storage space as an array of bytes.

It correctly initialises the ring buffer structure with a pointer to the allocated space and sets the size. The put and get zones are initialised to zero by default. This assumes that the compiler will zero-initialise static storage, i.e. allocated storage in the Blank Static Storage section. There is not need to explicitly reset the ring buffer before use.

Parameters
_name_Name of the ring buffer.
_size_Size of the ring buffer.

Definition at line 351 of file ring_buf.h.

Function Documentation

◆ ring_buf_free_space()

static ring_buf_size_t ring_buf_free_space ( const struct ring_buf buf)
inlinestatic

Calculates free space in the ring buffer.

Computes the number of bytes currently available for use in the ring buffer.

Parameters
bufRing buffer.
Returns
Number of free bytes.

Definition at line 183 of file ring_buf.h.

◆ ring_buf_is_empty()

static bool ring_buf_is_empty ( const struct ring_buf buf)
inlinestatic

Checks if the ring buffer is empty.

Determines whether the ring buffer has no used space. A ring buffer is considered empty when the used space is zero.

Parameters
bufRing buffer.
Return values
trueif the buffer is empty.
falseotherwise.

Definition at line 172 of file ring_buf.h.

◆ ring_buf_is_full()

static bool ring_buf_is_full ( const struct ring_buf buf)
inlinestatic

Checks if the ring buffer is full.

Determines whether the ring buffer has no free space. A ring buffer is considered full when the free space is zero.

Parameters
bufRing buffer.
Return values
trueif the buffer is full.
falseif not full.

Definition at line 195 of file ring_buf.h.

◆ ring_buf_reset()

void ring_buf_reset ( struct ring_buf buf,
ring_buf_ptrdiff_t  base 
)

Resets a ring buffer.

Resets both put and get zones to the specified base index. The base index typically starts at zero but can be set to any value.

Parameters
bufRing buffer.
baseBase index for both put and get zones.

Definition at line 96 of file ring_buf.c.

◆ ring_buf_used_space()

static ring_buf_size_t ring_buf_used_space ( const struct ring_buf buf)
inlinestatic

Calculates used space in the ring buffer.

Computes the number of bytes currently used in the ring buffer.

Parameters
bufRing buffer.
Returns
Number of used bytes.

Definition at line 160 of file ring_buf.h.