zephyr/samples/subsys/ipc/rpmsg_multi_instance
Carlo Caione 0c2dabb4b9 ipc: rpmsg_multi_instance: Rework instance tracking
This patch is the first step to make the rpmsg_multi_instance usable in
a multi-core scenario.

The current driver is using a local driver variable (instance) to track
the number of allocated instances. This counter is practically used to
allocate to the instance the correct portion of the shared memory.

This is fundamentally wrong because this is assuming that it does exist
only one single shared memory region to split amongs all the allocated
instances.  When the platform has more than one core this is obviously
not the case since each couple of cores are communicating using a
different memory region.

To solve this issue we introduce a new struct rpmsg_mi_ctx_shm_cfg that
is doing two things: (1) it's carrying the information about the shared
memory and (2) it's carrying an internal variable used to track the
instances allocated in that region. The same struct should be used every
time a new instance is allocated in the same shared memory region.

We also fix a problem with the current code where there is a race
between threads when accessing the instance variable, so this patch is
adding a serializing mutex.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-08-27 06:44:08 -04:00
..
boards
remote ipc: rpmsg_multi_instance: Rework instance tracking 2021-08-27 06:44:08 -04:00
src ipc: rpmsg_multi_instance: Rework instance tracking 2021-08-27 06:44:08 -04:00
CMakeLists.txt cmake: increase minimal required version to 3.20.0 2021-08-20 09:47:34 +02:00
prj.conf
README.rst
sample.yaml

.. _Multiple_instance_RPMsg_sample:

Multiple instance of RPMsg
##########################

Overview
********

Multiple instance of RPMsg is an abstraction created over OpenAMP.
It simplifies the initialization and endpoint creation process.
This sample demonstrates how to use multi-instance RPMsg in Zephyr.

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

.. zephyr-app-commands::
   :zephyr-app: samples/subsys/ipc/rpmsg_multi_instance
   :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

When you reset the development kit, the following messages (one for master and one for remote) will appear on the corresponding serial ports:

.. code-block:: console

   *** Booting Zephyr OS build zephyr-v2.5.0-3564-gf89886d69a8c  ***
   Starting application thread!

   RPMsg Multiple instance [master no 1] demo started

   RPMsg Multiple instance [master no 2] demo started
   Master [no 1] core received a message: 1
   Master [no 2] core received a message: 1
   Master [no 1] core received a message: 3
   Master [no 2] core received a message: 3
   Master [no 1] core received a message: 5
   Master [no 2] core received a message: 5
   ...
   Master [no 1] core received a message: 99
   RPMsg Multiple instance [no 1] demo ended.
   Master [no 2] core received a message: 99
   RPMsg Multiple instance [no 2] demo ended.


.. code-block:: console

   *** Booting Zephyr OS build zephyr-v2.5.0-3564-gf89886d69a8c  ***
   Starting application thread!

   RPMsg Multiple instance [remote no 1] demo started

   RPMsg Multiple instance [remote no 2] demo started
   Remote [no 1] core received a message: 0
   Remote [no 2] core received a message: 0
   Remote [no 1] core received a message: 2
   Remote [no 2] core received a message: 2
   Remote [no 1] core received a message: 4
   Remote [no 2] core received a message: 4
   ...
   Remote [no 1] core received a message: 98
   RPMsg Multiple instance [no 1] demo ended.
   Remote [no 2] core received a message: 98
   RPMsg Multiple instance [no 2] demo ended.