diff --git a/samples/subsys/ipc/ipc_service/icmsg/remote/src/main.c b/samples/subsys/ipc/ipc_service/icmsg/remote/src/main.c index 5cabd03ac7705a0..e4b51369cdc19f3 100644 --- a/samples/subsys/ipc/ipc_service/icmsg/remote/src/main.c +++ b/samples/subsys/ipc/ipc_service/icmsg/remote/src/main.c @@ -14,26 +14,44 @@ #include LOG_MODULE_REGISTER(remote, LOG_LEVEL_INF); - +#if defined(CONFIG_MULTITHREADING) K_SEM_DEFINE(bound_sem, 0, 1); +#else +volatile uint32_t bound_sem = 1; +volatile uint32_t recv_sem = 1; +#endif + +static unsigned char expected_message = 'a'; +static size_t expected_len = PACKET_SIZE_START; +static size_t received; static void ep_bound(void *priv) { + received = 0; +#if defined(CONFIG_MULTITHREADING) k_sem_give(&bound_sem); +#else + bound_sem = 0; +#endif LOG_INF("Ep bounded"); } static void ep_recv(const void *data, size_t len, void *priv) { +#if defined(CONFIG_ASSERT) struct data_packet *packet = (struct data_packet *)data; - static unsigned char expected_message = 'a'; - static size_t expected_len = PACKET_SIZE_START; __ASSERT(packet->data[0] == expected_message, "Unexpected message. Expected %c, got %c", expected_message, packet->data[0]); __ASSERT(len == expected_len, "Unexpected length. Expected %zu, got %zu", expected_len, len); +#endif + +#ifndef CONFIG_MULTITHREADING + recv_sem = 0; +#endif + received += len; expected_message++; expected_len++; @@ -61,11 +79,17 @@ static int send_for_time(struct ipc_ept *ep, const int64_t sending_time_ms) ret = ipc_service_send(ep, &msg, mlen); if (ret == -ENOMEM) { /* No space in the buffer. Retry. */ + ret = 0; continue; } else if (ret < 0) { LOG_ERR("Failed to send (%c) failed with ret %d", msg.data[0], ret); break; } +#if !defined(CONFIG_MULTITHREADING) + else { + recv_sem = 1; + } +#endif msg.data[0]++; if (msg.data[0] > 'Z') { @@ -79,7 +103,12 @@ static int send_for_time(struct ipc_ept *ep, const int64_t sending_time_ms) mlen = PACKET_SIZE_START; } +#if defined(CONFIG_MULTITHREADING) k_usleep(1); +#else + while ((recv_sem != 0) && ((k_uptime_get() - start) < sending_time_ms)) { + }; +#endif } LOG_INF("Sent %zu [Bytes] over %lld [ms]", bytes_sent, sending_time_ms); @@ -111,12 +140,17 @@ int main(void) } ret = ipc_service_register_endpoint(ipc0_instance, &ep, &ep_cfg); - if (ret != 0) { + if (ret < 0) { LOG_ERR("ipc_service_register_endpoint() failure"); return ret; } +#if defined(CONFIG_MULTITHREADING) k_sem_take(&bound_sem, K_FOREVER); +#else + while (bound_sem != 0) { + }; +#endif ret = send_for_time(&ep, SENDING_TIME_MS); if (ret < 0) { @@ -124,6 +158,7 @@ int main(void) return ret; } + LOG_INF("Received %zu [Bytes] in total", received); LOG_INF("IPC-service REMOTE demo ended"); return 0; diff --git a/samples/subsys/ipc/ipc_service/icmsg/sample.yaml b/samples/subsys/ipc/ipc_service/icmsg/sample.yaml index 298c41f56dbb23a..39618937867d390 100644 --- a/samples/subsys/ipc/ipc_service/icmsg/sample.yaml +++ b/samples/subsys/ipc/ipc_service/icmsg/sample.yaml @@ -18,6 +18,7 @@ tests: - "host: Sent" - "host: Received" - "host: IPC-service HOST demo ended" + sample.ipc.icmsg.nrf54l15: platform_allow: nrf54l15pdk/nrf54l15/cpuapp integration_platforms: @@ -27,3 +28,17 @@ tests: icmsg_SNIPPET=nordic-flpr sysbuild: true harness: remote + + sample.ipc.icmsg.nrf54l15_no_multithreading: + platform_allow: nrf54l15pdk/nrf54l15/cpuapp + integration_platforms: + - nrf54l15pdk/nrf54l15/cpuapp + tags: ipc + extra_args: + icmsg_SNIPPET=nordic-flpr + icmsg_CONFIG_MULTITHREADING=n + icmsg_CONFIG_LOG_MODE_MINIMAL=y + remote_CONFIG_MULTITHREADING=n + remote_CONFIG_LOG_MODE_MINIMAL=y + sysbuild: true + harness: remote diff --git a/samples/subsys/ipc/ipc_service/icmsg/src/main.c b/samples/subsys/ipc/ipc_service/icmsg/src/main.c index 0b492ddd1c02d72..d8d98fe8ae21e62 100644 --- a/samples/subsys/ipc/ipc_service/icmsg/src/main.c +++ b/samples/subsys/ipc/ipc_service/icmsg/src/main.c @@ -18,29 +18,42 @@ #include LOG_MODULE_REGISTER(host, LOG_LEVEL_INF); - +#if defined(CONFIG_MULTITHREADING) K_SEM_DEFINE(bound_sem, 0, 1); +#else +volatile uint32_t bound_sem = 1; +volatile uint32_t recv_sem = 1; +#endif + static unsigned char expected_message = 'A'; static size_t expected_len = PACKET_SIZE_START; - static size_t received; static void ep_bound(void *priv) { received = 0; - +#if defined(CONFIG_MULTITHREADING) k_sem_give(&bound_sem); +#else + bound_sem = 0; +#endif LOG_INF("Ep bounded"); } static void ep_recv(const void *data, size_t len, void *priv) { +#if defined(CONFIG_ASSERT) struct data_packet *packet = (struct data_packet *)data; __ASSERT(packet->data[0] == expected_message, "Unexpected message. Expected %c, got %c", expected_message, packet->data[0]); __ASSERT(len == expected_len, "Unexpected length. Expected %zu, got %zu", expected_len, len); +#endif + +#ifndef CONFIG_MULTITHREADING + recv_sem = 0; +#endif received += len; expected_message++; @@ -76,6 +89,11 @@ static int send_for_time(struct ipc_ept *ep, const int64_t sending_time_ms) LOG_ERR("Failed to send (%c) failed with ret %d", msg.data[0], ret); break; } +#if !defined(CONFIG_MULTITHREADING) + else { + recv_sem = 1; + } +#endif msg.data[0]++; if (msg.data[0] > 'z') { @@ -89,7 +107,12 @@ static int send_for_time(struct ipc_ept *ep, const int64_t sending_time_ms) mlen = PACKET_SIZE_START; } +#if defined(CONFIG_MULTITHREADING) k_usleep(1); +#else + while ((recv_sem != 0) && ((k_uptime_get() - start) < sending_time_ms)) { + }; +#endif } LOG_INF("Sent %zu [Bytes] over %lld [ms]", bytes_sent, sending_time_ms); @@ -126,7 +149,12 @@ int main(void) return ret; } +#if defined(CONFIG_MULTITHREADING) k_sem_take(&bound_sem, K_FOREVER); +#else + while (bound_sem != 0) { + }; +#endif ret = send_for_time(&ep, SENDING_TIME_MS); if (ret < 0) { @@ -135,7 +163,11 @@ int main(void) } LOG_INF("Wait 500ms. Let remote core finish its sends"); +#if defined(CONFIG_MULTITHREADING) k_msleep(500); +#else + k_busy_wait(500000); +#endif LOG_INF("Received %zu [Bytes] in total", received);