88#include <zephyr/device.h>
99
1010#include <zephyr/ipc/ipc_service.h>
11+ #include <hal/nrf_reset.h>
12+ #include <string.h>
1113
1214#include "common.h"
1315
1416#include <zephyr/logging/log.h>
1517LOG_MODULE_REGISTER (host , LOG_LEVEL_INF );
1618
1719
20+ #define DT_DRV_COMPAT zephyr_ipc_icmsg
21+
1822K_SEM_DEFINE (bound_sem , 0 , 1 );
23+ static unsigned char expected_message = 'A' ;
24+ static size_t expected_len = PACKET_SIZE_START ;
1925
2026static void ep_bound (void * priv )
2127{
@@ -26,8 +32,6 @@ static void ep_bound(void *priv)
2632static void ep_recv (const void * data , size_t len , void * priv )
2733{
2834 struct data_packet * packet = (struct data_packet * )data ;
29- static unsigned char expected_message = 'A' ;
30- static size_t expected_len = PACKET_SIZE_START ;
3135
3236 __ASSERT (packet -> data [0 ] == expected_message , "Unexpected message. Expected %c, got %c" ,
3337 expected_message , packet -> data [0 ]);
@@ -124,6 +128,58 @@ int main(void)
124128 return ret ;
125129 }
126130
131+ LOG_INF ("Wait 500ms. Let net core finish its sends" );
132+ k_msleep (500 );
133+
134+ LOG_INF ("Stop network core" );
135+ nrf_reset_network_force_off (NRF_RESET , true);
136+
137+ LOG_INF ("Reset IPC service" );
138+
139+ ret = ipc_service_deregister_endpoint (& ep );
140+ if (ret != 0 ) {
141+ LOG_ERR ("ipc_service_register_endpoint() failure" );
142+ return ret ;
143+ }
144+
145+ /* Reset message and expected message value and len. */
146+ expected_message = 'A' ;
147+ expected_len = PACKET_SIZE_START ;
148+
149+ /* Reset bound sem. */
150+ ret = k_sem_init (& bound_sem , 0 , 1 );
151+ if (ret != 0 ) {
152+ LOG_ERR ("k_sem_init() failure" );
153+ return ret ;
154+ }
155+
156+ uintptr_t tx_shm_size = DT_REG_SIZE (DT_INST_PHANDLE (0 , tx_region ));
157+ uintptr_t tx_shm_addr = DT_REG_ADDR (DT_INST_PHANDLE (0 , tx_region ));
158+ uintptr_t rx_shm_size = DT_REG_SIZE (DT_INST_PHANDLE (0 , rx_region ));
159+ uintptr_t rx_shm_addr = DT_REG_ADDR (DT_INST_PHANDLE (0 , rx_region ));
160+
161+ LOG_INF ("Clean shared memory" );
162+
163+ memset ((void * )tx_shm_addr , 0 , tx_shm_size );
164+ memset ((void * )rx_shm_addr , 0 , rx_shm_size );
165+
166+ ret = ipc_service_register_endpoint (ipc0_instance , & ep , & ep_cfg );
167+ if (ret != 0 ) {
168+ LOG_INF ("ipc_service_register_endpoint() failure" );
169+ return ret ;
170+ }
171+
172+ LOG_INF ("Run network core" );
173+ nrf_reset_network_force_off (NRF_RESET , false);
174+
175+ k_sem_take (& bound_sem , K_FOREVER );
176+
177+ ret = send_for_time (& ep , SENDING_TIME_MS );
178+ if (ret < 0 ) {
179+ LOG_ERR ("send_for_time() failure" );
180+ return ret ;
181+ }
182+
127183 LOG_INF ("IPC-service HOST demo ended" );
128184
129185 return 0 ;
0 commit comments