tests: modem: pipe: mock: Implement TRANSMIT_IDLE event

Implements TRANSMIT_IDLE event notification for mock
modem_pipe.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
This commit is contained in:
Bjarki Arge Andreasen 2024-01-12 11:31:14 +01:00 committed by Carles Cufí
parent 7c9f2872e1
commit 325bc953a8
2 changed files with 19 additions and 15 deletions

View file

@ -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,

View file

@ -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;