Skip to content

Commit

Permalink
[nrf fromtree] modules: hal_nordic: nrfs: Enqueue requests when not c…
Browse files Browse the repository at this point in the history
…onnected

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]>
(cherry picked from commit c120f4f)
  • Loading branch information
57300 authored and bjarki-andreasen committed Nov 29, 2024
1 parent aa6dd06 commit 8673de1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions modules/hal_nordic/nrfs/backends/nrfs_backend_ipc_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 8673de1

Please sign in to comment.