Skip to content

Commit bac6ef7

Browse files
jaz1-nordicrlubos
authored andcommitted
[nrf fromlist] samples: subsys: ipc: icmsg: Align to NO MULTITHREADING
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
1 parent 5616857 commit bac6ef7

File tree

4 files changed

+136
-8
lines changed

4 files changed

+136
-8
lines changed

samples/subsys/ipc/ipc_service/icmsg/remote/boards/nrf54l15pdk_nrf54l15_cpuflpr.overlay

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@
3939
&cpuflpr_vevif_tx {
4040
status = "okay";
4141
};
42+
43+
&uart30 {
44+
/delete-property/ hw-flow-control;
45+
};

samples/subsys/ipc/ipc_service/icmsg/remote/src/main.c

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,44 @@
1414
#include <zephyr/logging/log.h>
1515
LOG_MODULE_REGISTER(remote, LOG_LEVEL_INF);
1616

17-
17+
#if defined(CONFIG_MULTITHREADING)
1818
K_SEM_DEFINE(bound_sem, 0, 1);
19+
#else
20+
volatile uint32_t bound_sem = 1;
21+
volatile uint32_t recv_sem = 1;
22+
#endif
23+
24+
static unsigned char expected_message = 'a';
25+
static size_t expected_len = PACKET_SIZE_START;
26+
static size_t received;
1927

2028
static void ep_bound(void *priv)
2129
{
30+
received = 0;
31+
#if defined(CONFIG_MULTITHREADING)
2232
k_sem_give(&bound_sem);
33+
#else
34+
bound_sem = 0;
35+
#endif
2336
LOG_INF("Ep bounded");
2437
}
2538

2639
static void ep_recv(const void *data, size_t len, void *priv)
2740
{
41+
#if defined(CONFIG_ASSERT)
2842
struct data_packet *packet = (struct data_packet *)data;
29-
static unsigned char expected_message = 'a';
30-
static size_t expected_len = PACKET_SIZE_START;
3143

3244
__ASSERT(packet->data[0] == expected_message, "Unexpected message. Expected %c, got %c",
3345
expected_message, packet->data[0]);
3446
__ASSERT(len == expected_len, "Unexpected length. Expected %zu, got %zu",
3547
expected_len, len);
48+
#endif
49+
50+
#ifndef CONFIG_MULTITHREADING
51+
recv_sem = 0;
52+
#endif
3653

54+
received += len;
3755
expected_message++;
3856
expected_len++;
3957

@@ -61,11 +79,17 @@ static int send_for_time(struct ipc_ept *ep, const int64_t sending_time_ms)
6179
ret = ipc_service_send(ep, &msg, mlen);
6280
if (ret == -ENOMEM) {
6381
/* No space in the buffer. Retry. */
82+
ret = 0;
6483
continue;
6584
} else if (ret < 0) {
6685
LOG_ERR("Failed to send (%c) failed with ret %d", msg.data[0], ret);
6786
break;
6887
}
88+
#if !defined(CONFIG_MULTITHREADING)
89+
else {
90+
recv_sem = 1;
91+
}
92+
#endif
6993

7094
msg.data[0]++;
7195
if (msg.data[0] > 'Z') {
@@ -79,7 +103,12 @@ static int send_for_time(struct ipc_ept *ep, const int64_t sending_time_ms)
79103
mlen = PACKET_SIZE_START;
80104
}
81105

106+
#if defined(CONFIG_MULTITHREADING)
82107
k_usleep(1);
108+
#else
109+
while ((recv_sem != 0) && ((k_uptime_get() - start) < sending_time_ms)) {
110+
};
111+
#endif
83112
}
84113

85114
LOG_INF("Sent %zu [Bytes] over %lld [ms]", bytes_sent, sending_time_ms);
@@ -111,19 +140,25 @@ int main(void)
111140
}
112141

