Skip to content

Commit

Permalink
[nrf fromlist] 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]>

Upstream PR: zephyrproject-rtos/zephyr#73857
  • Loading branch information
jaz1-nordic authored and masz-nordic committed Jul 29, 2024
1 parent 492be49 commit 067240e
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@
&cpuflpr_vevif_tx {
status = "okay";
};

&uart30 {
/delete-property/ hw-flow-control;
};
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
59 changes: 58 additions & 1 deletion 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 @@ -26,4 +27,60 @@ tests:
extra_args:
icmsg_SNIPPET=nordic-flpr
sysbuild: true
harness: remote
harness: console
harness_config:
type: multi_line
ordered: false
regex:
- "host: IPC-service HOST demo started"
- "host: Ep bounded"
- "host: Perform sends for"
- "host: Sent"
- "host: Received"
- "host: IPC-service HOST demo ended"

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: console
harness_config:
type: multi_line
ordered: false
regex:
- "I: IPC-service HOST demo started"
- "I: Ep bounded"
- "I: Perform sends for"
- "I: Sent"
- "I: Received"
- "I: IPC-service HOST demo ended"

sample.ipc.icmsg.nrf54l15_remote_no_multithreading:
platform_allow: nrf54l15pdk/nrf54l15/cpuapp
integration_platforms:
- nrf54l15pdk/nrf54l15/cpuapp
tags: ipc
extra_args:
icmsg_SNIPPET=nordic-flpr
remote_CONFIG_MULTITHREADING=n
remote_CONFIG_LOG_MODE_MINIMAL=y
sysbuild: true
harness: console
harness_config:
type: multi_line
ordered: false
regex:
- "host: IPC-service HOST demo started"
- "host: Ep bounded"
- "host: Perform sends for"
- "host: Sent"
- "host: Received"
- "host: IPC-service HOST demo ended"
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 @@ -75,6 +88,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 @@ -88,7 +106,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 @@ -125,7 +148,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 @@ -134,7 +162,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 067240e

Please sign in to comment.