Skip to content

Commit 3b2d943

Browse files
committed
drivers/serial: update to use new ring_buffer api
Move to new ring_buffer api. Signed-off-by: Måns Ansgariusson <[email protected]>
1 parent 6c023cc commit 3b2d943

File tree

10 files changed

+87
-110
lines changed

10 files changed

+87
-110
lines changed

drivers/serial/Kconfig.bitbang

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ config UART_BITBANG
88
select SERIAL_HAS_DRIVER
99
select SERIAL_SUPPORT_INTERRUPT
1010
select COUNTER
11-
select RING_BUFFER
1211
help
1312
Enable the Bitbang UART controller.
1413
The driver relies on counter interrupts to generate/sample UART

drivers/serial/Kconfig.bridge

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ config UART_BRIDGE
66
default y
77
depends on DT_HAS_ZEPHYR_UART_BRIDGE_ENABLED
88
select UART_INTERRUPT_DRIVEN
9-
select RING_BUFFER
109
help
1110
Enable the UART bridge driver.
1211

drivers/serial/Kconfig.bt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ config UART_BT
66
depends on BT_ZEPHYR_NUS
77
depends on DT_HAS_ZEPHYR_NUS_UART_ENABLED
88
select UART_INTERRUPT_DRIVEN
9-
select RING_BUFFER
109
select EXPERIMENTAL
1110
select SERIAL_SUPPORT_INTERRUPT
1211
help

drivers/serial/Kconfig.emul

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ config UART_EMUL
1111
select SERIAL_HAS_DRIVER
1212
select SERIAL_SUPPORT_INTERRUPT
1313
select SERIAL_SUPPORT_ASYNC
14-
select RING_BUFFER
1514
select EXPERIMENTAL
1615
help
1716
Enable the emulated UART driver.

drivers/serial/Kconfig.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ config SERIAL_TEST
88
select SERIAL_HAS_DRIVER
99
select SERIAL_SUPPORT_INTERRUPT
1010
select SERIAL_SUPPORT_ASYNC
11-
select RING_BUFFER if (UART_INTERRUPT_DRIVEN || UART_ASYNC_API)

drivers/serial/serial_test.c

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ LOG_MODULE_REGISTER(mock_serial, CONFIG_LOG_DEFAULT_LEVEL);
2323

