Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes required for SW-defined IO devices on L15 #1887

Merged
merged 5 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions arch/riscv/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ FUNC_NORETURN void z_riscv_switch_to_main_no_multithreading(k_thread_entry_t mai
main_stack = (K_THREAD_STACK_BUFFER(z_main_stack) +
K_THREAD_STACK_SIZEOF(z_main_stack));

irq_unlock(MSTATUS_IEN);

__asm__ volatile (
"mv sp, %0; jalr ra, %1, 0"
:
Expand Down
2 changes: 2 additions & 0 deletions include/zephyr/ipc/icmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ struct icmsg_data_t {

/* General */
const struct icmsg_config_t *cfg;
#ifdef CONFIG_MULTITHREADING
struct k_work_delayable notify_work;
struct k_work mbox_work;
#endif
atomic_t state;
};

Expand Down
9 changes: 6 additions & 3 deletions samples/drivers/mbox/remote/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,20 @@ int main(void)
printk("Maximum TX channels: %d\n", mbox_max_channels_get_dt(&tx_channel));

while (1) {
#if defined(CONFIG_MULTITHREADING)
k_sleep(K_MSEC(3000));
#else
k_busy_wait(3000000);
#endif

printk("Ping (on channel %d)\n", tx_channel.channel_id);

ret = mbox_send_dt(&tx_channel, NULL);
if (ret < 0) {
printk("Could not send (%d)\n", ret);
return 0;
}

k_sleep(K_MSEC(3000));
}
#endif /* CONFIG_TX_ENABLED */

return 0;
}
35 changes: 35 additions & 0 deletions samples/drivers/mbox/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,38 @@ tests:
regex:
- "Ping \\(on channel 16\\)"
- "Pong \\(on channel 15\\)"

sample.drivers.mbox.nrf54l15_no_multithreading:
platform_allow:
- nrf54l15pdk/nrf54l15/cpuapp
integration_platforms:
- nrf54l15pdk/nrf54l15/cpuapp
extra_args:
mbox_SNIPPET=nordic-flpr
mbox_CONFIG_MULTITHREADING=n
remote_CONFIG_MULTITHREADING=n
sysbuild: true
harness: console
harness_config:
type: multi_line
ordered: false
regex:
- "Ping \\(on channel 16\\)"
- "Pong \\(on channel 15\\)"

sample.drivers.mbox.nrf54l15_remote_no_multithreading:
platform_allow:
- nrf54l15pdk/nrf54l15/cpuapp
integration_platforms:
- nrf54l15pdk/nrf54l15/cpuapp
extra_args:
mbox_SNIPPET=nordic-flpr
remote_CONFIG_MULTITHREADING=n
sysbuild: true
harness: console
harness_config:
type: multi_line
ordered: false
regex:
- "Ping \\(on channel 16\\)"
- "Pong \\(on channel 15\\)"
4 changes: 4 additions & 0 deletions samples/drivers/mbox/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ int main(void)
printk("Maximum TX channels: %d\n", mbox_max_channels_get_dt(&tx_channel));

while (1) {
#if defined(CONFIG_MULTITHREADING)
k_sleep(K_MSEC(2000));
#else
k_busy_wait(2000000);
#endif

printk("Ping (on channel %d)\n", tx_channel.channel_id);

Expand Down
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"
41 changes: 40 additions & 1 deletion samples/subsys/ipc/ipc_service/icmsg/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,44 @@
#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++;
expected_len++;

Expand Down Expand Up @@ -70,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 @@ -83,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 @@ -120,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 @@ -129,7 +162,13 @@ 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);

#if defined(CONFIG_SOC_NRF5340_CPUAPP)
LOG_INF("Stop network core");
Expand Down
2 changes: 2 additions & 0 deletions subsys/ipc/ipc_service/lib/Kconfig.icmsg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

config IPC_SERVICE_ICMSG_SHMEM_ACCESS_SYNC
bool "Synchronize access to shared memory"
depends on MULTITHREADING
default y
help
Provide synchronization access to shared memory at a library level.
Expand Down Expand Up @@ -30,6 +31,7 @@ config IPC_SERVICE_ICMSG_BOND_NOTIFY_REPEAT_TO_MS

config IPC_SERVICE_BACKEND_ICMSG_WQ_ENABLE
bool "Use dedicated workqueue"
depends on MULTITHREADING
default y
help
Enable dedicated workqueue thread for the ICMsg backend.
Expand Down
Loading
Loading