Skip to content

Commit c120f4f

Browse files
57300kartben
authored andcommitted
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 <[email protected]>
1 parent dae37b6 commit c120f4f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

modules/hal_nordic/nrfs/backends/nrfs_backend_ipc_service.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ static void ipc_sysctrl_ept_bound(void *priv)
9595
LOG_DBG("Bound to sysctrl.");
9696
k_event_post(&ipc_connected_event, IPC_INIT_DONE_EVENT);
9797
atomic_set(&ipc_cpusys_channel_config.status, CONNECTED);
98+
99+
if (k_msgq_num_used_get(&ipc_transmit_msgq) > 0) {
100+
k_work_submit(&backend_send_work);
101+
}
98102
}
99103

100104
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)
172176

173177
nrfs_err_t nrfs_backend_send_ex(void *message, size_t size, k_timeout_t timeout, bool high_prio)
174178
{
175-
if (atomic_get(&ipc_cpusys_channel_config.status) != CONNECTED) {
176-
LOG_WRN("Backend not yet connected to sysctrl");
177-
return NRFS_ERR_INVALID_STATE;
178-
}
179-
180179
if (size <= MAX_PACKET_DATA_SIZE) {
181180
int err;
182181
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,
190189
return NRFS_ERR_IPC;
191190
}
192191

193-
err = k_work_submit(&backend_send_work);
192+
if (nrfs_backend_connected()) {
193+
err = k_work_submit(&backend_send_work);
194+
}
194195

195196
return err >= 0 ? 0 : NRFS_ERR_IPC;
196197
}

0 commit comments

Comments
 (0)