Zephyr Project API  3.2.0
A Scalable Open Source RTOS
ring_buffer.h File Reference
#include <zephyr/kernel.h>
#include <zephyr/sys/util.h>
#include <errno.h>

Go to the source code of this file.

Data Structures

struct  ring_buf
 A structure to represent a ring buffer. More...
 

Macros

#define RING_BUFFER_MAX_SIZE   0x80000000U
 
#define RING_BUFFER_SIZE_ASSERT_MSG    "Size too big"
 
#define RING_BUF_DECLARE(name, size8)
 Define and initialize a ring buffer for byte data. More...
 
#define RING_BUF_ITEM_DECLARE(name, size32)
 Define and initialize an "item based" ring buffer. More...
 
#define RING_BUF_ITEM_DECLARE_SIZE(name, size32)    RING_BUF_ITEM_DECLARE(name, size32)
 Define and initialize an "item based" ring buffer. More...
 
#define RING_BUF_ITEM_DECLARE_POW2(name, pow)    RING_BUF_ITEM_DECLARE(name, BIT(pow))
 Define and initialize a power-of-2 sized "item based" ring buffer. More...
 
#define RING_BUF_ITEM_SIZEOF(expr)    ((sizeof(expr) + sizeof(uint32_t) - 1) / sizeof(uint32_t))
 Compute the ring buffer size in 32-bit needed to store an element. More...
 

Functions

static void ring_buf_internal_reset (struct ring_buf *buf, int32_t value)
 Function to force ring_buf internal states to given value. More...
 
static void ring_buf_init (struct ring_buf *buf, uint32_t size, uint8_t *data)
 Initialize a ring buffer for byte data. More...
 
static void ring_buf_item_init (struct ring_buf *buf, uint32_t size, uint32_t *data)
 Initialize an "item based" ring buffer. More...
 
static bool ring_buf_is_empty (struct ring_buf *buf)
 Determine if a ring buffer is empty. More...
 
static void ring_buf_reset (struct ring_buf *buf)
 Reset ring buffer state. More...
 
static uint32_t ring_buf_space_get (struct ring_buf *buf)
 Determine free space in a ring buffer. More...
 
static uint32_t ring_buf_item_space_get (struct ring_buf *buf)
 Determine free space in an "item based" ring buffer. More...
 
static uint32_t ring_buf_capacity_get (struct ring_buf *buf)
 Return ring buffer capacity. More...
 
static uint32_t ring_buf_size_get (struct ring_buf *buf)
 Determine used space in a ring buffer. More...
 
uint32_t ring_buf_put_claim (struct ring_buf *buf, uint8_t **data, uint32_t size)
 Allocate buffer for writing data to a ring buffer. More...
 
int ring_buf_put_finish (struct ring_buf *buf, uint32_t size)
 Indicate number of bytes written to allocated buffers. More...
 
uint32_t ring_buf_put (struct ring_buf *buf, const uint8_t *data, uint32_t size)
 Write (copy) data to a ring buffer. More...
 
uint32_t ring_buf_get_claim (struct ring_buf *buf, uint8_t **data, uint32_t size)
 Get address of a valid data in a ring buffer. More...
 
int ring_buf_get_finish (struct ring_buf *buf, uint32_t size)
 Indicate number of bytes read from claimed buffer. More...
 
uint32_t ring_buf_get (struct ring_buf *buf, uint8_t *data, uint32_t size)
 Read data from a ring buffer. More...
 
uint32_t ring_buf_peek (struct ring_buf *buf, uint8_t *data, uint32_t size)
 Peek at data from a ring buffer. More...
 
int ring_buf_item_put (struct ring_buf *buf, uint16_t type, uint8_t value, uint32_t *data, uint8_t size32)
 Write a data item to a ring buffer. More...
 
int ring_buf_item_get (struct ring_buf *buf, uint16_t *type, uint8_t *value, uint32_t *data, uint8_t *size32)
 Read a data item from a ring buffer. More...
 

Macro Definition Documentation

◆ RING_BUFFER_MAX_SIZE

#define RING_BUFFER_MAX_SIZE   0x80000000U

◆ RING_BUFFER_SIZE_ASSERT_MSG

#define RING_BUFFER_SIZE_ASSERT_MSG    "Size too big"

Function Documentation

◆ ring_buf_internal_reset()

static void ring_buf_internal_reset ( struct ring_buf buf,
int32_t  value 
)
inlinestatic

Function to force ring_buf internal states to given value.

Any value other than 0 makes sense only in validation testing context.