Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MAINTAINERS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5097,7 +5097,7 @@ Utilities:
- tests/lib/onoff/
- tests/lib/sys_util/
- tests/lib/sprintf/
- tests/lib/ringbuffer/
- tests/lib/ring_buffer/
- tests/lib/notify/
- tests/lib/linear_range/
labels:
Expand Down
389 changes: 98 additions & 291 deletions doc/kernel/data_structures/ring_buffers.rst

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion drivers/console/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ config IPM_CONSOLE_SENDER

config IPM_CONSOLE_RECEIVER
bool "Inter-processor Mailbox console receiver"
select RING_BUFFER
help
Enable the receiving side of IPM console

Expand Down
23 changes: 10 additions & 13 deletions drivers/console/ipm_console_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
static void ipm_console_thread(void *arg1, void *arg2, void *arg3)
{
uint8_t size32;
uint16_t type;
int ret, key;
const struct ipm_console_receiver_config_info *config_info;
struct ipm_console_receiver_runtime_data *driver_data;
Expand All @@ -28,19 +27,17 @@ static void ipm_console_thread(void *arg1, void *arg2, void *arg3)
driver_data = (struct ipm_console_receiver_runtime_data *)arg1;
config_info = (const struct ipm_console_receiver_config_info *)arg2;
ARG_UNUSED(arg3);
size32 = 0U;
pos = 0;

while (1) {
k_sem_take(&driver_data->sem, K_FOREVER);

ret = ring_buf_item_get(&driver_data->rb, &type,
(uint8_t *)&config_info->line_buf[pos],
NULL, &size32);
if (ret) {
ret = ring_buffer_read(&driver_data->rb, (uint8_t *)&config_info->line_buf[pos],
sizeof(uint32_t));

if (ret < sizeof(uint32_t)) {
/* Shouldn't ever happen... */
printk("ipm console ring buffer error: %d\n", ret);
size32 = 0U;
continue;
}

Expand Down Expand Up @@ -73,7 +70,7 @@ static void ipm_console_thread(void *arg1, void *arg2, void *arg3)
* clearing the channel_disabled flag.
*/
if (driver_data->channel_disabled &&
ring_buf_item_space_get(&driver_data->rb)) {
sizeof(uint32_t) <= ring_buffer_space(&driver_data->rb)) {
key = irq_lock();
ipm_set_enabled(driver_data->ipm_device, 1);
driver_data->channel_disabled = 0;
Expand All @@ -92,8 +89,8 @@ static void ipm_console_receive_callback(const struct device *ipm_dev,
ARG_UNUSED(data);

/* Should always be at least one free buffer slot */
ret = ring_buf_item_put(&driver_data->rb, 0, id, NULL, 0);
__ASSERT(ret == 0, "Failed to insert data into ring buffer");
ret = ring_buffer_write(&driver_data->rb, &id, sizeof(id));
__ASSERT(ret != sizeof(id), "Failed to insert data into ring buffer");
k_sem_give(&driver_data->sem);

/* If the buffer is now full, disable future interrupts for this channel
Expand All @@ -104,7 +101,7 @@ static void ipm_console_receive_callback(const struct device *ipm_dev,
* call with the wait flag enabled. It blocks until the receiver side
* re-enables the channel and consumes the data.
*/
if (ring_buf_item_space_get(&driver_data->rb) == 0) {
if (ring_buffer_space(&driver_data->rb) < sizeof(uint32_t)) {
ipm_set_enabled(ipm_dev, 0);
driver_data->channel_disabled = 1;
}
Expand Down Expand Up @@ -135,8 +132,8 @@ int ipm_console_receiver_init(const struct device *d)
driver_data->ipm_device = ipm;
driver_data->channel_disabled = 0;
k_sem_init(&driver_data->sem, 0, K_SEM_MAX_LIMIT);
ring_buf_item_init(&driver_data->rb, config_info->rb_size32,
config_info->ring_buf_data);
ring_buffer_init(&driver_data->rb, config_info->ring_buf_data,
config_info->rb_size32 * sizeof(uint32_t));

ipm_register_callback(ipm, ipm_console_receive_callback, driver_data);

Expand Down
1 change: 0 additions & 1 deletion drivers/entropy/Kconfig.cc13xx_cc26xx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ config ENTROPY_CC13XX_CC26XX_RNG
default y
depends on DT_HAS_TI_CC13XX_CC26XX_TRNG_ENABLED
select ENTROPY_HAS_DRIVER
select RING_BUFFER
help
This option enables the driver for the True Random Number Generator (TRNG)
for TI SimpleLink CC13xx / CC26xx SoCs.
Expand Down
14 changes: 7 additions & 7 deletions drivers/entropy/entropy_cc13xx_cc26xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
struct entropy_cc13xx_cc26xx_data {
struct k_sem lock;
struct k_sem sync;
struct ring_buf pool;
struct ring_buffer pool;
uint8_t data[CONFIG_ENTROPY_CC13XX_CC26XX_POOL_SIZE];
#ifdef CONFIG_PM
Power_NotifyObj post_notify;
Expand Down Expand Up @@ -111,7 +111,7 @@ static int entropy_cc13xx_cc26xx_get_entropy(const struct device *dev,

while (len) {
k_sem_take(&data->lock, K_FOREVER);
cnt = ring_buf_get(&data->pool, buf, len);
cnt = ring_buffer_read(&data->pool, buf, len);
k_sem_give(&data->lock);

if (cnt) {
Expand Down Expand Up @@ -140,7 +140,7 @@ static void entropy_cc13xx_cc26xx_isr(const struct device *dev)
num[1] = TRNGNumberGet(TRNG_HI_WORD);
num[0] = TRNGNumberGet(TRNG_LOW_WORD);

cnt = ring_buf_put(&data->pool, (uint8_t *)num, sizeof(num));
cnt = ring_buffer_write(&data->pool, (uint8_t *)num, sizeof(num));

/* When pool is full disable interrupt and stop reading numbers */
if (cnt != sizeof(num)) {
Expand Down Expand Up @@ -178,7 +178,7 @@ static int entropy_cc13xx_cc26xx_get_entropy_isr(const struct device *dev,
unsigned int key;

key = irq_lock();
cnt = ring_buf_get(&data->pool, buf, len);
cnt = ring_buffer_read(&data->pool, buf, len);
irq_unlock(key);

if ((cnt == len) || ((flags & ENTROPY_BUSYWAIT) == 0U)) {
Expand All @@ -200,7 +200,7 @@ static int entropy_cc13xx_cc26xx_get_entropy_isr(const struct device *dev,
num[1] = TRNGNumberGet(TRNG_HI_WORD);
num[0] = TRNGNumberGet(TRNG_LOW_WORD);

ring_buf_put(&data->pool, (uint8_t *)num,
ring_buffer_write(&data->pool, (uint8_t *)num,
sizeof(num));
}

Expand All @@ -209,7 +209,7 @@ static int entropy_cc13xx_cc26xx_get_entropy_isr(const struct device *dev,
* would allow us to pick up anything that has been put
* in by the ISR as well.
*/
cnt = ring_buf_get(&data->pool, buf, len);
cnt = ring_buffer_read(&data->pool, buf, len);

if (src & TRNG_FRO_SHUTDOWN) {
handle_shutdown_ovf();
Expand Down Expand Up @@ -286,7 +286,7 @@ static int entropy_cc13xx_cc26xx_init(const struct device *dev)
struct entropy_cc13xx_cc26xx_data *data = dev->data;

/* Initialize driver data */
ring_buf_init(&data->pool, sizeof(data->data), data->data);
ring_buffer_init(&data->pool, data->data, sizeof(data->data));

#if defined(CONFIG_PM)
Power_setDependency(PowerCC26XX_PERIPH_TRNG);
Expand Down
1 change: 0 additions & 1 deletion drivers/espi/Kconfig.npcx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ config ESPI_NPCX_BYPASS_CH_ENABLE_FATAL_ERROR
config ESPI_NPCX_PERIPHERAL_DEBUG_PORT_80_MULTI_BYTE
bool "Host can write 1/2/4 bytes of Port80 data in a eSPI transaction"
depends on (SOC_SERIES_NPCX9 || SOC_SERIES_NPCX4) && ESPI_PERIPHERAL_DEBUG_PORT_80
select RING_BUFFER
help
EC can accept 1/2/4 bytes of Port 80 data written from the Host in an
eSPI transaction.
Expand Down
21 changes: 11 additions & 10 deletions drivers/espi/host_subs_npcx.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ struct host_sub_npcx_data {
uint8_t espi_rst_level; /* current ESPI_RST# status */
const struct device *host_bus_dev; /* device for eSPI/LPC bus */
#ifdef CONFIG_ESPI_NPCX_PERIPHERAL_DEBUG_PORT_80_MULTI_BYTE
struct ring_buf port80_ring_buf;
struct ring_buffer port80_ring_buf;
uint8_t port80_data[CONFIG_ESPI_NPCX_PERIPHERAL_DEBUG_PORT_80_RING_BUF_SIZE];
struct k_work work;
#endif
Expand Down Expand Up @@ -505,26 +505,26 @@ static void host_port80_work_handler(struct k_work *item)
{
uint32_t code = 0;
struct host_sub_npcx_data *data = CONTAINER_OF(item, struct host_sub_npcx_data, work);
struct ring_buf *rbuf = &data->port80_ring_buf;
struct ring_buffer *rbuf = &data->port80_ring_buf;
struct espi_event evt = {ESPI_BUS_PERIPHERAL_NOTIFICATION,
(ESPI_PERIPHERAL_INDEX_0 << 16) | ESPI_PERIPHERAL_DEBUG_PORT80,
ESPI_PERIPHERAL_NODATA};

while (!ring_buf_is_empty(rbuf)) {
while (!ring_buffer_empty(rbuf)) {
struct npcx_dp80_buf dp80_buf;
uint8_t offset;

ring_buf_get(rbuf, &dp80_buf.offset_code[0], sizeof(dp80_buf.offset_code));
ring_buffer_read(rbuf, &dp80_buf.offset_code[0], sizeof(dp80_buf.offset_code));
offset = dp80_buf.offset_code[1];
code |= dp80_buf.offset_code[0] << (8 * offset);
if (ring_buf_is_empty(rbuf)) {
if (ring_buffer_empty(rbuf)) {
evt.evt_data = code;
espi_send_callbacks(host_sub_data.callbacks, host_sub_data.host_bus_dev,
evt);
break;
}
/* peek the offset of the next byte */
ring_buf_peek(rbuf, &dp80_buf.offset_code[0], sizeof(dp80_buf.offset_code));
ring_buffer_peek(rbuf, &dp80_buf.offset_code[0], sizeof(dp80_buf.offset_code));
offset = dp80_buf.offset_code[1];
/*
* If the peeked next byte's offset is 0, it is the start of the new code.
Expand All @@ -547,13 +547,13 @@ static void host_port80_isr(const void *arg)
uint8_t status = inst_shm->DP80STS;

#ifdef CONFIG_ESPI_NPCX_PERIPHERAL_DEBUG_PORT_80_MULTI_BYTE
struct ring_buf *rbuf = &host_sub_data.port80_ring_buf;
struct ring_buffer *rbuf = &host_sub_data.port80_ring_buf;

while (IS_BIT_SET(inst_shm->DP80STS, NPCX_DP80STS_FNE)) {
struct npcx_dp80_buf dp80_buf;

dp80_buf.offset_code_16 = inst_shm->DP80BUF;
ring_buf_put(rbuf, &dp80_buf.offset_code[0], sizeof(dp80_buf.offset_code));
ring_buffer_write(rbuf, &dp80_buf.offset_code[0], sizeof(dp80_buf.offset_code));
}
k_work_submit(&host_sub_data.work);
#else
Expand Down Expand Up @@ -1156,8 +1156,9 @@ int npcx_host_init_subs_core_domain(const struct device *host_bus_dev,
#if defined(CONFIG_ESPI_PERIPHERAL_DEBUG_PORT_80)
host_port80_init();
#if defined(CONFIG_ESPI_NPCX_PERIPHERAL_DEBUG_PORT_80_MULTI_BYTE)
ring_buf_init(&host_sub_data.port80_ring_buf, sizeof(host_sub_data.port80_data),
host_sub_data.port80_data);
ring_buffer_init(&host_sub_data.port80_ring_buf,
host_sub_data.port80_data,
sizeof(host_sub_data.port80_data));
k_work_init(&host_sub_data.work, host_port80_work_handler);
#endif
#endif
Expand Down
38 changes: 14 additions & 24 deletions drivers/hdlc_rcp_if/hdlc_rcp_if_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);

struct openthread_uart {
struct k_work work;
struct ring_buf *rx_ringbuf;
struct ring_buf *tx_ringbuf;
struct ring_buffer *rx_ringbuf;
struct ring_buffer *tx_ringbuf;
const struct device *dev;
atomic_t tx_busy;

Expand All @@ -45,8 +45,8 @@ struct openthread_uart {
};

#define OT_UART_DEFINE(_name, _ringbuf_rx_size, _ringbuf_tx_size) \
RING_BUF_DECLARE(_name##_rx_ringbuf, _ringbuf_rx_size); \
RING_BUF_DECLARE(_name##_tx_ringbuf, _ringbuf_tx_size); \
RING_BUFFER_DECLARE(_name##_rx_ringbuf, _ringbuf_rx_size); \
RING_BUFFER_DECLARE(_name##_tx_ringbuf, _ringbuf_tx_size); \
static struct openthread_uart _name = { \
.rx_ringbuf = &_name##_rx_ringbuf, \
.tx_ringbuf = &_name##_tx_ringbuf, \
Expand All @@ -70,11 +70,10 @@ static void ot_uart_rx_cb(struct k_work *item)
uint8_t *data;
uint32_t len;

len = ring_buf_get_claim(otuart->rx_ringbuf, &data,
otuart->rx_ringbuf->size);
len = ring_buffer_read_ptr(otuart->rx_ringbuf, &data);
if (len > 0) {
otuart->cb(data, len, otuart->param);
ring_buf_get_finish(otuart->rx_ringbuf, len);
ring_buffer_consume(otuart->rx_ringbuf, len);
}
}

Expand All @@ -83,14 +82,10 @@ static void uart_tx_handle(const struct device *dev)
uint32_t tx_len = 0, len;
uint8_t *data;

len = ring_buf_get_claim(
ot_uart.tx_ringbuf, &data,
ot_uart.tx_ringbuf->size);
len = ring_buffer_read_ptr(ot_uart.tx_ringbuf, &data);
if (len > 0) {
tx_len = uart_fifo_fill(dev, data, len);
int err = ring_buf_get_finish(ot_uart.tx_ringbuf, tx_len);
(void)err;
__ASSERT_NO_MSG(err == 0);
ring_buffer_consume(ot_uart.tx_ringbuf, tx_len);
} else {
uart_irq_tx_disable(dev);
}
Expand All @@ -101,15 +96,10 @@ static void uart_rx_handle(const struct device *dev)
uint32_t rd_len = 0, len;
uint8_t *data;

len = ring_buf_put_claim(
ot_uart.rx_ringbuf, &data,
ot_uart.rx_ringbuf->size);
len = ring_buffer_write_ptr(ot_uart.rx_ringbuf, &data);
if (len > 0) {
rd_len = uart_fifo_read(dev, data, len);

int err = ring_buf_put_finish(ot_uart.rx_ringbuf, rd_len);
(void)err;
__ASSERT_NO_MSG(err == 0);
ring_buffer_commit(ot_uart.rx_ringbuf, rd_len);
}
}

Expand All @@ -127,7 +117,7 @@ static void uart_callback(const struct device *dev, void *user_data)
}
}

if (ring_buf_size_get(ot_uart.rx_ringbuf) > 0) {
if (ring_buffer_size(ot_uart.rx_ringbuf) > 0) {
k_work_submit(&ot_uart.work);
}
}
Expand Down Expand Up @@ -175,7 +165,7 @@ static int hdlc_send(const uint8_t *frame, uint16_t length)
return -EIO;
}

ret = ring_buf_put(ot_uart.tx_ringbuf, frame, length);
ret = ring_buffer_write(ot_uart.tx_ringbuf, frame, length);
uart_irq_tx_enable(ot_uart.dev);

if (ret < length) {
Expand All @@ -191,8 +181,8 @@ static int hdlc_deinit(void)
uart_irq_tx_disable(ot_uart.dev);
uart_irq_rx_disable(ot_uart.dev);

ring_buf_reset(ot_uart.rx_ringbuf);
ring_buf_reset(ot_uart.tx_ringbuf);
ring_buffer_reset(ot_uart.rx_ringbuf);
ring_buffer_reset(ot_uart.tx_ringbuf);

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion drivers/input/Kconfig.tsc_keys
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ config INPUT_STM32_TSC_KEYS
bool "STM32 TSC touch library"
default y
depends on DT_HAS_ST_STM32_TSC_ENABLED
select RING_BUFFER
help
Enable support for STM32 TSC touch library.

Expand Down
11 changes: 6 additions & 5 deletions drivers/input/input_tsc_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ DT_INST_FOREACH_STATUS_OKAY(STM32_TSC_INIT)

struct input_tsc_keys_data {
uint32_t buffer[CONFIG_INPUT_STM32_TSC_KEYS_BUFFER_WORD_SIZE];
struct ring_buf rb;
struct ring_buffer rb;
bool expect_release;
struct k_timer sampling_timer;
};
Expand All @@ -372,11 +372,11 @@ static void input_tsc_callback_handler(uint32_t count_value, void *user_data)
(const struct input_tsc_keys_config *)dev->config;
struct input_tsc_keys_data *data = (struct input_tsc_keys_data *)dev->data;

if (ring_buf_item_space_get(&data->rb) == 0) {
if (ring_buffer_space(&data->rb) < sizeof(int32_t)) {
uint32_t oldest_point;
int32_t slope;

(void)ring_buf_get(&data->rb, (uint8_t *)&oldest_point, sizeof(oldest_point));
(void)ring_buffer_read(&data->rb, (uint8_t *)&oldest_point, sizeof(oldest_point));

slope = count_value - oldest_point;
if (slope < -config->noise_threshold && !data->expect_release) {
Expand All @@ -388,7 +388,7 @@ static void input_tsc_callback_handler(uint32_t count_value, void *user_data)
}
}

(void)ring_buf_put(&data->rb, (uint8_t *)&count_value, sizeof(count_value));
(void)ring_buffer_write(&data->rb, (uint8_t *)&count_value, sizeof(count_value));
}

static int input_tsc_keys_init(const struct device *dev)
Expand All @@ -401,7 +401,8 @@ static int input_tsc_keys_init(const struct device *dev)
return -ENODEV;
}

ring_buf_item_init(&data->rb, CONFIG_INPUT_STM32_TSC_KEYS_BUFFER_WORD_SIZE, data->buffer);
ring_buffer_init(&data->rb, data->buffer,
CONFIG_INPUT_STM32_TSC_KEYS_BUFFER_WORD_SIZE * sizeof(uint32_t));

uint8_t group_index = 0;

Expand Down
Loading
Loading