Skip to content

Commit

Permalink
samples: ipc: Modify icmsg_me sample allowing any multiendpoint backend
Browse files Browse the repository at this point in the history
There are more ipc_service backends that supports multiple endpoint.
This sample can be used for any of those backends, so this commits
makes the sample more generic. The default backend it still icmsg_me,
but now, the sample has files and instructions for icmsg_with_buf
backend.

Signed-off-by: Dominik Kilian <Dominik.Kilian@nordicsemi.no>
  • Loading branch information
doki-nordic committed Nov 2, 2023
1 parent 4e0a8db commit 6b07cb5
Show file tree
Hide file tree
Showing 15 changed files with 196 additions and 6 deletions.
Expand Up @@ -25,7 +25,7 @@ ExternalProject_Add(
ipc_service_remote
SOURCE_DIR ${APPLICATION_SOURCE_DIR}/remote
INSTALL_COMMAND "" # This particular build system has no install command
CMAKE_CACHE_ARGS -DBOARD:STRING=${BOARD_REMOTE}
CMAKE_CACHE_ARGS -DBOARD:STRING=${BOARD_REMOTE} -DDTC_OVERLAY_FILE:STRING=${DTC_OVERLAY_FILE_REMOTE}
BUILD_BYPRODUCTS "${REMOTE_ZEPHYR_DIR}/${KERNEL_BIN_NAME}"
# NB: Do we need to pass on more CMake variables?
BUILD_ALWAYS True
Expand Down
74 changes: 74 additions & 0 deletions samples/subsys/ipc/ipc_service/multi_endpoint/README.rst
@@ -0,0 +1,74 @@
.. _ipc_multi_endpoint_sample:

IPC Service - Multi-endpoint Sample Application
###############################################

This application demonstrates how to use IPC Service with multiple endpoints.
By default, it uses the ``icmsg_me`` backend.
You can also configure it to use the ``icbmsg`` backend.

Building the application for nrf5340dk_nrf5340_cpuapp
*****************************************************

.. zephyr-app-commands::
:zephyr-app: samples/subsys/ipc/ipc_service/multi_endpoint
:board: nrf5340dk_nrf5340_cpuapp
:goals: debug

Open a serial terminal (for example Minicom or PuTTY) and connect the board with the
following settings:

- Speed: 115200
- Data: 8 bits
- Parity: None
- Stop bits: 1

After resetting the board, the following message will appear on the corresponding
serial port:

.. code-block:: console
*** Booting Zephyr OS build v3.4.0-rc1-108-gccfbac8b0721 ***
IPC-service HOST [INST 0 - ENDP A] demo started
IPC-service HOST [INST 0 - ENDP B] demo started
IPC-service HOST [INST 1] demo started
HOST [0A]: 1
HOST [0A]: 3
HOST [0B]: 1
HOST [1]: 1
...
HOST [0A]: 99
IPC-service HOST [INST 0 - ENDP A] demo ended.
HOST [0B]: 99
IPC-service HOST [INST 0 - ENDP B] demo ended.
HOST [1]: 99
IPC-service HOST [INST 1] demo ended.
.. code-block:: console
*** Booting Zephyr OS build v3.4.0-rc1-108-gccfbac8b0721 ***
IPC-service REMOTE [INST 0 - ENDP A] demo started
IPC-service REMOTE [INST 0 - ENDP B] demo started
IPC-service REMOTE [INST 1] demo started
REMOTE [0A]: 0
REMOTE [0A]: 2
...
REMOTE [0A]: 98
IPC-service REMOTE [INST 0 - ENDP A] demo ended.
REMOTE [0B]: 98
IPC-service REMOTE [INST 0 - ENDP B] demo ended.
REMOTE [1]: 98
IPC-service REMOTE [INST 1] demo ended.
Changing the backend
********************

To change the backend to ``icbmsg``, switch the devicetree
overlay files as follows:

.. code-block:: console
$ west build -b nrf5340dk_nrf5340_cpuapp -- \
-DDTC_OVERLAY_FILE=boards/nrf5340dk_nrf5340_cpuapp_icbmsg.overlay \
-DDTC_OVERLAY_FILE_REMOTE=boards/nrf5340dk_nrf5340_cpunet_icbmsg.overlay
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
/delete-property/ zephyr,ipc_shm;
};

reserved-memory {
/delete-node/ memory@20070000;

sram_ipc0_tx: memory@20070000 {
reg = <0x20070000 0x4000>;
};

sram_ipc0_rx: memory@20074000 {
reg = <0x20074000 0x4000>;
};

sram_ipc1_tx: memory@20078000 {
reg = <0x20078000 0x4000>;
};

sram_ipc1_rx: memory@2007C000 {
reg = <0x2007C000 0x4000>;
};
};

