10#ifndef ZEPHYR_INCLUDE_SYS_RING_BUFFER_H_
11#define ZEPHYR_INCLUDE_SYS_RING_BUFFER_H_
22#define SIZE32_OF(x) (sizeof((x))/sizeof(uint32_t))
27#define RING_BUFFER_MAX_SIZE 0x80000000
29#define RING_BUFFER_SIZE_ASSERT_MSG \
30 "Size too big, if it is the ring buffer test check custom max size"
82#define RING_BUF_ITEM_DECLARE_POW2(name, pow) \
83 BUILD_ASSERT((1 << pow) < RING_BUFFER_MAX_SIZE,\
84 RING_BUFFER_SIZE_ASSERT_MSG); \
85 static uint32_t __noinit _ring_buffer_data_##name[BIT(pow)]; \
86 struct ring_buf name = { \
88 .mask = (BIT(pow)) - 1, \
89 .buf = { .buf32 = _ring_buffer_data_##name } \
106#define RING_BUF_ITEM_DECLARE_SIZE(name, size32) \
107 BUILD_ASSERT(size32 < RING_BUFFER_MAX_SIZE,\
108 RING_BUFFER_SIZE_ASSERT_MSG); \
109 static uint32_t __noinit _ring_buffer_data_##name[size32]; \
110 struct ring_buf name = { \
112 .buf = { .buf32 = _ring_buffer_data_##name} \
128#define RING_BUF_DECLARE(name, size8) \
129 BUILD_ASSERT(size8 < RING_BUFFER_MAX_SIZE,\
130 RING_BUFFER_SIZE_ASSERT_MSG); \
131 static uint8_t __noinit _ring_buffer_data_##name[size8]; \
132 struct ring_buf name = { \
134 .buf = { .buf8 = _ring_buffer_data_##name} \
164 buf->
mask = size - 1U;
uint32_t ring_buf_get(struct ring_buf *buf, uint8_t *data, uint32_t size)
Read data from a ring buffer.
int ring_buf_get_finish(struct ring_buf *buf, uint32_t size)
Indicate number of bytes read from claimed buffer.
int ring_buf_put_finish(struct ring_buf *buf, uint32_t size)
Indicate number of bytes written to allocated buffers.
uint32_t ring_buf_space_get(struct ring_buf *buf)
Determine free space in a ring buffer.
uint32_t ring_buf_put(struct ring_buf *buf, const uint8_t *data, uint32_t size)
Write (copy) data to a ring buffer.
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.
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.
uint32_t ring_buf_size_get(struct ring_buf *buf)
Determine used space in a ring buffer.
uint32_t ring_buf_peek(struct ring_buf *buf, uint8_t *data, uint32_t size)
Peek at data from a ring buffer.
static uint32_t ring_buf_capacity_get(struct ring_buf *buf)
Return ring buffer capacity.
Definition: ring_buffer.h:207
static void ring_buf_reset(struct ring_buf *buf)
Reset ring buffer state.
Definition: ring_buffer.h:184
int ring_buf_is_empty(struct ring_buf *buf)
Determine if a ring buffer is empty.
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.
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.
static void ring_buf_init(struct ring_buf *buf, uint32_t size, void *data)
Initialize a ring buffer.
Definition: ring_buffer.h:154
static bool is_power_of_two(unsigned int x)
Is x a power of two?
Definition: util.h:196
#define RING_BUFFER_SIZE_ASSERT_MSG
Definition: ring_buffer.h:29
#define RING_BUFFER_MAX_SIZE
Definition: ring_buffer.h:27
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
void * memset(void *buf, int c, size_t n)
Kernel Spin Lock.
Definition: spinlock.h:29
Definition: ring_buffer.h:44
uint32_t tmp_head
Definition: ring_buffer.h:46
uint32_t tmp_tail
Definition: ring_buffer.h:45
Definition: ring_buffer.h:38
uint32_t dropped_put_count
Definition: ring_buffer.h:39
A structure to represent a ring buffer.
Definition: ring_buffer.h:34
uint32_t tail
Definition: ring_buffer.h:36
uint32_t mask
Definition: ring_buffer.h:55
struct k_spinlock lock
Definition: ring_buffer.h:57
union ring_buf::ring_buf_buffer buf
union ring_buf::ring_buf_misc misc
uint32_t size
Definition: ring_buffer.h:49
uint32_t head
Definition: ring_buffer.h:35
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
Definition: ring_buffer.h:51
uint8_t * buf8
Definition: ring_buffer.h:53
uint32_t * buf32
Definition: ring_buffer.h:52
Definition: ring_buffer.h:37
struct ring_buf::ring_buf_misc::ring_buf_misc_item_mode item_mode
struct ring_buf::ring_buf_misc::ring_buf_misc_byte_mode byte_mode