2424
#define DT_DRV_COMPAT vnd_serial
2525
struct serial_vnd_data {
26-
#ifdef CONFIG_RING_BUFFER
2726
struct ring_buf *written;
2827
struct ring_buf *read_queue;
29-
#endif
3028
serial_vnd_write_cb_t callback;
3129
void *callback_data;
3230
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
@@ -49,14 +47,14 @@ static bool is_irq_rx_pending(const struct device *dev)
4947
{
5048
struct serial_vnd_data *data = dev->data;
5149

52-
return !ring_buf_is_empty(data->read_queue);
50+
return !ring_buffer_empty(data->read_queue);
5351
}
5452

5553
static bool is_irq_tx_pending(const struct device *dev)
5654
{
5755
struct serial_vnd_data *data = dev->data;
5856

59-
return ring_buf_space_get(data->written) != 0;
57+
return ring_buffer_space(data->written) != 0;
6058
}
6159

6260
static void irq_process(const struct device *dev)
@@ -105,7 +103,7 @@ static void irq_rx_disable(const struct device *dev)
105103
static int irq_rx_ready(const struct device *dev)
106104
{
107105
struct serial_vnd_data *data = dev->data;
108-
bool ready = !ring_buf_is_empty(data->read_queue);
106+
bool ready = !ring_buffer_empty(data->read_queue);
109107

110108
LOG_DBG("rx ready: %d", ready);
111109
return ready;
@@ -131,7 +129,7 @@ static void irq_tx_disable(const struct device *dev)
131129
static int irq_tx_ready(const struct device *dev)
132130
{
133131
struct serial_vnd_data *data = dev->data;
134-
int available = ring_buf_space_get(data->written);
132+
int available = ring_buffer_space(data->written);
135133

136134
LOG_DBG("tx ready: %d", available);
137135
return available;
@@ -163,7 +161,7 @@ static int irq_update(const struct device *dev)
163161
static int fifo_fill(const struct device *dev, const uint8_t *tx_data, int size)
164162
{
165163
struct serial_vnd_data *data = dev->data;
166-
uint32_t write_len = ring_buf_put(data->written, tx_data, size);
164+
uint32_t write_len = ring_buffer_write(data->written, tx_data, size);
167165

168166
if (data->callback) {
169167
data->callback(dev, data->callback_data);
@@ -174,7 +172,7 @@ static int fifo_fill(const struct device *dev, const uint8_t *tx_data, int size)
174172
static int fifo_read(const struct device *dev, uint8_t *rx_data, const int size)
175173
{
176174
struct serial_vnd_data *data = dev->data;
177-
int read_len = ring_buf_get(data->read_queue, rx_data, size);
175+
int read_len = ring_buffer_read(data->read_queue, rx_data, size);
178176

179177
LOG_HEXDUMP_DBG(rx_data, read_len, "");
180178
return read_len;
@@ -183,33 +181,29 @@ static int fifo_read(const struct device *dev, uint8_t *rx_data, const int size)
183181

184182
static int serial_vnd_poll_in(const struct device *dev, unsigned char *c)
185183
{
186-
#ifdef CONFIG_RING_BUFFER
184+
187185
struct serial_vnd_data *data = dev->data;
188186
uint32_t bytes_read;
189187

190188
if (data == NULL || data->read_queue == NULL) {
191189
return -ENOTSUP;
192190
}
193-
bytes_read = ring_buf_get(data->read_queue, c, 1);
191+
bytes_read = ring_buffer_read(data->read_queue, c, 1);
194192
if (bytes_read == 1) {
195193
return 0;
196194
}
197195
return -1;
198-
#else
199-
return -ENOTSUP;
200-
#endif
201196
}
202197

203198
static void serial_vnd_poll_out(const struct device *dev, unsigned char c)
204199
{
205200
struct serial_vnd_data *data = dev->data;
206201

207-
#ifdef CONFIG_RING_BUFFER
208202
if (data == NULL || data->written == NULL) {
209203
return;
210204
}
211-
ring_buf_put(data->written, &c, 1);
212-
#endif
205+
ring_buffer_write(data->written, &c, 1);
206+
213207
if (data->callback) {
214208
data->callback(dev, data->callback_data);
215209
}
@@ -219,7 +213,6 @@ static void serial_vnd_poll_out(const struct device *dev, unsigned char c)
219213
static void async_rx_run(const struct device *dev);
220214
#endif
221215

222-
#ifdef CONFIG_RING_BUFFER
223216
int serial_vnd_queue_in_data(const struct device *dev, const unsigned char *c, uint32_t size)
224217
{
225218
struct serial_vnd_data *data = dev->data;
@@ -228,7 +221,7 @@ int serial_vnd_queue_in_data(const struct device *dev, const unsigned char *c, u
228221
if (data == NULL || data->read_queue == NULL) {
229222
return -ENOTSUP;
230223
}
231-
write_size = ring_buf_put(data->read_queue, c, size);
224+
write_size = ring_buffer_write(data->read_queue, c, size);
232225

233226
LOG_DBG("size %u write_size %u", size, write_size);
234227
LOG_HEXDUMP_DBG(c, write_size, "");
@@ -253,7 +246,7 @@ uint32_t serial_vnd_out_data_size_get(const struct device *dev)
253246
if (data == NULL || data->written == NULL) {
254247
return -ENOTSUP;
255248
}
256-
return ring_buf_size_get(data->written);
249+
return ring_buffer_size(data->written);
257250
}
258251

259252
uint32_t serial_vnd_read_out_data(const struct device *dev, unsigned char *out_data, uint32_t size)
@@ -263,7 +256,7 @@ uint32_t serial_vnd_read_out_data(const struct device *dev, unsigned char *out_d
263256
if (data == NULL || data->written == NULL) {
264257
return -ENOTSUP;
265258
}
266-
return ring_buf_get(data->written, out_data, size);
259+
return ring_buffer_read(data->written, out_data, size);
267260
}
268261

269262
uint32_t serial_vnd_peek_out_data(const struct device *dev, unsigned char *out_data, uint32_t size)
@@ -275,7 +268,7 @@ uint32_t serial_vnd_peek_out_data(const struct device *dev, unsigned char *out_d
275268
}
276269
return ring_buf_peek(data->written, out_data, size);
277270
}
278-
#endif
271+
279272

280273
void serial_vnd_set_callback(const struct device *dev, serial_vnd_write_cb_t callback,
281274
void *user_data)
@@ -345,7 +338,7 @@ static int serial_vnd_api_tx(const struct device *dev, const uint8_t *tx_data, s
345338
return -EINVAL;
346339
}
347340

348-
write_len = ring_buf_put(data->written, tx_data, len);
341+
write_len = ring_buffer_write(data->written, tx_data, len);
349342
if (data->callback) {
350343
data->callback(dev, data->callback_data);
351344
}
@@ -377,7 +370,7 @@ static void async_rx_run(const struct device *dev)
377370

378371
read_remaining = data->read_size - data->read_position;
379372

380-
read_len = ring_buf_get(data->read_queue, &data->read_buf[data->read_position],
373+
read_len = ring_buffer_read(data->read_queue, &data->read_buf[data->read_position],
381374
read_remaining);
382375

383376
if (read_len != 0) {
@@ -456,8 +449,8 @@ static DEVICE_API(uart, serial_vnd_api) = {
456449
};
457450

458451
#define VND_SERIAL_DATA_BUFFER(n) \
459-
RING_BUF_DECLARE(written_data_##n, DT_INST_PROP(n, buffer_size)); \
460-
RING_BUF_DECLARE(read_queue_##n, DT_INST_PROP(n, buffer_size)); \
452+
RING_BUFFER_DECLARE(written_data_##n, DT_INST_PROP(n, buffer_size)); \
453+
RING_BUFFER_DECLARE(read_queue_##n, DT_INST_PROP(n, buffer_size)); \
461454
static struct serial_vnd_data serial_vnd_data_##n = { \
462455
.written = &written_data_##n, \
463456
.read_queue = &read_queue_##n, \

drivers/serial/uart_bitbang.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct uart_bitbang_data {
5656
/* Tx counter config */
5757
struct counter_top_cfg tx_counter_cfg;
5858
/* Tx ring buffer */
59-
struct ring_buf *tx_ringbuf;
59+
struct ring_buffer *tx_ringbuf;
6060
/* Rx state */
6161
enum uart_bitbang_state rx_state;
6262
/* Rx bit index */
@@ -70,7 +70,7 @@ struct uart_bitbang_data {
7070
/* Rx callback data */
7171
struct gpio_callback rx_gpio_cb_data;
7272
/* Rx ring buffer */
73-
struct ring_buf *rx_ringbuf;
73+
struct ring_buffer *rx_ringbuf;
7474
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
7575
/* Interrupt flags */
7676
#define UART_BITBANG_IRQ_TC (1 << 0)
@@ -196,7 +196,8 @@ static void uart_bitbang_rx_counter_top_interrupt(const struct device *dev, void
196196
}
197197

198198
/* Push data received to rx ring buffer */
199-
ring_buf_put(data->rx_ringbuf, (const uint8_t *)&data->rx_data, sizeof(uint16_t));
199+
ring_buffer_write(data->rx_ringbuf, (const uint8_t *)&data->rx_data,
200+
sizeof(uint16_t));
200201

201202
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
202203
if ((data->user_cb) && (data->irq & UART_BITBANG_IRQ_RXNE)) {
@@ -233,7 +234,7 @@ static int uart_bitbang_poll_in_u16(const struct device *dev, uint16_t *in_u16)
233234
{
234235
struct uart_bitbang_data *data = dev->data;
235236

236-
uint32_t s = ring_buf_get(data->rx_ringbuf, (uint8_t *)in_u16, sizeof(uint16_t));
237+
uint32_t s = ring_buffer_read(data->rx_ringbuf, (uint8_t *)in_u16, sizeof(uint16_t));
237238

238239
return (s == sizeof(uint16_t)) ? 0 : -1;
239240
}
@@ -265,7 +266,7 @@ static void uart_bitbang_tx_counter_top_interrupt(const struct device *dev, void
265266
switch (data->tx_state) {
266267
case UART_BITBANG_IDLE:
267268
/* Claim the next data */
268-
size = ring_buf_get_claim(data->tx_ringbuf, (uint8_t **)&data->tx_data,
269+
size = MIN(ring_buffer_read_ptr(data->tx_ringbuf, (uint8_t **)&data->tx_data),
269270
sizeof(uint16_t));
270271
if (size == sizeof(uint16_t)) {
271272
/* Start next transmission */
@@ -333,7 +334,7 @@ static void uart_bitbang_tx_counter_top_interrupt(const struct device *dev, void
333334
break;
334335
case UART_BITBANG_COMPLETE:
335336
/* Terminate current transfer */
336-
ring_buf_get_finish(data->tx_ringbuf, sizeof(uint16_t));
337+
ring_buffer_consume(data->tx_ringbuf, sizeof(uint16_t));
337338
data->tx_state = UART_BITBANG_IDLE;
338339
break;
339340
}
@@ -348,7 +349,7 @@ static void uart_bitbang_poll_out_u16(const struct device *dev, uint16_t out_u16
348349
if (config->tx_gpio.port != NULL) {
349350

350351
/* Push data to send to tx ring buffer */
351-
ring_buf_put(data->tx_ringbuf, (const uint8_t *)&out_u16, sizeof(uint16_t));
352+
ring_buffer_write(data->tx_ringbuf, (const uint8_t *)&out_u16, sizeof(uint16_t));
352353

353354
/* Start tx counter if not already started */
354355
counter_reset(config->tx_counter);
@@ -497,7 +498,7 @@ static int uart_bitbang_irq_tx_ready(const struct device *dev)
497498
{
498499
struct uart_bitbang_data *data = dev->data;
499500

500-
return (int)(ring_buf_space_get(data->tx_ringbuf) / sizeof(uint16_t));
501+
return (int)(ring_buffer_space(data->tx_ringbuf) / sizeof(uint16_t));
501502
}
502503

503504
static void uart_bitbang_irq_rx_enable(const struct device *dev)
@@ -520,14 +521,14 @@ static int uart_bitbang_irq_tx_complete(const struct device *dev)
520521
{
521522
struct uart_bitbang_data *data = dev->data;
522523

523-
return ring_buf_is_empty(data->tx_ringbuf) ? 1 : 0;
524+
return ring_buffer_empty(data->tx_ringbuf) ? 1 : 0;
524525
}
525526

526527
static int uart_bitbang_irq_rx_ready(const struct device *dev)
527528
{
528529
struct uart_bitbang_data *data = dev->data;
529530

530-
return (ring_buf_size_get(data->rx_ringbuf) > 0) ? 1 : 0;
531+
return (ring_buffer_size(data->rx_ringbuf) > 0) ? 1 : 0;
531532
}
532533

533534
static void uart_bitbang_irq_err_enable(const struct device *dev)
@@ -777,8 +778,8 @@ static int uart_bitbang_init(const struct device *dev)
777778
.uart_cfg = &uart_cfg_##index, \
778779
.msb = DT_INST_PROP_OR(index, msb, false), \
779780
}; \
780-
RING_BUF_DECLARE(uart_bitbang_tx_ringbuf##index, DT_INST_PROP(index, tx_fifo_size)); \
781-
RING_BUF_DECLARE(uart_bitbang_rx_ringbuf##index, DT_INST_PROP(index, rx_fifo_size)); \
781+
RING_BUFFER_DECLARE(uart_bitbang_tx_ringbuf##index, DT_INST_PROP(index, tx_fifo_size)); \
782+
RING_BUFFER_DECLARE(uart_bitbang_rx_ringbuf##index, DT_INST_PROP(index, rx_fifo_size)); \
782783
static struct uart_bitbang_data uart_bitbang_data_##index = { \
783784
.config = &uart_bitbang_config_##index, \
784785
.tx_ringbuf = &uart_bitbang_tx_ringbuf##index, \

0 commit comments

Comments
 (0)