Skip to content

Commit d1327c4

Browse files
committed
subsys/usb: update to new ring_buffer api
move to new ring_buffer api. Signed-off-by: Måns Ansgariusson <[email protected]>
1 parent 1ee27f7 commit d1327c4

File tree

6 files changed

+37
-40
lines changed

6 files changed

+37
-40
lines changed

subsys/usb/device/class/Kconfig.cdc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ config USB_CDC_ACM
1111
depends on DT_HAS_ZEPHYR_CDC_ACM_UART_ENABLED
1212
select SERIAL_HAS_DRIVER
1313
select SERIAL_SUPPORT_INTERRUPT
14-
select RING_BUFFER
1514
select UART_INTERRUPT_DRIVEN
1615
help
1716
USB CDC ACM class support.

subsys/usb/device/class/cdc_acm.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static void cdc_acm_write_cb(uint8_t ep, int size, void *priv)
230230
* ensure that actual payload will not be sent before initialization
231231
* timeout passes.
232232
*/
233-
if (ring_buf_is_empty(dev_data->tx_ringbuf) && size) {
233+
if (ring_buffer_empty(dev_data->tx_ringbuf) && size) {
234234
LOG_DBG("tx_ringbuf is empty");
235235
return;
236236
}
@@ -303,13 +303,13 @@ static void cdc_acm_read_cb(uint8_t ep, int size, void *priv)
303303
size_t wrote;
304304

305305
LOG_DBG("ep %x size %d dev_data %p rx_ringbuf space %u",
306-
ep, size, dev_data, ring_buf_space_get(dev_data->rx_ringbuf));
306+
ep, size, dev_data, ring_buffer_space(dev_data->rx_ringbuf));
307307

308308
if (size <= 0) {
309309
goto done;
310310
}
311311

312-
wrote = ring_buf_put(dev_data->rx_ringbuf, dev_data->rx_buf, size);
312+
wrote = ring_buffer_write(dev_data->rx_ringbuf, dev_data->rx_buf, size);
313313
if (wrote < size) {
314314
LOG_ERR("Ring buffer full, drop %zd bytes", size - wrote);
315315
}
@@ -321,7 +321,7 @@ static void cdc_acm_read_cb(uint8_t ep, int size, void *priv)
321321
k_work_submit_to_queue(&USB_WORK_Q, &dev_data->cb_work);
322322
}
323323

