Lines Matching refs:async

20 static inline struct rx_buf_t *block_start_get(struct modem_backend_uart_async *async, uint8_t *buf)  in block_start_get()  argument
25 block_num = (((size_t)buf - sizeof(struct rx_buf_t) - (size_t)async->rx_slab.buffer) / in block_start_get()
26 async->rx_buf_size); in block_start_get()
28 return (struct rx_buf_t *) &async->rx_slab.buffer[block_num * async->rx_buf_size]; in block_start_get()
31 static struct rx_buf_t *rx_buf_alloc(struct modem_backend_uart_async *async) in rx_buf_alloc() argument
35 if (k_mem_slab_alloc(&async->rx_slab, (void **) &buf, K_NO_WAIT)) { in rx_buf_alloc()
43 static void rx_buf_ref(struct modem_backend_uart_async *async, void *buf) in rx_buf_ref() argument
45 atomic_inc(&(block_start_get(async, buf)->ref_counter)); in rx_buf_ref()
48 static void rx_buf_unref(struct modem_backend_uart_async *async, void *buf) in rx_buf_unref() argument
50 struct rx_buf_t *uart_buf = block_start_get(async, buf); in rx_buf_unref()
54 k_mem_slab_free(&async->rx_slab, (void *)uart_buf); in rx_buf_unref()
67 struct rx_buf_t *buf = rx_buf_alloc(&backend->async); in modem_backend_uart_async_hwfc_rx_enable()
74 backend->async.rx_buf_size - sizeof(struct rx_buf_t), in modem_backend_uart_async_hwfc_rx_enable()
77 rx_buf_unref(&backend->async, buf->buf); in modem_backend_uart_async_hwfc_rx_enable()
88 if (!atomic_test_bit(&backend->async.common.state, in modem_backend_uart_async_hwfc_rx_recovery()
99 if (!atomic_test_and_clear_bit(&backend->async.common.state, in modem_backend_uart_async_hwfc_rx_recovery()
110 if (!atomic_test_bit(&backend->async.common.state, in modem_backend_uart_async_hwfc_is_uart_stopped()
112 !atomic_test_bit(&backend->async.common.state, in modem_backend_uart_async_hwfc_is_uart_stopped()
114 !atomic_test_bit(&backend->async.common.state, in modem_backend_uart_async_hwfc_is_uart_stopped()
124 return atomic_test_bit(&backend->async.common.state, in modem_backend_uart_async_hwfc_is_open()
137 atomic_clear_bit(&backend->async.common.state, in modem_backend_uart_async_hwfc_event_handler()
146 atomic_clear_bit(&backend->async.common.state, in modem_backend_uart_async_hwfc_event_handler()
153 struct rx_buf_t *buf = rx_buf_alloc(&backend->async); in modem_backend_uart_async_hwfc_event_handler()
160 backend->async.rx_buf_size - sizeof(struct rx_buf_t)); in modem_backend_uart_async_hwfc_event_handler()
163 rx_buf_unref(&backend->async, buf->buf); in modem_backend_uart_async_hwfc_event_handler()
169 rx_buf_unref(&backend->async, evt->data.rx_buf.buf); in modem_backend_uart_async_hwfc_event_handler()
175 rx_buf_ref(&backend->async, evt->data.rx.buf); in modem_backend_uart_async_hwfc_event_handler()
178 err = k_msgq_put(&backend->async.rx_queue, &rx_event, K_NO_WAIT); in modem_backend_uart_async_hwfc_event_handler()
182 rx_buf_unref(&backend->async, evt->data.rx.buf); in modem_backend_uart_async_hwfc_event_handler()
190 if (atomic_test_bit(&backend->async.common.state, in modem_backend_uart_async_hwfc_event_handler()
192 if (!atomic_test_and_set_bit(&backend->async.common.state, in modem_backend_uart_async_hwfc_event_handler()
209 k_work_submit(&backend->async.common.rx_disabled_work); in modem_backend_uart_async_hwfc_event_handler()
216 struct rx_buf_t *buf = rx_buf_alloc(&backend->async); in modem_backend_uart_async_hwfc_open()
223 atomic_clear(&backend->async.common.state); in modem_backend_uart_async_hwfc_open()
224 atomic_set_bit(&backend->async.common.state, MODEM_BACKEND_UART_ASYNC_STATE_OPEN_BIT); in modem_backend_uart_async_hwfc_open()
227 backend->async.rx_buf_size - sizeof(struct rx_buf_t), in modem_backend_uart_async_hwfc_open()
230 rx_buf_unref(&backend->async, buf->buf); in modem_backend_uart_async_hwfc_open()
231 atomic_clear(&backend->async.common.state); in modem_backend_uart_async_hwfc_open()
242 return (backend->async.rx_buf_size - sizeof(struct rx_buf_t)) * backend->async.rx_buf_count; in get_receive_buf_size()
258 return backend->async.common.transmit_buf_size; in get_transmit_buf_size()
268 transmitting = atomic_test_and_set_bit(&backend->async.common.state, in modem_backend_uart_async_hwfc_transmit()
278 memcpy(backend->async.common.transmit_buf, buf, bytes_to_transmit); in modem_backend_uart_async_hwfc_transmit()
280 ret = uart_tx(backend->uart, backend->async.common.transmit_buf, bytes_to_transmit, in modem_backend_uart_async_hwfc_transmit()
304 size_t reserved = backend->async.rx_event.len; in modem_backend_uart_async_hwfc_receive()
306 for (int i = 0; i < k_msgq_num_used_get(&backend->async.rx_queue); i++) { in modem_backend_uart_async_hwfc_receive()
307 if (k_msgq_peek_at(&backend->async.rx_queue, &rx_event, i)) { in modem_backend_uart_async_hwfc_receive()
318 if (backend->async.rx_event.len == 0) { in modem_backend_uart_async_hwfc_receive()
319 if (k_msgq_get(&backend->async.rx_queue, &backend->async.rx_event, in modem_backend_uart_async_hwfc_receive()
324 copy_size = MIN(size - received, backend->async.rx_event.len); in modem_backend_uart_async_hwfc_receive()
325 memcpy(buf, backend->async.rx_event.buf, copy_size); in modem_backend_uart_async_hwfc_receive()
328 backend->async.rx_event.buf += copy_size; in modem_backend_uart_async_hwfc_receive()
329 backend->async.rx_event.len -= copy_size; in modem_backend_uart_async_hwfc_receive()
331 if (backend->async.rx_event.len == 0) { in modem_backend_uart_async_hwfc_receive()
332 rx_buf_unref(&backend->async, backend->async.rx_event.buf); in modem_backend_uart_async_hwfc_receive()
336 if (backend->async.rx_event.len != 0 || in modem_backend_uart_async_hwfc_receive()
337 k_msgq_num_used_get(&backend->async.rx_queue) != 0) { in modem_backend_uart_async_hwfc_receive()
350 atomic_clear_bit(&backend->async.common.state, MODEM_BACKEND_UART_ASYNC_STATE_OPEN_BIT); in modem_backend_uart_async_hwfc_close()
353 if (!atomic_test_and_clear_bit(&backend->async.common.state, in modem_backend_uart_async_hwfc_close()
380 struct modem_backend_uart_async *async = in modem_backend_uart_async_hwfc_notify_closed() local
384 CONTAINER_OF(async, struct modem_backend_uart, async); in modem_backend_uart_async_hwfc_notify_closed()
412 backend->async.rx_buf_count = CONFIG_MODEM_BACKEND_UART_ASYNC_HWFC_BUFFER_COUNT; in modem_backend_uart_async_init()
419 buf_size -= (config->receive_buf_size % (sizeof(uint32_t) * backend->async.rx_buf_count)); in modem_backend_uart_async_init()
420 backend->async.rx_buf_size = buf_size / backend->async.rx_buf_count; in modem_backend_uart_async_init()
421 __ASSERT_NO_MSG(backend->async.rx_buf_size > sizeof(struct rx_buf_t)); in modem_backend_uart_async_init()
424 err = k_mem_slab_init(&backend->async.rx_slab, config->receive_buf, in modem_backend_uart_async_init()
425 backend->async.rx_buf_size, backend->async.rx_buf_count); in modem_backend_uart_async_init()
429 k_msgq_init(&backend->async.rx_queue, (char *)&backend->async.rx_queue_buf, in modem_backend_uart_async_init()
432 backend->async.common.transmit_buf = config->transmit_buf; in modem_backend_uart_async_init()
433 backend->async.common.transmit_buf_size = config->transmit_buf_size; in modem_backend_uart_async_init()
434 k_work_init(&backend->async.common.rx_disabled_work, in modem_backend_uart_async_init()