88 * @brief IPC service layer of the nRF71 Wi-Fi driver.
99 */
1010
11+ #include <errno.h>
12+
1113#include <zephyr/kernel.h>
1214#include <zephyr/logging/log.h>
1315
1416LOG_MODULE_DECLARE (wifi_nrf , CONFIG_WIFI_NRF71_LOG_LEVEL );
1517
1618#include "ipc_service.h"
1719
20+ static K_SEM_DEFINE (wifi_ipc_bind_sem , 0 , 1 ) ;
21+
22+ static void wifi_ipc_signal_bound (void )
23+ {
24+ k_sem_give (& wifi_ipc_bind_sem );
25+ }
26+
27+ static int wifi_ipc_wait_bound (wifi_ipc_t * context )
28+ {
29+ if (context -> busy_q .ipc_ready ) {
30+ return 0 ;
31+ }
32+
33+ if (k_sem_take (& wifi_ipc_bind_sem ,
34+ K_MSEC (CONFIG_NRF71_IPC_BIND_TIMEOUT_MS )) != 0 &&
35+ !context -> busy_q .ipc_ready ) {
36+ LOG_ERR ("IPC endpoint not bound after %d ms (Wi-Fi core up? "
37+ "CONFIG_SOC_NRF71_WIFI_BOOT=y for TF-M builds)" ,
38+ CONFIG_NRF71_IPC_BIND_TIMEOUT_MS );
39+ return - ETIMEDOUT ;
40+ }
41+
42+ return 0 ;
43+ }
44+
1845static void wifi_ipc_ep_bound (void * priv )
1946{
2047 wifi_ipc_t * context = (wifi_ipc_t * )priv ;
2148
2249 context -> busy_q .ipc_ready = true;
50+ wifi_ipc_signal_bound ();
2351}
2452
2553/* For single-endpoint TX+RX bind: set both contexts ready when endpoint is bound */
@@ -33,6 +61,7 @@ static void wifi_ipc_ep_bound_tx_rx(void *priv)
3361 if (wifi_ipc_rx_ctx_shared != NULL ) {
3462 wifi_ipc_rx_ctx_shared -> busy_q .ipc_ready = true;
3563 }
64+ wifi_ipc_signal_bound ();
3665}
3766
3867static void wifi_ipc_recv_callback (const void * data , size_t len , void * priv )
@@ -66,6 +95,8 @@ static wifi_ipc_status_t wifi_ipc_busyq_register(wifi_ipc_t *context)
6695 int ret ;
6796 const struct device * ipc_instance = GET_IPC_INSTANCE (context -> busy_q .ipc_inst );
6897
98+ k_sem_reset (& wifi_ipc_bind_sem );
99+
69100 ret = ipc_service_open_instance (ipc_instance );
70101 if (ret < 0 ) {
71102 return WIFI_IPC_STATUS_INIT_ERR ;
@@ -80,6 +111,10 @@ static wifi_ipc_status_t wifi_ipc_busyq_register(wifi_ipc_t *context)
80111 return WIFI_IPC_STATUS_INIT_ERR ;
81112 }
82113
114+ if (wifi_ipc_wait_bound (context ) != 0 ) {
115+ return WIFI_IPC_STATUS_INIT_ERR ;
116+ }
117+
83118 LOG_INF ("IPC busy queue registered" );
84119
85120 return WIFI_IPC_STATUS_OK ;
@@ -103,6 +138,7 @@ wifi_ipc_status_t wifi_ipc_bind_ipc_service_tx_rx(wifi_ipc_t *tx_context,
103138{
104139 wifi_ipc_status_t ret ;
105140
141+ wifi_ipc_busyq_init (& rx_context -> busy_q , ipc_inst , NULL , priv );
106142 wifi_ipc_rx_ctx_shared = rx_context ;
107143 wifi_ipc_busyq_init (& tx_context -> busy_q , ipc_inst , rx_cb , priv );
108144 tx_context -> busy_q .ipc_ep_cfg .cb .bound = wifi_ipc_ep_bound_tx_rx ;
@@ -119,7 +155,7 @@ static wifi_ipc_status_t wifi_ipc_busyq_send(wifi_ipc_t *context, const void *da
119155 wifi_ipc_busyq_t * busyq = & context -> busy_q ;
120156
121157 if (!busyq -> ipc_ready ) {
122- LOG_ERR ("IPC service is not ready" );
158+ LOG_DBG ("IPC service is not ready" );
123159 return WIFI_IPC_STATUS_BUSYQ_NOTREADY ;
124160 }
125161
0 commit comments