324-
if (ring_buf_space_get(dev_data->rx_ringbuf) < sizeof(dev_data->rx_buf)) {
324+
if (ring_buffer_space(dev_data->rx_ringbuf) < sizeof(dev_data->rx_buf)) {
325325
dev_data->rx_paused = true;
326326
return;
327327
}
@@ -526,10 +526,10 @@ static int cdc_acm_fifo_fill(const struct device *dev,
526526
size_t wrote;
527527

528528
LOG_DBG("dev_data %p len %d tx_ringbuf space %u",
529-
dev_data, len, ring_buf_space_get(dev_data->tx_ringbuf));
529+
dev_data, len, ring_buffer_space(dev_data->tx_ringbuf));
530530

531531
lock = irq_lock();
532-
wrote = ring_buf_put(dev_data->tx_ringbuf, tx_data, len);
532+
wrote = ring_buffer_write(dev_data->tx_ringbuf, tx_data, len);
533533
irq_unlock(lock);
534534
LOG_DBG("Wrote %zu of %d bytes to TX ringbuffer", wrote, len);
535535

@@ -557,12 +557,12 @@ static int cdc_acm_fifo_read(const struct device *dev, uint8_t *rx_data,
557557
uint32_t len;
558558

559559
LOG_DBG("dev %p size %d rx_ringbuf space %u",
560-
dev, size, ring_buf_space_get(dev_data->rx_ringbuf));
560+
dev, size, ring_buffer_space(dev_data->rx_ringbuf));
561561

562-
len = ring_buf_get(dev_data->rx_ringbuf, rx_data, size);
562+
len = ring_buffer_read(dev_data->rx_ringbuf, rx_data, size);
563563

564564
if (dev_data->rx_paused == true) {
565-
if (ring_buf_space_get(dev_data->rx_ringbuf) >= CDC_ACM_BUFFER_SIZE) {
565+
if (ring_buffer_space(dev_data->rx_ringbuf) >= CDC_ACM_BUFFER_SIZE) {
566566
struct usb_cfg_data *cfg = (void *)dev->config;
567567

568568
if (dev_data->configured) {
@@ -615,7 +615,7 @@ static int cdc_acm_irq_tx_ready(const struct device *dev)
615615
struct cdc_acm_dev_data_t * const dev_data = dev->data;
616616

617617
if (dev_data->tx_irq_ena && dev_data->tx_ready) {
618-
return ring_buf_space_get(dev_data->tx_ringbuf);
618+
return ring_buffer_space(dev_data->tx_ringbuf);
619619
}
620620

621621
return 0;
@@ -694,11 +694,11 @@ static int cdc_acm_irq_update(const struct device *dev)
694694
{
695695
struct cdc_acm_dev_data_t * const dev_data = dev->data;
696696

697-
if (!ring_buf_space_get(dev_data->tx_ringbuf)) {
697+
if (!ring_buffer_space(dev_data->tx_ringbuf)) {
698698
dev_data->tx_ready = false;
699699
}
700700

701-
if (ring_buf_is_empty(dev_data->rx_ringbuf)) {
701+
if (ring_buffer_empty(dev_data->rx_ringbuf)) {
702702
dev_data->rx_ready = false;
703703
}
704704

@@ -1033,7 +1033,7 @@ static void cdc_acm_poll_out(const struct device *dev, unsigned char c)
10331033

10341034
while (true) {
10351035
lock = irq_lock();
1036-
wrote = ring_buf_put(dev_data->tx_ringbuf, &c, 1);
1036+
wrote = ring_buffer_write(dev_data->tx_ringbuf, &c, 1);
10371037
irq_unlock(lock);
10381038
if (wrote == 1) {
10391039
break;

subsys/usb/device_next/class/Kconfig.cdc_acm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ config USBD_CDC_ACM_CLASS
88
depends on DT_HAS_ZEPHYR_CDC_ACM_UART_ENABLED
99
select SERIAL_HAS_DRIVER
1010
select SERIAL_SUPPORT_INTERRUPT
11-
select RING_BUFFER
1211
select UART_INTERRUPT_DRIVEN
1312
default y
1413
help

subsys/usb/device_next/class/Kconfig.midi2

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

55
config USBD_MIDI2_CLASS
66
bool "USB MIDI 2.0 class support [EXPERIMENTAL]"
7-
select RING_BUFFER
87
help
98
Enable the USB MIDI 2.0 device class support.
109

subsys/usb/device_next/class/usbd_cdc_acm.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static int usbd_cdc_acm_request(struct usbd_class_data *const c_data,
309309
size_t done;
310310

311311
LOG_HEXDUMP_INF(buf->data, buf->len, "");
312-
done = ring_buf_put(data->rx_fifo.rb, buf->data, buf->len);
312+
done = ring_buffer_write(data->rx_fifo.rb, buf->data, buf->len);
313313
if (done && data->cb) {
314314
cdc_acm_work_submit(&data->irq_cb_work);
315315
}
@@ -326,7 +326,7 @@ static int usbd_cdc_acm_request(struct usbd_class_data *const c_data,
326326

327327
atomic_clear_bit(&data->state, CDC_ACM_TX_FIFO_BUSY);
328328

329-
if (!ring_buf_is_empty(data->tx_fifo.rb)) {
329+
if (!ring_buffer_empty(data->tx_fifo.rb)) {
330330
/* Queue pending TX data on IN endpoint */
331331
cdc_acm_work_schedule(&data->tx_fifo_work, K_NO_WAIT);
332332
}
@@ -361,7 +361,7 @@ static void usbd_cdc_acm_enable(struct usbd_class_data *const c_data)
361361
}
362362

363363
if (atomic_test_bit(&data->state, CDC_ACM_IRQ_TX_ENABLED)) {
364-
if (ring_buf_space_get(data->tx_fifo.rb)) {
364+
if (ring_buffer_space(data->tx_fifo.rb)) {
365365
/* Raise TX ready interrupt */
366366
cdc_acm_work_submit(&data->irq_cb_work);
367367
} else {
@@ -658,7 +658,7 @@ static void cdc_acm_tx_fifo_handler(struct k_work *work)
658658
return;
659659
}
660660

661-
len = ring_buf_get(data->tx_fifo.rb, buf->data, buf->size);
661+
len = ring_buffer_read(data->tx_fifo.rb, buf->data, buf->size);
662662
net_buf_add(buf, len);
663663

664664
data->zlp_needed = len != 0 && len % cdc_acm_get_bulk_mps(c_data) == 0;
@@ -697,7 +697,7 @@ static void cdc_acm_rx_fifo_handler(struct k_work *work)
697697
return;
698698
}
699699

700-
if (ring_buf_space_get(data->rx_fifo.rb) < cdc_acm_get_bulk_mps(c_data)) {
700+
if (ring_buffer_space(data->rx_fifo.rb) < cdc_acm_get_bulk_mps(c_data)) {
701701
LOG_INF("RX buffer to small, throttle");
702702
return;
703703
}
@@ -729,7 +729,7 @@ static void cdc_acm_irq_tx_enable(const struct device *dev)
729729

730730
atomic_set_bit(&data->state, CDC_ACM_IRQ_TX_ENABLED);
731731

732-
if (ring_buf_space_get(data->tx_fifo.rb)) {
732+
if (ring_buffer_space(data->tx_fifo.rb)) {
733733
LOG_INF("tx_en: trigger irq_cb_work");
734734
cdc_acm_work_submit(&data->irq_cb_work);
735735
}
@@ -749,7 +749,7 @@ static void cdc_acm_irq_rx_enable(const struct device *dev)
749749
atomic_set_bit(&data->state, CDC_ACM_IRQ_RX_ENABLED);
750750

751751
/* Permit buffer to be drained regardless of USB state */
752-
if (!ring_buf_is_empty(data->rx_fifo.rb)) {
752+
if (!ring_buffer_empty(data->rx_fifo.rb)) {
753753
LOG_INF("rx_en: trigger irq_cb_work");
754754
cdc_acm_work_submit(&data->irq_cb_work);
755755
}
@@ -782,14 +782,14 @@ static int cdc_acm_fifo_fill(const struct device *dev,
782782
}
783783

784784
key = k_spin_lock(&data->lock);
785-
done = ring_buf_put(data->tx_fifo.rb, tx_data, len);
785+
done = ring_buffer_write(data->tx_fifo.rb, tx_data, len);
786786
k_spin_unlock(&data->lock, key);
787787
if (done) {
788788
data->tx_fifo.altered = true;
789789
}
790790

791791
LOG_INF("UART dev %p, len %d, remaining space %u",
792-
dev, len, ring_buf_space_get(data->tx_fifo.rb));
792+
dev, len, ring_buffer_space(data->tx_fifo.rb));
793793

794794
return done;
795795
}
@@ -810,7 +810,7 @@ static int cdc_acm_fifo_read(const struct device *dev,
810810
return 0;
811811
}
812812

813-
len = ring_buf_get(data->rx_fifo.rb, rx_data, size);
813+
len = ring_buffer_read(data->rx_fifo.rb, rx_data, size);
814814
if (len) {
815815
data->rx_fifo.altered = true;
816816
}
@@ -824,7 +824,7 @@ static int cdc_acm_irq_tx_ready(const struct device *dev)
824824

825825
if (check_wq_ctx(dev)) {
826826
if (data->tx_fifo.irq) {
827-
return ring_buf_space_get(data->tx_fifo.rb);
827+
return ring_buffer_space(data->tx_fifo.rb);
828828
}
829829
} else {
830830
LOG_WRN("Invoked by inappropriate context");
@@ -878,14 +878,14 @@ static int cdc_acm_irq_update(const struct device *dev)
878878
}
879879

880880
if (atomic_test_bit(&data->state, CDC_ACM_IRQ_RX_ENABLED) &&
881-
!ring_buf_is_empty(data->rx_fifo.rb)) {
881+
!ring_buffer_empty(data->rx_fifo.rb)) {
882882
data->rx_fifo.irq = true;
883883
} else {
884884
data->rx_fifo.irq = false;
885885
}
886886

887887
if (atomic_test_bit(&data->state, CDC_ACM_IRQ_TX_ENABLED) &&
888-
ring_buf_space_get(data->tx_fifo.rb)) {
888+
ring_buffer_space(data->tx_fifo.rb)) {
889889
data->tx_fifo.irq = true;
890890
} else {
891891
data->tx_fifo.irq = false;
@@ -947,13 +947,13 @@ static void cdc_acm_irq_cb_handler(struct k_work *work)
947947
}
948948

949949
if (atomic_test_bit(&data->state, CDC_ACM_IRQ_RX_ENABLED) &&
950-
!ring_buf_is_empty(data->rx_fifo.rb)) {
950+
!ring_buffer_empty(data->rx_fifo.rb)) {
951951
LOG_DBG("rx irq pending, submit irq_cb_work");
952952
cdc_acm_work_submit(&data->irq_cb_work);
953953
}
954954

955955
if (atomic_test_bit(&data->state, CDC_ACM_IRQ_TX_ENABLED) &&
956-
ring_buf_space_get(data->tx_fifo.rb)) {
956+
ring_buffer_space(data->tx_fifo.rb)) {
957957
LOG_DBG("tx irq pending, submit irq_cb_work");
958958
cdc_acm_work_submit(&data->irq_cb_work);
959959
}
@@ -975,11 +975,11 @@ static int cdc_acm_poll_in(const struct device *dev, unsigned char *const c)
975975
uint32_t len;
976976
int ret = -1;
977977

978-
if (ring_buf_is_empty(data->rx_fifo.rb)) {
978+
if (ring_buffer_empty(data->rx_fifo.rb)) {
979979
return ret;
980980
}
981981

982-
len = ring_buf_get(data->rx_fifo.rb, c, 1);
982+
len = ring_buffer_read(data->rx_fifo.rb, c, 1);
983983
if (len) {
984984
cdc_acm_work_submit(&data->rx_fifo_work);
985985
ret = 0;
@@ -996,7 +996,7 @@ static void cdc_acm_poll_out(const struct device *dev, const unsigned char c)
996996

997997
while (true) {
998998
key = k_spin_lock(&data->lock);
999-
wrote = ring_buf_put(data->tx_fifo.rb, &c, 1);
999+
wrote = ring_buffer_write(data->tx_fifo.rb, &c, 1);
10001000
k_spin_unlock(&data->lock, key);
10011001

10021002
if (wrote == 1) {
@@ -1119,8 +1119,8 @@ static int usbd_cdc_acm_preinit(const struct device *dev)
11191119
{
11201120
struct cdc_acm_uart_data *const data = dev->data;
11211121

1122-
ring_buf_reset(data->tx_fifo.rb);
1123-
ring_buf_reset(data->rx_fifo.rb);
1122+
ring_buffer_reset(data->tx_fifo.rb);
1123+
ring_buffer_reset(data->rx_fifo.rb);
11241124

11251125
k_work_init_delayable(&data->tx_fifo_work, cdc_acm_tx_fifo_handler);
11261126
k_work_init(&data->rx_fifo_work, cdc_acm_rx_fifo_handler);

subsys/usb/device_next/class/usbd_midi2.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ static void usbd_midi_tx_work(struct k_work *work)
440440
return;
441441
}
442442

443-
net_buf_add(buf, ring_buf_get(&data->tx_queue, buf->data, buf->size));
443+
net_buf_add(buf, ring_buffer_read(&data->tx_queue, buf->data, buf->size));
444444
LOG_HEXDUMP_DBG(buf->data, buf->len, "MIDI2 - Tx DATA");
445445

446446
ret = usbd_ep_enqueue(data->class_data, buf);
@@ -455,7 +455,7 @@ static int usbd_midi_preinit(const struct device *dev)
455455
struct usbd_midi_data *data = dev->data;
456456

457457
LOG_DBG("Init device %s", dev->name);
458-
ring_buf_init(&data->tx_queue, MIDI_QUEUE_SIZE, data->tx_queue_buf);
458+
ring_buffer_init(&data->tx_queue, data->tx_queue_buf, MIDI_QUEUE_SIZE);
459459
k_work_init(&data->rx_work, usbd_midi_rx_work);
460460
k_work_init(&data->tx_work, usbd_midi_tx_work);
461461

@@ -475,14 +475,14 @@ int usbd_midi_send(const struct device *dev, const struct midi_ump ump)
475475
return -EIO;
476476
}
477477

478-
if (buflen > ring_buf_space_get(&data->tx_queue)) {
478+
if (buflen > ring_buffer_space(&data->tx_queue)) {
479479
LOG_WRN("Not enough space in tx queue");
480480
return -ENOBUFS;
481481
}
482482

483483
for (size_t i = 0; i < words; i++) {
484484
word = sys_cpu_to_le32(ump.data[i]);
485-
ring_buf_put(&data->tx_queue, (const uint8_t *)&word, 4);
485+
ring_buffer_write(&data->tx_queue, (const uint8_t *)&word, 4);
486486
}
487487
k_work_submit(&data->tx_work);
488488

0 commit comments

Comments
 (0)