Lines Matching refs:backend

23 static bool modem_backend_uart_async_is_uart_stopped(struct modem_backend_uart *backend)  in modem_backend_uart_async_is_uart_stopped()  argument
25 if (!atomic_test_bit(&backend->async.state, in modem_backend_uart_async_is_uart_stopped()
27 !atomic_test_bit(&backend->async.state, in modem_backend_uart_async_is_uart_stopped()
29 !atomic_test_bit(&backend->async.state, in modem_backend_uart_async_is_uart_stopped()
31 !atomic_test_bit(&backend->async.state, in modem_backend_uart_async_is_uart_stopped()
39 static bool modem_backend_uart_async_is_open(struct modem_backend_uart *backend) in modem_backend_uart_async_is_open() argument
41 return atomic_test_bit(&backend->async.state, in modem_backend_uart_async_is_open()
45 static uint32_t get_receive_buf_length(struct modem_backend_uart *backend) in get_receive_buf_length() argument
47 return ring_buf_size_get(&backend->async.receive_rb); in get_receive_buf_length()
53 struct modem_backend_uart *backend = (struct modem_backend_uart *) user_data; in modem_backend_uart_async_event_handler() local
59 atomic_clear_bit(&backend->async.state, in modem_backend_uart_async_event_handler()
61 k_work_submit(&backend->transmit_idle_work); in modem_backend_uart_async_event_handler()
65 if (modem_backend_uart_async_is_open(backend)) { in modem_backend_uart_async_event_handler()
68 atomic_clear_bit(&backend->async.state, in modem_backend_uart_async_event_handler()
70 k_work_submit(&backend->transmit_idle_work); in modem_backend_uart_async_event_handler()
75 if (!atomic_test_and_set_bit(&backend->async.state, in modem_backend_uart_async_event_handler()
77 uart_rx_buf_rsp(backend->uart, backend->async.receive_bufs[0], in modem_backend_uart_async_event_handler()
78 backend->async.receive_buf_size); in modem_backend_uart_async_event_handler()
83 if (!atomic_test_and_set_bit(&backend->async.state, in modem_backend_uart_async_event_handler()
85 uart_rx_buf_rsp(backend->uart, backend->async.receive_bufs[1], in modem_backend_uart_async_event_handler()
86 backend->async.receive_buf_size); in modem_backend_uart_async_event_handler()
95 if (evt->data.rx_buf.buf == backend->async.receive_bufs[0]) { in modem_backend_uart_async_event_handler()
96 atomic_clear_bit(&backend->async.state, in modem_backend_uart_async_event_handler()
102 if (evt->data.rx_buf.buf == backend->async.receive_bufs[1]) { in modem_backend_uart_async_event_handler()
103 atomic_clear_bit(&backend->async.state, in modem_backend_uart_async_event_handler()
113 key = k_spin_lock(&backend->async.receive_rb_lock); in modem_backend_uart_async_event_handler()
114 received = ring_buf_put(&backend->async.receive_rb, in modem_backend_uart_async_event_handler()
119 const unsigned int buf_size = get_receive_buf_length(backend); in modem_backend_uart_async_event_handler()
121 ring_buf_reset(&backend->async.receive_rb); in modem_backend_uart_async_event_handler()
122 k_spin_unlock(&backend->async.receive_rb_lock, key); in modem_backend_uart_async_event_handler()
129 k_spin_unlock(&backend->async.receive_rb_lock, key); in modem_backend_uart_async_event_handler()
130 k_work_schedule(&backend->receive_ready_work, K_NO_WAIT); in modem_backend_uart_async_event_handler()
134 atomic_clear_bit(&backend->async.state, in modem_backend_uart_async_event_handler()
146 if (modem_backend_uart_async_is_uart_stopped(backend)) { in modem_backend_uart_async_event_handler()
147 k_work_submit(&backend->async.rx_disabled_work); in modem_backend_uart_async_event_handler()
153 struct modem_backend_uart *backend = (struct modem_backend_uart *)data; in modem_backend_uart_async_open() local
156 atomic_clear(&backend->async.state); in modem_backend_uart_async_open()
157 ring_buf_reset(&backend->async.receive_rb); in modem_backend_uart_async_open()
159 atomic_set_bit(&backend->async.state, MODEM_BACKEND_UART_ASYNC_STATE_RX_BUF0_USED_BIT); in modem_backend_uart_async_open()
160 atomic_set_bit(&backend->async.state, MODEM_BACKEND_UART_ASYNC_STATE_RECEIVING_BIT); in modem_backend_uart_async_open()
161 atomic_set_bit(&backend->async.state, MODEM_BACKEND_UART_ASYNC_STATE_OPEN_BIT); in modem_backend_uart_async_open()
166 ret = uart_rx_enable(backend->uart, backend->async.receive_bufs[0], in modem_backend_uart_async_open()
167 backend->async.receive_buf_size, in modem_backend_uart_async_open()
170 atomic_clear(&backend->async.state); in modem_backend_uart_async_open()
174 modem_pipe_notify_opened(&backend->pipe); in modem_backend_uart_async_open()
179 static uint32_t get_receive_buf_size(struct modem_backend_uart *backend) in get_receive_buf_size() argument
181 return ring_buf_capacity_get(&backend->async.receive_rb); in get_receive_buf_size()
184 static void advertise_transmit_buf_stats(struct modem_backend_uart *backend, uint32_t length) in advertise_transmit_buf_stats() argument
186 modem_stats_buffer_advertise_length(&backend->transmit_buf_stats, length); in advertise_transmit_buf_stats()
189 static void advertise_receive_buf_stats(struct modem_backend_uart *backend) in advertise_receive_buf_stats() argument
193 length = get_receive_buf_length(backend); in advertise_receive_buf_stats()
194 modem_stats_buffer_advertise_length(&backend->receive_buf_stats, length); in advertise_receive_buf_stats()
198 static uint32_t get_transmit_buf_size(struct modem_backend_uart *backend) in get_transmit_buf_size() argument
200 return backend->async.transmit_buf_size; in get_transmit_buf_size()
205 struct modem_backend_uart *backend = (struct modem_backend_uart *)data; in modem_backend_uart_async_transmit() local
210 transmitting = atomic_test_and_set_bit(&backend->async.state, in modem_backend_uart_async_transmit()
217 bytes_to_transmit = MIN(size, get_transmit_buf_size(backend)); in modem_backend_uart_async_transmit()
220 memcpy(backend->async.transmit_buf, buf, bytes_to_transmit); in modem_backend_uart_async_transmit()
222 ret = uart_tx(backend->uart, backend->async.transmit_buf, bytes_to_transmit, in modem_backend_uart_async_transmit()
226 advertise_transmit_buf_stats(backend, bytes_to_transmit); in modem_backend_uart_async_transmit()
240 struct modem_backend_uart *backend = (struct modem_backend_uart *)data; in modem_backend_uart_async_receive() local
245 key = k_spin_lock(&backend->async.receive_rb_lock); in modem_backend_uart_async_receive()
248 advertise_receive_buf_stats(backend); in modem_backend_uart_async_receive()
251 received = ring_buf_get(&backend->async.receive_rb, buf, size); in modem_backend_uart_async_receive()
252 empty = ring_buf_is_empty(&backend->async.receive_rb); in modem_backend_uart_async_receive()
253 k_spin_unlock(&backend->async.receive_rb_lock, key); in modem_backend_uart_async_receive()
256 k_work_schedule(&backend->receive_ready_work, K_NO_WAIT); in modem_backend_uart_async_receive()
264 struct modem_backend_uart *backend = (struct modem_backend_uart *)data; in modem_backend_uart_async_close() local
266 atomic_clear_bit(&backend->async.state, MODEM_BACKEND_UART_ASYNC_STATE_OPEN_BIT); in modem_backend_uart_async_close()
267 uart_tx_abort(backend->uart); in modem_backend_uart_async_close()
268 uart_rx_disable(backend->uart); in modem_backend_uart_async_close()
279 bool modem_backend_uart_async_is_supported(struct modem_backend_uart *backend) in modem_backend_uart_async_is_supported() argument
281 return uart_callback_set(backend->uart, modem_backend_uart_async_event_handler, in modem_backend_uart_async_is_supported()
282 backend) == 0; in modem_backend_uart_async_is_supported()
290 struct modem_backend_uart *backend = in modem_backend_uart_async_notify_closed() local
293 modem_pipe_notify_closed(&backend->pipe); in modem_backend_uart_async_notify_closed()
297 static void init_stats(struct modem_backend_uart *backend) in init_stats() argument
303 receive_buf_size = get_receive_buf_size(backend); in init_stats()
304 transmit_buf_size = get_transmit_buf_size(backend); in init_stats()
306 snprintk(name, sizeof(name), "%s_%s", backend->uart->name, "rx"); in init_stats()
307 modem_stats_buffer_init(&backend->receive_buf_stats, name, receive_buf_size); in init_stats()
308 snprintk(name, sizeof(name), "%s_%s", backend->uart->name, "tx"); in init_stats()
309 modem_stats_buffer_init(&backend->transmit_buf_stats, name, transmit_buf_size); in init_stats()
313 void modem_backend_uart_async_init(struct modem_backend_uart *backend, in modem_backend_uart_async_init() argument
319 backend->async.receive_buf_size = receive_buf_size_quarter; in modem_backend_uart_async_init()
320 backend->async.receive_bufs[0] = &config->receive_buf[0]; in modem_backend_uart_async_init()
321 backend->async.receive_bufs[1] = &config->receive_buf[receive_buf_size_quarter]; in modem_backend_uart_async_init()
324 ring_buf_init(&backend->async.receive_rb, (receive_buf_size_quarter * 2), in modem_backend_uart_async_init()
327 backend->async.transmit_buf = config->transmit_buf; in modem_backend_uart_async_init()
328 backend->async.transmit_buf_size = config->transmit_buf_size; in modem_backend_uart_async_init()
329 k_work_init(&backend->async.rx_disabled_work, modem_backend_uart_async_notify_closed); in modem_backend_uart_async_init()
330 modem_pipe_init(&backend->pipe, backend, &modem_backend_uart_async_api); in modem_backend_uart_async_init()
333 init_stats(backend); in modem_backend_uart_async_init()