Skip to content

Commit 828694a

Browse files
committed
subsys/*: update to new ring_buffer api
Update various subsystems to use the new ring_buffer API. Signed-off-by: Måns Ansgariusson <[email protected]>
1 parent 2b32c42 commit 828694a

File tree

8 files changed

+36
-39
lines changed

8 files changed

+36
-39
lines changed

subsys/bluetooth/audio/shell/bap_usb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct decoded_sdu {
9595
uint32_t ts;
9696
} decoded_sdu;
9797

98-
RING_BUF_DECLARE(usb_in_ring_buf, USB_IN_RING_BUF_SIZE);
98+
RING_BUFFER_DECLARE(usb_in_ring_buf, USB_IN_RING_BUF_SIZE);
9999
K_MEM_SLAB_DEFINE_STATIC(usb_in_buf_pool, ROUND_UP(USB_STEREO_FRAME_SIZE, UDC_BUF_GRANULARITY),
100100
USB_ENQUEUE_COUNT, UDC_BUF_ALIGN);
101101

@@ -118,7 +118,7 @@ static void usb_data_request(const struct device *dev)
118118
}
119119

120120
/* This may fail without causing issues since usb_audio_data is 0-initialized */
121-
size = ring_buf_get(&usb_in_ring_buf, pcm_buf, USB_STEREO_FRAME_SIZE);
121+
size = ring_buffer_read(&usb_in_ring_buf, pcm_buf, USB_STEREO_FRAME_SIZE);
122122
if (size != USB_STEREO_FRAME_SIZE) {
123123
/* If we could not fill the buffer, zero-fill the rest (possibly all) */
124124
memset(((uint8_t *)pcm_buf) + size, 0, USB_STEREO_FRAME_SIZE - size);
@@ -181,7 +181,7 @@ static void bap_usb_send_frames_to_usb(void)
181181
uint32_t rb_size;
182182

183183
/* Not enough space to store data */
184-
if (ring_buf_space_get(&usb_in_ring_buf) < sizeof(stereo_frame)) {
184+
if (ring_buffer_space(&usb_in_ring_buf) < sizeof(stereo_frame)) {
185185
if ((fail_cnt % bap_get_stats_interval()) == 0U) {
186186
LOG_WRN("[%zu] Could not send more than %zu frames to USB",
187187
fail_cnt, i);
@@ -219,7 +219,7 @@ static void bap_usb_send_frames_to_usb(void)
219219
}
220220
}
221221

222-
rb_size = ring_buf_put(&usb_in_ring_buf, (uint8_t *)stereo_frame,
222+
rb_size = ring_buffer_write(&usb_in_ring_buf, (uint8_t *)stereo_frame,
223223
sizeof(stereo_frame));
224224
if (rb_size != sizeof(stereo_frame)) {
225225
LOG_WRN("Failed to put frame on USB ring buf");

subsys/gnss/rtk/serial/serial.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
LOG_MODULE_REGISTER(rtk_serial, CONFIG_GNSS_RTK_LOG_LEVEL);
1919

2020
static const struct device *rtk_serial_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_rtk_serial));
21-
static struct ring_buf process_ringbuf;
21+
static struct ring_buffer process_ringbuf;
2222
static uint8_t process_buf[2048];
2323

2424
static void gnss_rtk_process_work_handler(struct k_work *work)
2525
{
2626
static uint8_t work_buf[2048];
27-
uint32_t len = ring_buf_get(&process_ringbuf, work_buf, sizeof(work_buf));
27+
uint32_t len = ring_buffer_read(&process_ringbuf, work_buf, sizeof(work_buf));
2828
uint32_t offset = 0;
2929

3030
ARG_UNUSED(work);
@@ -70,7 +70,7 @@ static void rtk_uart_isr_callback(const struct device *dev, void *user_data)
7070

7171
ret = uart_fifo_read(dev, &c, 1);
7272
if (ret > 0) {
73-
ret = ring_buf_put(&process_ringbuf, &c, 1);
73+
ret = ring_buffer_write(&process_ringbuf, &c, 1);
7474
}
7575
} while (ret > 0);
7676

@@ -86,7 +86,7 @@ static int rtk_serial_client_init(void)
8686
{
8787
int err;
8888

89-
ring_buf_init(&process_ringbuf, ARRAY_SIZE(process_buf), process_buf);
89+
ring_buffer_init(&process_ringbuf, process_buf, ARRAY_SIZE(process_buf));
9090

9191
err = uart_irq_callback_user_data_set(rtk_serial_dev, rtk_uart_isr_callback, NULL);
9292
if (err < 0) {

subsys/mgmt/osdp/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
menuconfig OSDP
88
bool "Open Supervised Device Protocol (OSDP) driver"
9-
select RING_BUFFER
109
imply SERIAL_SUPPORT_INTERRUPT
1110
imply UART_INTERRUPT_DRIVEN
1211
imply UART_USE_RUNTIME_CONFIGURE

subsys/mgmt/osdp/src/osdp.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ LOG_MODULE_REGISTER(osdp, CONFIG_OSDP_LOG_LEVEL);
2626
#endif /* CONFIG_OSDP_SC_ENABLED */
2727

2828
struct osdp_device {
29-
struct ring_buf rx_buf;
30-
struct ring_buf tx_buf;
29+
struct ring_buffer rx_buf;
30+
struct ring_buffer tx_buf;
3131
#ifdef CONFIG_OSDP_MODE_PD
3232
int rx_event_data;
3333
struct k_fifo rx_event_fifo;
@@ -52,15 +52,15 @@ static void osdp_handle_in_byte(struct osdp_device *p, uint8_t *buf, int len)
5252
/* Check for new packet beginning with [FF,53,...] sequence */
5353
if (p->last_byte == 0xFF && buf[0] == 0x53) {
5454
buf[0] = 0xFF;
55-
ring_buf_put(&p->rx_buf, buf, 1); /* put last byte */
55+
ring_buffer_write(&p->rx_buf, buf, 1); /* put last byte */
5656
buf[0] = 0x53;
57-
ring_buf_put(&p->rx_buf, buf, len); /* put rest */
57+
ring_buffer_write(&p->rx_buf, buf, len); /* put rest */
5858
p->wait_for_mark = 0; /* Mark found. Clear flag */
5959
}
6060
p->last_byte = buf[0];
6161
return;
6262
}
63-
ring_buf_put(&p->rx_buf, buf, len);
63+
ring_buffer_write(&p->rx_buf, buf, len);
6464
}
6565

6666
static void osdp_uart_isr(const struct device *dev, void *user_data)
@@ -79,7 +79,7 @@ static void osdp_uart_isr(const struct device *dev, void *user_data)
7979
}
8080

8181
if (uart_irq_tx_ready(dev)) {
82-
len = ring_buf_get(&p->tx_buf, buf, 1);
82+
len = ring_buffer_read(&p->tx_buf, buf, 1);
8383
if (!len) {
8484
uart_irq_tx_disable(dev);
8585
} else {
@@ -99,15 +99,15 @@ static int osdp_uart_receive(void *data, uint8_t *buf, int len)
9999
{
100100
struct osdp_device *p = data;
101101

102-
return (int)ring_buf_get(&p->rx_buf, buf, len);
102+
return (int)ring_buffer_read(&p->rx_buf, buf, len);
103103
}
104104

105105
static int osdp_uart_send(void *data, uint8_t *buf, int len)
106106
{
107107
int sent = 0;
108108
struct osdp_device *p = data;
109109

110-
sent = (int)ring_buf_put(&p->tx_buf, buf, len);
110+
sent = (int)ring_buffer_write(&p->tx_buf, buf, len);
111111
uart_irq_tx_enable(p->dev);
112112
return sent;
113113
}
@@ -117,8 +117,8 @@ static void osdp_uart_flush(void *data)
117117
struct osdp_device *p = data;
118118

119119
p->wait_for_mark = 1;
120-
ring_buf_reset(&p->tx_buf);
121-
ring_buf_reset(&p->rx_buf);
120+
ring_buffer_reset(&p->tx_buf);
121+
ring_buffer_reset(&p->rx_buf);
122122
}
123123

124124
struct osdp *osdp_get_ctx()
@@ -193,8 +193,8 @@ static int osdp_init(void)
193193
k_fifo_init(&p->rx_event_fifo);
194194
#endif
195195

196-
ring_buf_init(&p->rx_buf, sizeof(p->rx_fbuf), p->rx_fbuf);
197-
ring_buf_init(&p->tx_buf, sizeof(p->tx_fbuf), p->tx_fbuf);
196+
ring_buffer_init(&p->rx_buf, p->rx_fbuf, sizeof(p->rx_fbuf));
197+
ring_buffer_init(&p->tx_buf, p->tx_fbuf, sizeof(p->tx_fbuf));
198198

199199
/* init OSDP uart device */
200200
p->dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_osdp_uart));

subsys/testsuite/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ config TEST_BUSY_SIM
210210
bool "Busy simulator"
211211
depends on TEST
212212
select ENTROPY_GENERATOR
213-
select RING_BUFFER if !XOSHIRO_RANDOM_GENERATOR
214213
select COUNTER
215214
help
216215
It simulates cpu load by using counter device to generate interrupts

subsys/testsuite/busy_sim/busy_sim.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static uint32_t get_timeout(bool idle, bool use_rand)
8484
if (use_rand) {
8585
sys_rand_get(&rand_val, sizeof(rand_val));
8686
} else {
87-
len = ring_buf_get(&rnd_rbuf,
87+
len = ring_buffer_read(&rnd_rbuf,
8888
(uint8_t *)&rand_val,
8989
sizeof(rand_val));
9090
if (len < sizeof(rand_val)) {
@@ -198,7 +198,7 @@ static int busy_sim_init(const struct device *dev)
198198

199199
if (config->entropy) {
200200
k_work_init(&sim_work, rng_pool_work_handler);
201-
ring_buf_init(&rnd_rbuf, BUFFER_SIZE, rnd_buf);
201+
ring_buffer_init(&rnd_rbuf, rnd_buf, BUFFER_SIZE);
202202
}
203203

204204
data->us_tick = freq / 1000000;

subsys/tracing/Kconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,12 @@ choice TRACING_METHOD_CHOICE
8080

8181
config TRACING_SYNC
8282
bool "Synchronous Tracing"
83-
select RING_BUFFER
8483
help
8584
Enable synchronous tracing. This requires the backend to be
8685
very low-latency.
8786

8887
config TRACING_ASYNC
8988
bool "Asynchronous Tracing"
90-
select RING_BUFFER
9189
help
9290
Enable asynchronous tracing. This will buffer all the tracing
9391
packets to the ring buffer first, tracing thread will try to

subsys/tracing/tracing_buffer.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6-
6+
#include <zephyr/sys/util.h>
77
#include <zephyr/sys/ring_buffer.h>
88

9-
static struct ring_buf tracing_ring_buf;
9+
static struct ring_buffer tracing_ring_buf;
1010
static uint8_t tracing_buffer[CONFIG_TRACING_BUFFER_SIZE + 1];
1111
static uint8_t tracing_cmd_buffer[CONFIG_TRACING_CMD_BUFFER_SIZE];
1212

@@ -19,51 +19,52 @@ uint32_t tracing_cmd_buffer_alloc(uint8_t **data)
1919

2020
uint32_t tracing_buffer_put_claim(uint8_t **data, uint32_t size)
2121
{
22-
return ring_buf_put_claim(&tracing_ring_buf, data, size);
22+
return MIN(ring_buffer_write_ptr(&tracing_ring_buf, data), size);
2323
}
2424

2525
int tracing_buffer_put_finish(uint32_t size)
2626
{
27-
return ring_buf_put_finish(&tracing_ring_buf, size);
27+
ring_buffer_commit(&tracing_ring_buf, size);
28+
return 0;
2829
}
2930

3031
uint32_t tracing_buffer_put(uint8_t *data, uint32_t size)
3132
{
32-
return ring_buf_put(&tracing_ring_buf, data, size);
33+
return ring_buffer_write(&tracing_ring_buf, data, size);
3334
}
3435

3536
uint32_t tracing_buffer_get_claim(uint8_t **data, uint32_t size)
3637
{
37-
return ring_buf_get_claim(&tracing_ring_buf, data, size);
38+
return MIN(ring_buffer_read_ptr(&tracing_ring_buf, data), size);
3839
}
3940

4041
int tracing_buffer_get_finish(uint32_t size)
4142
{
42-
return ring_buf_get_finish(&tracing_ring_buf, size);
43+
ring_buffer_consume(&tracing_ring_buf, size);
44+
return 0;
4345
}
4446

4547
uint32_t tracing_buffer_get(uint8_t *data, uint32_t size)
4648
{
47-
return ring_buf_get(&tracing_ring_buf, data, size);
49+
return ring_buffer_read(&tracing_ring_buf, data, size);
4850
}
4951

5052
void tracing_buffer_init(void)
5153
{
52-
ring_buf_init(&tracing_ring_buf,
53-
sizeof(tracing_buffer), tracing_buffer);
54+
ring_buffer_init(&tracing_ring_buf, tracing_buffer, sizeof(tracing_buffer));
5455
}
5556

5657
bool tracing_buffer_is_empty(void)
5758
{
58-
return ring_buf_is_empty(&tracing_ring_buf);
59+
return ring_buffer_empty(&tracing_ring_buf);
5960
}
6061

6162
uint32_t tracing_buffer_capacity_get(void)
6263
{
63-
return ring_buf_capacity_get(&tracing_ring_buf);
64+
return ring_buffer_capacity(&tracing_ring_buf);
6465
}
6566

6667
uint32_t tracing_buffer_space_get(void)
6768
{
68-
return ring_buf_space_get(&tracing_ring_buf);
69+
return ring_buffer_space(&tracing_ring_buf);
6970
}

0 commit comments

Comments
 (0)