1 /* 2 * Copyright (c) 2022 Trackunit Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/modem/pipe.h> 8 #include <zephyr/kernel.h> 9 #include <zephyr/sys/ring_buffer.h> 10 11 #ifndef ZEPHYR_DRIVERS_MODEM_MODEM_PIPE_MOCK 12 #define ZEPHYR_DRIVERS_MODEM_MODEM_PIPE_MOCK 13 14 struct modem_backend_mock_transaction { 15 /* Get data which will trigger put */ 16 const uint8_t *get; 17 size_t get_size; 18 19 /* Data which will be put in response to get data */ 20 const uint8_t *put; 21 size_t put_size; 22 }; 23 24 struct modem_backend_mock { 25 struct modem_pipe pipe; 26 27 struct ring_buf rx_rb; 28 struct ring_buf tx_rb; 29 30 struct k_work receive_ready_work; 31 struct k_work transmit_idle_work; 32 33 const struct modem_backend_mock_transaction *transaction; 34 size_t transaction_match_cnt; 35 36 /* Max allowed read/write size */ 37 size_t limit; 38 /* Mock Brige pair */ 39 struct modem_backend_mock *bridge; 40 }; 41 42 struct modem_backend_mock_config { 43 uint8_t *rx_buf; 44 size_t rx_buf_size; 45 uint8_t *tx_buf; 46 size_t tx_buf_size; 47 size_t limit; 48 }; 49 50 struct modem_pipe *modem_backend_mock_init(struct modem_backend_mock *mock, 51 const struct modem_backend_mock_config *config); 52 53 void modem_backend_mock_reset(struct modem_backend_mock *mock); 54 55 int modem_backend_mock_get(struct modem_backend_mock *mock, uint8_t *buf, size_t size); 56 57 void modem_backend_mock_put(struct modem_backend_mock *mock, const uint8_t *buf, size_t size); 58 59 void modem_backend_mock_prime(struct modem_backend_mock *mock, 60 const struct modem_backend_mock_transaction *transaction); 61 62 void modem_backend_mock_bridge(struct modem_backend_mock *mock_a, 63 struct modem_backend_mock *mock_b); 64 65 #endif /* ZEPHYR_DRIVERS_MODEM_MODEM_PIPE_MOCK */ 66