113142
ret = ipc_service_register_endpoint(ipc0_instance, &ep, &ep_cfg);
114-
if (ret != 0) {
143+
if (ret < 0) {
115144
LOG_ERR("ipc_service_register_endpoint() failure");
116145
return ret;
117146
}
118147

148+
#if defined(CONFIG_MULTITHREADING)
119149
k_sem_take(&bound_sem, K_FOREVER);
150+
#else
151+
while (bound_sem != 0) {
152+
};
153+
#endif
120154

121155
ret = send_for_time(&ep, SENDING_TIME_MS);
122156
if (ret < 0) {
123157
LOG_ERR("send_for_time() failure");
124158
return ret;
125159
}
126160

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

129164
return 0;

samples/subsys/ipc/ipc_service/icmsg/sample.yaml

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ tests:
1818
- "host: Sent"
1919
- "host: Received"
2020
- "host: IPC-service HOST demo ended"
21+
2122
sample.ipc.icmsg.nrf54l15:
2223
platform_allow: nrf54l15pdk/nrf54l15/cpuapp
2324
integration_platforms:
@@ -26,4 +27,60 @@ tests:
2627
extra_args:
2728
icmsg_SNIPPET=nordic-flpr
2829
sysbuild: true
29-
harness: remote
30+
harness: console
31+
harness_config:
32+
type: multi_line
33+
ordered: false
34+
regex:
35+
- "host: IPC-service HOST demo started"
36+
- "host: Ep bounded"
37+
- "host: Perform sends for"
38+
- "host: Sent"
39+
- "host: Received"
40+
- "host: IPC-service HOST demo ended"
41+
42+
sample.ipc.icmsg.nrf54l15_no_multithreading:
43+
platform_allow: nrf54l15pdk/nrf54l15/cpuapp
44+
integration_platforms:
45+
- nrf54l15pdk/nrf54l15/cpuapp
46+
tags: ipc
47+
extra_args:
48+
icmsg_SNIPPET=nordic-flpr
49+
icmsg_CONFIG_MULTITHREADING=n
50+
icmsg_CONFIG_LOG_MODE_MINIMAL=y
51+
remote_CONFIG_MULTITHREADING=n
52+
remote_CONFIG_LOG_MODE_MINIMAL=y
53+
sysbuild: true
54+
harness: console
55+
harness_config:
56+
type: multi_line
57+
ordered: false
58+
regex:
59+
- "I: IPC-service HOST demo started"
60+
- "I: Ep bounded"
61+
- "I: Perform sends for"
62+
- "I: Sent"
63+
- "I: Received"
64+
- "I: IPC-service HOST demo ended"
65+
66+
sample.ipc.icmsg.nrf54l15_remote_no_multithreading:
67+
platform_allow: nrf54l15pdk/nrf54l15/cpuapp
68+
integration_platforms:
69+
- nrf54l15pdk/nrf54l15/cpuapp
70+
tags: ipc
71+
extra_args:
72+
icmsg_SNIPPET=nordic-flpr
73+
remote_CONFIG_MULTITHREADING=n
74+
remote_CONFIG_LOG_MODE_MINIMAL=y
75+
sysbuild: true
76+
harness: console
77+
harness_config:
78+
type: multi_line
79+
ordered: false
80+
regex:
81+
- "host: IPC-service HOST demo started"
82+
- "host: Ep bounded"
83+
- "host: Perform sends for"
84+
- "host: Sent"
85+
- "host: Received"
86+
- "host: IPC-service HOST demo ended"

samples/subsys/ipc/ipc_service/icmsg/src/main.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,42 @@
1818
#include <zephyr/logging/log.h>
1919
LOG_MODULE_REGISTER(host, LOG_LEVEL_INF);
2020

21-
21+
#if defined(CONFIG_MULTITHREADING)
2222
K_SEM_DEFINE(bound_sem, 0, 1);
23+
#else
24+
volatile uint32_t bound_sem = 1;
25+
volatile uint32_t recv_sem = 1;
26+
#endif
27+
2328
static unsigned char expected_message = 'A';
2429
static size_t expected_len = PACKET_SIZE_START;
25-
2630
static size_t received;
2731

2832
static void ep_bound(void *priv)
2933
{
3034
received = 0;
31-
35+
#if defined(CONFIG_MULTITHREADING)
3236
k_sem_give(&bound_sem);
37+
#else
38+
bound_sem = 0;
39+
#endif
3340
LOG_INF("Ep bounded");
3441
}
3542

3643
static void ep_recv(const void *data, size_t len, void *priv)
3744
{
45+
#if defined(CONFIG_ASSERT)
3846
struct data_packet *packet = (struct data_packet *)data;
3947

4048
__ASSERT(packet->data[0] == expected_message, "Unexpected message. Expected %c, got %c",
4149
expected_message, packet->data[0]);
4250
__ASSERT(len == expected_len, "Unexpected length. Expected %zu, got %zu",
4351
expected_len, len);
52+
#endif
53+
54+
#ifndef CONFIG_MULTITHREADING
55+
recv_sem = 0;
56+
#endif
4457

4558
received += len;
4659
expected_message++;
@@ -75,6 +88,11 @@ static int send_for_time(struct ipc_ept *ep, const int64_t sending_time_ms)
7588
LOG_ERR("Failed to send (%c) failed with ret %d", msg.data[0], ret);
7689
break;
7790
}
91+
#if !defined(CONFIG_MULTITHREADING)
92+
else {
93+
recv_sem = 1;
94+
}
95+
#endif
7896

7997
msg.data[0]++;
8098
if (msg.data[0] > 'z') {
@@ -88,7 +106,12 @@ static int send_for_time(struct ipc_ept *ep, const int64_t sending_time_ms)
88106
mlen = PACKET_SIZE_START;
89107
}
90108

109+
#if defined(CONFIG_MULTITHREADING)
91110
k_usleep(1);
111+
#else
112+
while ((recv_sem != 0) && ((k_uptime_get() - start) < sending_time_ms)) {
113+
};
114+
#endif
92115
}
93116

94117
LOG_INF("Sent %zu [Bytes] over %lld [ms]", bytes_sent, sending_time_ms);
@@ -125,7 +148,12 @@ int main(void)
125148
return ret;
126149
}
127150

151+
#if defined(CONFIG_MULTITHREADING)
128152
k_sem_take(&bound_sem, K_FOREVER);
153+
#else
154+
while (bound_sem != 0) {
155+
};
156+
#endif
129157

130158
ret = send_for_time(&ep, SENDING_TIME_MS);
131159
if (ret < 0) {
@@ -134,7 +162,11 @@ int main(void)
134162
}
135163

136164
LOG_INF("Wait 500ms. Let remote core finish its sends");
165+
#if defined(CONFIG_MULTITHREADING)
137166
k_msleep(500);
167+
#else
168+
k_busy_wait(500000);
169+
#endif
138170

139171
LOG_INF("Received %zu [Bytes] in total", received);
140172

0 commit comments

Comments
 (0)