Skip to content

Commit

Permalink
samples: subsys: ipc: icmsg: Align to NO MULTITHREADING
Browse files Browse the repository at this point in the history
Removed k_sleep dependencies and added 'printk' instead of LOG
in non-multithreaded runs.

Signed-off-by: Jakub Zymelka <[email protected]>
  • Loading branch information
jaz1-nordic committed Jun 17, 2024
1 parent c560d2e commit f2cc498
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 7 deletions.
43 changes: 39 additions & 4 deletions samples/subsys/ipc/ipc_service/icmsg/remote/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,44 @@
#include <zephyr/logging/log.h>
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++;

Expand Down Expand Up @@ -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') {
Expand All @@ -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);
Expand Down Expand Up @@ -111,19 +140,25 @@ 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) {
LOG_ERR("send_for_time() failure");
return ret;
}

LOG_INF("Received %zu [Bytes] in total", received);
LOG_INF("IPC-service REMOTE demo ended");

return 0;
Expand Down
15 changes: 15 additions & 0 deletions samples/subsys/ipc/ipc_service/icmsg/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
38 changes: 35 additions & 3 deletions samples/subsys/ipc/ipc_service/icmsg/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,42 @@
#include <zephyr/logging/log.h>
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++;
Expand Down Expand Up @@ -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') {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand Down

0 comments on commit f2cc498

Please sign in to comment.