Skip to content

Commit

Permalink
modem: backend: uart: Implement transmit idle event
Browse files Browse the repository at this point in the history
Make async and interrupt driven UART backends notify transmit
idle when transmit is idle.

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
  • Loading branch information
bjarki-andreasen authored and fabiobaltieri committed Jan 11, 2024
1 parent 516af3c commit 8c6a9ee
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/zephyr/modem/backend/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct modem_backend_uart {
const struct device *uart;
struct modem_pipe pipe;
struct k_work receive_ready_work;
struct k_work transmit_idle_work;

union {
struct modem_backend_uart_isr isr;
Expand Down
9 changes: 9 additions & 0 deletions subsys/modem/backends/modem_backend_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ static void modem_backend_uart_receive_ready_handler(struct k_work *item)
modem_pipe_notify_receive_ready(&backend->pipe);
}

static void modem_backend_uart_transmit_idle_handler(struct k_work *item)
{
struct modem_backend_uart *backend =
CONTAINER_OF(item, struct modem_backend_uart, transmit_idle_work);

modem_pipe_notify_transmit_idle(&backend->pipe);
}

struct modem_pipe *modem_backend_uart_init(struct modem_backend_uart *backend,
const struct modem_backend_uart_config *config)
{
Expand All @@ -35,6 +43,7 @@ struct modem_pipe *modem_backend_uart_init(struct modem_backend_uart *backend,
memset(backend, 0x00, sizeof(*backend));
backend->uart = config->uart;
k_work_init(&backend->receive_ready_work, modem_backend_uart_receive_ready_handler);
k_work_init(&backend->transmit_idle_work, modem_backend_uart_transmit_idle_handler);

#ifdef CONFIG_MODEM_BACKEND_UART_ASYNC
if (modem_backend_uart_async_is_supported(backend)) {
Expand Down
2 changes: 2 additions & 0 deletions subsys/modem/backends/modem_backend_uart_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ static void modem_backend_uart_async_event_handler(const struct device *dev,
case UART_TX_DONE:
atomic_clear_bit(&backend->async.state,
MODEM_BACKEND_UART_ASYNC_STATE_TRANSMITTING_BIT);
k_work_submit(&backend->transmit_idle_work);

break;

case UART_TX_ABORTED:
LOG_WRN("Transmit aborted");
atomic_clear_bit(&backend->async.state,
MODEM_BACKEND_UART_ASYNC_STATE_TRANSMITTING_BIT);
k_work_submit(&backend->transmit_idle_work);

break;

Expand Down
1 change: 1 addition & 0 deletions subsys/modem/backends/modem_backend_uart_isr.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static void modem_backend_uart_isr_irq_handler_transmit_ready(struct modem_backe

if (ring_buf_is_empty(&backend->isr.transmit_rb) == true) {
uart_irq_tx_disable(backend->uart);
k_work_submit(&backend->transmit_idle_work);
return;
}

Expand Down

0 comments on commit 8c6a9ee

Please sign in to comment.