ipc {
/delete-node/ ipc0;

ipc0: ipc0 {
compatible = "zephyr,ipc-icbmsg";
tx-region = <&sram_ipc0_tx>;
rx-region = <&sram_ipc0_rx>;
tx-blocks = <16>;
rx-blocks = <24>;
mboxes = <&mbox 0>, <&mbox 1>;
mbox-names = "tx", "rx";
status = "okay";
};

ipc1: ipc1 {
compatible = "zephyr,ipc-icbmsg";
tx-region = <&sram_ipc1_tx>;
rx-region = <&sram_ipc1_rx>;
tx-blocks = <32>;
rx-blocks = <48>;
mboxes = <&mbox 2>, <&mbox 3>;
mbox-names = "tx", "rx";
status = "okay";
};
};
};
@@ -1,4 +1,5 @@
CONFIG_PRINTK=y
CONFIG_LOG_PRINTK=n

CONFIG_IPC_SERVICE=y
CONFIG_IPC_SERVICE_BACKEND_ICMSG_ME_NOCOPY_RX=y
Expand Down
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
/delete-property/ zephyr,ipc_shm;
};

reserved-memory {
/delete-node/ memory@20070000;

sram_ipc0_rx: memory@20070000 {
reg = <0x20070000 0x4000>;
};

sram_ipc0_tx: memory@20074000 {
reg = <0x20074000 0x4000>;
};

sram_ipc1_rx: memory@20078000 {
reg = <0x20078000 0x4000>;
};

sram_ipc1_tx: memory@2007C000 {
reg = <0x2007C000 0x4000>;
};
};

ipc {
/delete-node/ ipc0;

ipc0: ipc0 {
compatible = "zephyr,ipc-icbmsg";
tx-region = <&sram_ipc0_tx>;
rx-region = <&sram_ipc0_rx>;
tx-blocks = <24>;
rx-blocks = <16>;
mboxes = <&mbox 0>, <&mbox 1>;
mbox-names = "rx", "tx";
status = "okay";
};

ipc1: ipc1 {
compatible = "zephyr,ipc-icbmsg";
tx-region = <&sram_ipc1_tx>;
rx-region = <&sram_ipc1_rx>;
tx-blocks = <48>;
rx-blocks = <32>;
mboxes = <&mbox 2>, <&mbox 3>;
mbox-names = "rx", "tx";
status = "okay";
};
};
};
@@ -1,4 +1,5 @@
CONFIG_PRINTK=y
CONFIG_LOG_PRINTK=n

CONFIG_IPC_SERVICE=y
CONFIG_IPC_SERVICE_BACKEND_ICMSG_ME_NOCOPY_RX=y
Expand Down
Expand Up @@ -258,15 +258,15 @@ static void ipc1_entry(void *dummy0, void *dummy1, void *dummy2)
printk("get_tx_buffer(%u) failed with ret %d\n", sizeof(message), ret);
break;
}
if (tx_buffer_size != sizeof(message)) {
if (tx_buffer_size < sizeof(message)) {
printk("get_tx_buffer modified buffer size to unexpected value %u\n",
tx_buffer_size);
break;
}

*((uint8_t *) tx_buffer) = message;

ret = ipc_service_send_nocopy(&ipc1_ept, tx_buffer, tx_buffer_size);
ret = ipc_service_send_nocopy(&ipc1_ept, tx_buffer, sizeof(message));
if (ret < 0) {
printk("send_message_nocopy(%u) failed with ret %d\n", message, ret);
break;
Expand Down
@@ -1,7 +1,7 @@
sample:
name: IPC Service example integration (icmsg multi endpoint backend)
tests:
sample.ipc.icmsg_me:
sample.ipc.multi_endpoint:
platform_allow: nrf5340dk_nrf5340_cpuapp
integration_platforms:
- nrf5340dk_nrf5340_cpuapp
Expand Down
Expand Up @@ -250,15 +250,15 @@ static void ipc1_entry(void *dummy0, void *dummy1, void *dummy2)
printk("get_tx_buffer(%u) failed with ret %d\n", sizeof(message), ret);
break;
}
if (tx_buffer_size != sizeof(message)) {
if (tx_buffer_size < sizeof(message)) {
printk("get_tx_buffer modified buffer size to unexpected value %u\n",
tx_buffer_size);
break;
}

*((uint8_t *) tx_buffer) = message;

ret = ipc_service_send_nocopy(&ipc1_ept, tx_buffer, tx_buffer_size);
ret = ipc_service_send_nocopy(&ipc1_ept, tx_buffer, sizeof(message));
if (ret < 0) {
printk("send_message_nocopy(%u) failed with ret %d\n", message, ret);
break;
Expand Down

0 comments on commit 6b07cb5

Please sign in to comment.