Skip to content

Commit

Permalink
serial/usb: update struct ring_buf users
Browse files Browse the repository at this point in the history
Update the interrupt driver UART drivers that use `struct ring_buf`
internally to report the number of bytes that can be pushed in
`uart_fifo_fill` without fragmentation.

Signed-off-by: Jordan Yates <[email protected]>
  • Loading branch information
JordanYates authored and aescolar committed Oct 2, 2024
1 parent 5bd53b6 commit 81352d0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions drivers/serial/serial_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ static void irq_tx_disable(const struct device *dev)
static int irq_tx_ready(const struct device *dev)
{
struct serial_vnd_data *data = dev->data;
bool ready = (ring_buf_space_get(data->written) != 0);
int available = ring_buf_space_get(data->written);

LOG_DBG("tx ready: %d", ready);
return ready;
LOG_DBG("tx ready: %d", available);
return available;
}

static void irq_callback_set(const struct device *dev, uart_irq_callback_user_data_t cb,
Expand Down
6 changes: 3 additions & 3 deletions drivers/serial/uart_emul.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,18 @@ static int uart_emul_fifo_read(const struct device *dev, uint8_t *rx_data, int s

static int uart_emul_irq_tx_ready(const struct device *dev)
{
bool ready = false;
int available = 0;
struct uart_emul_data *data = dev->data;

K_SPINLOCK(&data->tx_lock) {
if (!data->tx_irq_en) {
K_SPINLOCK_BREAK;
}

ready = ring_buf_space_get(data->tx_rb) > 0;
available = ring_buf_space_get(data->tx_rb);
}

return ready;
return available;
}

static int uart_emul_irq_rx_ready(const struct device *dev)
Expand Down
2 changes: 1 addition & 1 deletion subsys/usb/device/class/cdc_acm.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ static int cdc_acm_irq_tx_ready(const struct device *dev)
struct cdc_acm_dev_data_t * const dev_data = dev->data;

if (dev_data->tx_irq_ena && dev_data->tx_ready) {
return 1;
return ring_buf_space_get(dev_data->tx_ringbuf);
}

return 0;
Expand Down
4 changes: 1 addition & 3 deletions subsys/usb/device_next/class/usbd_cdc_acm.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,7 @@ static int cdc_acm_irq_tx_ready(const struct device *dev)
struct cdc_acm_uart_data *const data = dev->data;

if (check_wq_ctx(dev)) {
if (ring_buf_space_get(data->tx_fifo.rb)) {
return 1;
}
return ring_buf_space_get(data->tx_fifo.rb);
} else {
LOG_WRN("Invoked by inappropriate context");
__ASSERT_NO_MSG(false);
Expand Down

0 comments on commit 81352d0

Please sign in to comment.