From 325bc953a89d79ca71b6f8b59ea320bbf78fa656 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 12 Jan 2024 11:31:14 +0100 Subject: [PATCH] tests: modem: pipe: mock: Implement TRANSMIT_IDLE event Implements TRANSMIT_IDLE event notification for mock modem_pipe. Signed-off-by: Bjarki Arge Andreasen --- tests/subsys/modem/mock/modem_backend_mock.c | 24 ++++++++++++++------ tests/subsys/modem/mock/modem_backend_mock.h | 10 ++------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/subsys/modem/mock/modem_backend_mock.c b/tests/subsys/modem/mock/modem_backend_mock.c index 0a12fc4367..5b7b47c0eb 100644 --- a/tests/subsys/modem/mock/modem_backend_mock.c +++ b/tests/subsys/modem/mock/modem_backend_mock.c @@ -47,7 +47,8 @@ static int modem_backend_mock_transmit(void *data, const uint8_t *buf, size_t si struct modem_backend_mock *t_mock = mock->bridge; ret = ring_buf_put(&t_mock->rx_rb, buf, size); - k_work_submit(&t_mock->received_work_item.work); + k_work_submit(&t_mock->receive_ready_work); + k_work_submit(&mock->transmit_idle_work); return ret; } @@ -59,6 +60,7 @@ static int modem_backend_mock_transmit(void *data, const uint8_t *buf, size_t si mock->transaction = NULL; } + k_work_submit(&mock->transmit_idle_work); return ret; } @@ -85,14 +87,22 @@ struct modem_pipe_api modem_backend_mock_api = { .close = modem_backend_mock_close, }; -static void modem_backend_mock_received_handler(struct k_work *item) +static void modem_backend_mock_receive_ready_handler(struct k_work *item) { - struct modem_backend_mock_work *mock_work_item = (struct modem_backend_mock_work *)item; - struct modem_backend_mock *mock = mock_work_item->mock; + struct modem_backend_mock *mock = + CONTAINER_OF(item, struct modem_backend_mock, receive_ready_work); modem_pipe_notify_receive_ready(&mock->pipe); } +static void modem_backend_mock_transmit_idle_handler(struct k_work *item) +{ + struct modem_backend_mock *mock = + CONTAINER_OF(item, struct modem_backend_mock, transmit_idle_work); + + modem_pipe_notify_transmit_idle(&mock->pipe); +} + struct modem_pipe *modem_backend_mock_init(struct modem_backend_mock *mock, const struct modem_backend_mock_config *config) { @@ -100,8 +110,8 @@ struct modem_pipe *modem_backend_mock_init(struct modem_backend_mock *mock, ring_buf_init(&mock->rx_rb, config->rx_buf_size, config->rx_buf); ring_buf_init(&mock->tx_rb, config->tx_buf_size, config->tx_buf); - mock->received_work_item.mock = mock; - k_work_init(&mock->received_work_item.work, modem_backend_mock_received_handler); + k_work_init(&mock->receive_ready_work, modem_backend_mock_receive_ready_handler); + k_work_init(&mock->transmit_idle_work, modem_backend_mock_transmit_idle_handler); mock->limit = config->limit; modem_pipe_init(&mock->pipe, mock, &modem_backend_mock_api); return &mock->pipe; @@ -130,7 +140,7 @@ void modem_backend_mock_put(struct modem_backend_mock *mock, const uint8_t *buf, __ASSERT(ring_buf_put(&mock->rx_rb, buf, size) == size, "Mock buffer capacity exceeded"); - k_work_submit(&mock->received_work_item.work); + k_work_submit(&mock->receive_ready_work); } void modem_backend_mock_prime(struct modem_backend_mock *mock, diff --git a/tests/subsys/modem/mock/modem_backend_mock.h b/tests/subsys/modem/mock/modem_backend_mock.h index 7d9ad11bf4..56a5b585cb 100644 --- a/tests/subsys/modem/mock/modem_backend_mock.h +++ b/tests/subsys/modem/mock/modem_backend_mock.h @@ -11,13 +11,6 @@ #ifndef ZEPHYR_DRIVERS_MODEM_MODEM_PIPE_MOCK #define ZEPHYR_DRIVERS_MODEM_MODEM_PIPE_MOCK -struct modem_backend_mock; - -struct modem_backend_mock_work { - struct k_work work; - struct modem_backend_mock *mock; -}; - struct modem_backend_mock_transaction { /* Get data which will trigger put */ const uint8_t *get; @@ -34,7 +27,8 @@ struct modem_backend_mock { struct ring_buf rx_rb; struct ring_buf tx_rb; - struct modem_backend_mock_work received_work_item; + struct k_work receive_ready_work; + struct k_work transmit_idle_work; const struct modem_backend_mock_transaction *transaction; size_t transaction_match_cnt;