Lines Matching full:backend
14 static void modem_backend_uart_isr_flush(struct modem_backend_uart *backend) in modem_backend_uart_isr_flush() argument
18 while (uart_fifo_read(backend->uart, &c, 1) > 0) { in modem_backend_uart_isr_flush()
23 static void modem_backend_uart_isr_irq_handler_receive_ready(struct modem_backend_uart *backend) in modem_backend_uart_isr_irq_handler_receive_ready() argument
30 receive_rb = &backend->isr.receive_rdb[backend->isr.receive_rdb_used]; in modem_backend_uart_isr_irq_handler_receive_ready()
44 ret = uart_fifo_read(backend->uart, buffer, size); in modem_backend_uart_isr_irq_handler_receive_ready()
57 k_work_schedule(&backend->receive_ready_work, in modem_backend_uart_isr_irq_handler_receive_ready()
61 k_work_reschedule(&backend->receive_ready_work, K_NO_WAIT); in modem_backend_uart_isr_irq_handler_receive_ready()
65 static void modem_backend_uart_isr_irq_handler_transmit_ready(struct modem_backend_uart *backend) in modem_backend_uart_isr_irq_handler_transmit_ready() argument
71 if (ring_buf_is_empty(&backend->isr.transmit_rb) == true) { in modem_backend_uart_isr_irq_handler_transmit_ready()
72 uart_irq_tx_disable(backend->uart); in modem_backend_uart_isr_irq_handler_transmit_ready()
73 k_work_submit(&backend->transmit_idle_work); in modem_backend_uart_isr_irq_handler_transmit_ready()
77 size = ring_buf_get_claim(&backend->isr.transmit_rb, &buffer, UINT32_MAX); in modem_backend_uart_isr_irq_handler_transmit_ready()
78 ret = uart_fifo_fill(backend->uart, buffer, size); in modem_backend_uart_isr_irq_handler_transmit_ready()
80 ring_buf_get_finish(&backend->isr.transmit_rb, 0); in modem_backend_uart_isr_irq_handler_transmit_ready()
82 ring_buf_get_finish(&backend->isr.transmit_rb, (uint32_t)ret); in modem_backend_uart_isr_irq_handler_transmit_ready()
85 atomic_sub(&backend->isr.transmit_buf_len, (uint32_t)ret); in modem_backend_uart_isr_irq_handler_transmit_ready()
91 struct modem_backend_uart *backend = (struct modem_backend_uart *)user_data; in modem_backend_uart_isr_irq_handler() local
98 modem_backend_uart_isr_irq_handler_receive_ready(backend); in modem_backend_uart_isr_irq_handler()
102 modem_backend_uart_isr_irq_handler_transmit_ready(backend); in modem_backend_uart_isr_irq_handler()
108 struct modem_backend_uart *backend = (struct modem_backend_uart *)data; in modem_backend_uart_isr_open() local
110 ring_buf_reset(&backend->isr.receive_rdb[0]); in modem_backend_uart_isr_open()
111 ring_buf_reset(&backend->isr.receive_rdb[1]); in modem_backend_uart_isr_open()
112 ring_buf_reset(&backend->isr.transmit_rb); in modem_backend_uart_isr_open()
113 atomic_set(&backend->isr.transmit_buf_len, 0); in modem_backend_uart_isr_open()
114 modem_backend_uart_isr_flush(backend); in modem_backend_uart_isr_open()
115 uart_irq_rx_enable(backend->uart); in modem_backend_uart_isr_open()
116 uart_irq_tx_enable(backend->uart); in modem_backend_uart_isr_open()
117 modem_pipe_notify_opened(&backend->pipe); in modem_backend_uart_isr_open()
121 static uint32_t get_transmit_buf_length(struct modem_backend_uart *backend) in get_transmit_buf_length() argument
123 return atomic_get(&backend->isr.transmit_buf_len); in get_transmit_buf_length()
127 static uint32_t get_receive_buf_length(struct modem_backend_uart *backend) in get_receive_buf_length() argument
129 return ring_buf_size_get(&backend->isr.receive_rdb[0]) + in get_receive_buf_length()
130 ring_buf_size_get(&backend->isr.receive_rdb[1]); in get_receive_buf_length()
133 static uint32_t get_receive_buf_size(struct modem_backend_uart *backend) in get_receive_buf_size() argument
135 return ring_buf_capacity_get(&backend->isr.receive_rdb[0]) + in get_receive_buf_size()
136 ring_buf_capacity_get(&backend->isr.receive_rdb[1]); in get_receive_buf_size()
139 static uint32_t get_transmit_buf_size(struct modem_backend_uart *backend) in get_transmit_buf_size() argument
141 return ring_buf_capacity_get(&backend->isr.transmit_rb); in get_transmit_buf_size()
144 static void advertise_transmit_buf_stats(struct modem_backend_uart *backend) in advertise_transmit_buf_stats() argument
148 length = get_transmit_buf_length(backend); in advertise_transmit_buf_stats()
149 modem_stats_buffer_advertise_length(&backend->transmit_buf_stats, length); in advertise_transmit_buf_stats()
152 static void advertise_receive_buf_stats(struct modem_backend_uart *backend) in advertise_receive_buf_stats() argument
156 uart_irq_rx_disable(backend->uart); in advertise_receive_buf_stats()
157 length = get_receive_buf_length(backend); in advertise_receive_buf_stats()
158 uart_irq_rx_enable(backend->uart); in advertise_receive_buf_stats()
159 modem_stats_buffer_advertise_length(&backend->receive_buf_stats, length); in advertise_receive_buf_stats()
163 static bool modem_backend_uart_isr_transmit_buf_above_limit(struct modem_backend_uart *backend) in modem_backend_uart_isr_transmit_buf_above_limit() argument
165 return backend->isr.transmit_buf_put_limit < get_transmit_buf_length(backend); in modem_backend_uart_isr_transmit_buf_above_limit()
170 struct modem_backend_uart *backend = (struct modem_backend_uart *)data; in modem_backend_uart_isr_transmit() local
173 if (modem_backend_uart_isr_transmit_buf_above_limit(backend) == true) { in modem_backend_uart_isr_transmit()
177 uart_irq_tx_disable(backend->uart); in modem_backend_uart_isr_transmit()
178 written = ring_buf_put(&backend->isr.transmit_rb, buf, size); in modem_backend_uart_isr_transmit()
179 uart_irq_tx_enable(backend->uart); in modem_backend_uart_isr_transmit()
182 atomic_add(&backend->isr.transmit_buf_len, written); in modem_backend_uart_isr_transmit()
185 advertise_transmit_buf_stats(backend); in modem_backend_uart_isr_transmit()
193 struct modem_backend_uart *backend = (struct modem_backend_uart *)data; in modem_backend_uart_isr_receive() local
199 advertise_receive_buf_stats(backend); in modem_backend_uart_isr_receive()
203 receive_rdb_unused = (backend->isr.receive_rdb_used == 1) ? 0 : 1; in modem_backend_uart_isr_receive()
206 read_bytes += ring_buf_get(&backend->isr.receive_rdb[receive_rdb_unused], buf, size); in modem_backend_uart_isr_receive()
208 if (ring_buf_is_empty(&backend->isr.receive_rdb[receive_rdb_unused]) == false) { in modem_backend_uart_isr_receive()
213 uart_irq_rx_disable(backend->uart); in modem_backend_uart_isr_receive()
214 backend->isr.receive_rdb_used = receive_rdb_unused; in modem_backend_uart_isr_receive()
215 uart_irq_rx_enable(backend->uart); in modem_backend_uart_isr_receive()
218 receive_rdb_unused = (backend->isr.receive_rdb_used == 1) ? 0 : 1; in modem_backend_uart_isr_receive()
220 read_bytes += ring_buf_get(&backend->isr.receive_rdb[receive_rdb_unused], in modem_backend_uart_isr_receive()
228 struct modem_backend_uart *backend = (struct modem_backend_uart *)data; in modem_backend_uart_isr_close() local
230 uart_irq_rx_disable(backend->uart); in modem_backend_uart_isr_close()
231 uart_irq_tx_disable(backend->uart); in modem_backend_uart_isr_close()
232 modem_pipe_notify_closed(&backend->pipe); in modem_backend_uart_isr_close()
244 static void init_stats(struct modem_backend_uart *backend) in init_stats() argument
250 receive_buf_size = get_receive_buf_size(backend); in init_stats()
251 transmit_buf_size = get_transmit_buf_size(backend); in init_stats()
253 snprintk(name, sizeof(name), "%s_%s", backend->uart->name, "rx"); in init_stats()
254 modem_stats_buffer_init(&backend->receive_buf_stats, name, receive_buf_size); in init_stats()
255 snprintk(name, sizeof(name), "%s_%s", backend->uart->name, "tx"); in init_stats()
256 modem_stats_buffer_init(&backend->transmit_buf_stats, name, transmit_buf_size); in init_stats()
260 void modem_backend_uart_isr_init(struct modem_backend_uart *backend, in modem_backend_uart_isr_init() argument
265 backend->isr.transmit_buf_put_limit = in modem_backend_uart_isr_init()
270 ring_buf_init(&backend->isr.receive_rdb[0], receive_double_buf_size, in modem_backend_uart_isr_init()
273 ring_buf_init(&backend->isr.receive_rdb[1], receive_double_buf_size, in modem_backend_uart_isr_init()
276 ring_buf_init(&backend->isr.transmit_rb, config->transmit_buf_size, in modem_backend_uart_isr_init()
279 atomic_set(&backend->isr.transmit_buf_len, 0); in modem_backend_uart_isr_init()
280 uart_irq_rx_disable(backend->uart); in modem_backend_uart_isr_init()
281 uart_irq_tx_disable(backend->uart); in modem_backend_uart_isr_init()
282 uart_irq_callback_user_data_set(backend->uart, modem_backend_uart_isr_irq_handler, in modem_backend_uart_isr_init()
283 backend); in modem_backend_uart_isr_init()
285 modem_pipe_init(&backend->pipe, backend, &modem_backend_uart_isr_api); in modem_backend_uart_isr_init()
288 init_stats(backend); in modem_backend_uart_isr_init()