Line data Source code
1 0 : /* 2 : * Copyright (c) 2022 Trackunit Corporation 3 : * 4 : * SPDX-License-Identifier: Apache-2.0 5 : */ 6 : 7 : #include <zephyr/kernel.h> 8 : #include <zephyr/types.h> 9 : #include <zephyr/device.h> 10 : #include <zephyr/drivers/uart.h> 11 : #include <zephyr/sys/ring_buffer.h> 12 : #include <zephyr/sys/atomic.h> 13 : 14 : #include <zephyr/modem/pipe.h> 15 : #include <zephyr/modem/stats.h> 16 : 17 : #ifndef ZEPHYR_MODEM_BACKEND_UART_ 18 0 : #define ZEPHYR_MODEM_BACKEND_UART_ 19 : 20 : #ifdef __cplusplus 21 : extern "C" { 22 : #endif 23 : 24 0 : struct modem_backend_uart_isr { 25 0 : struct ring_buf receive_rdb[2]; 26 0 : struct ring_buf transmit_rb; 27 0 : atomic_t transmit_buf_len; 28 0 : atomic_t receive_buf_len; 29 0 : uint8_t receive_rdb_used; 30 0 : uint32_t transmit_buf_put_limit; 31 : }; 32 : 33 0 : struct modem_backend_uart_async { 34 0 : uint8_t *receive_bufs[2]; 35 0 : uint32_t receive_buf_size; 36 0 : struct ring_buf receive_rb; 37 0 : struct k_spinlock receive_rb_lock; 38 0 : uint8_t *transmit_buf; 39 0 : uint32_t transmit_buf_size; 40 0 : struct k_work rx_disabled_work; 41 0 : atomic_t state; 42 : }; 43 : 44 0 : struct modem_backend_uart { 45 0 : const struct device *uart; 46 0 : struct modem_pipe pipe; 47 0 : struct k_work_delayable receive_ready_work; 48 0 : struct k_work transmit_idle_work; 49 : 50 : #if CONFIG_MODEM_STATS 51 : struct modem_stats_buffer receive_buf_stats; 52 : struct modem_stats_buffer transmit_buf_stats; 53 : #endif 54 : 55 : union { 56 0 : struct modem_backend_uart_isr isr; 57 0 : struct modem_backend_uart_async async; 58 0 : }; 59 : }; 60 : 61 0 : struct modem_backend_uart_config { 62 0 : const struct device *uart; 63 0 : uint8_t *receive_buf; 64 0 : uint32_t receive_buf_size; 65 0 : uint8_t *transmit_buf; 66 0 : uint32_t transmit_buf_size; 67 : }; 68 : 69 0 : struct modem_pipe *modem_backend_uart_init(struct modem_backend_uart *backend, 70 : const struct modem_backend_uart_config *config); 71 : 72 : #ifdef __cplusplus 73 : } 74 : #endif 75 : 76 : #endif /* ZEPHYR_MODEM_BACKEND_UART_ */