From 4efcb15b882b0b610bf937ce15f141b35c073328 Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Fri, 15 Nov 2024 08:41:59 +0100 Subject: [PATCH] [nrf fromtree] modules: hal_nordic: nrfs: Enqueue requests when not connected Allow `nrfs_backend_send` to push early requests into the message queue, but defer sending them until a connection is established, at which point the queue will be flushed. This benefits asynchronous code by making it optional to call `nrfs_backend_wait_for_connection` before using the nrfs service API, which is already non-blocking. Signed-off-by: Grzegorz Swiderski (cherry picked from commit c120f4fe562e39469179860e0acbfa697e50a3d7) --- .../nrfs/backends/nrfs_backend_ipc_service.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/hal_nordic/nrfs/backends/nrfs_backend_ipc_service.c b/modules/hal_nordic/nrfs/backends/nrfs_backend_ipc_service.c index 66077337422..129098e9b2d 100644 --- a/modules/hal_nordic/nrfs/backends/nrfs_backend_ipc_service.c +++ b/modules/hal_nordic/nrfs/backends/nrfs_backend_ipc_service.c @@ -95,6 +95,10 @@ static void ipc_sysctrl_ept_bound(void *priv) LOG_DBG("Bound to sysctrl."); k_event_post(&ipc_connected_event, IPC_INIT_DONE_EVENT); atomic_set(&ipc_cpusys_channel_config.status, CONNECTED); + + if (k_msgq_num_used_get(&ipc_transmit_msgq) > 0) { + k_work_submit(&backend_send_work); + } } static void ipc_sysctrl_ept_recv(const void *data, size_t size, void *priv) @@ -172,11 +176,6 @@ nrfs_err_t nrfs_backend_send(void *message, size_t size) nrfs_err_t nrfs_backend_send_ex(void *message, size_t size, k_timeout_t timeout, bool high_prio) { - if (atomic_get(&ipc_cpusys_channel_config.status) != CONNECTED) { - LOG_WRN("Backend not yet connected to sysctrl"); - return NRFS_ERR_INVALID_STATE; - } - if (size <= MAX_PACKET_DATA_SIZE) { int err; struct ipc_data_packet tx_data; @@ -190,7 +189,9 @@ nrfs_err_t nrfs_backend_send_ex(void *message, size_t size, k_timeout_t timeout, return NRFS_ERR_IPC; } - err = k_work_submit(&backend_send_work); + if (nrfs_backend_connected()) { + err = k_work_submit(&backend_send_work); + } return err >= 0 ? 0 : NRFS_ERR_IPC; }