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

samples: subsys: ipc: basic: Basic cores communication #4

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 21 additions & 0 deletions samples/subsys/ipc/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

if(NOT CONFIG_BOARD_NRF54L15PDK_NRF54L15_CPUAPP)
message(FATAL_ERROR "${BOARD} is not supported for this sample")
endif()

project(ipc_basic_host)

target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/common)

target_sources(app PRIVATE src/main.c)

include(ExternalProject)
9 changes: 9 additions & 0 deletions samples/subsys/ipc/basic/Kconfig.sysbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0

source "share/sysbuild/Kconfig"

config REMOTE_BOARD
string
default "nrf54l15pdk/nrf54l15/cpuflpr" if $(BOARD) = "nrf54l15pdk"
48 changes: 48 additions & 0 deletions samples/subsys/ipc/basic/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.. zephyr:code-sample:: ipc-basic
:name: IPC service: basic struct
:relevant-api: ipc

Send messages between two cores using mbox and shared data structure.

Overview
********

This application demonstrates how to communcate between cores without any backend in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This application demonstrates how to communcate between cores without any backend in
This application demonstrates how to communicate between cores without any backend in

Zephyr. It is designed to demonstrate how to integrate it with Zephyr both
from a build perspective and code.

Building the application for nrf54l15pdk/nrf54l15/cpuapp
*****************************************************

.. zephyr-app-commands::
:zephyr-app: samples/subsys/ipc/basic
:board: nrf54l15pdk/nrf54l15/cpuapp
:goals: debug
:west-args: --sysbuild

Open a serial terminal (minicom, putty, etc.) and connect the board with the
following settings:

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

Reset the board and the following message will appear on the corresponding
serial port, one is host another is remote:

.. code-block:: console

*** Booting Zephyr OS build v3.7.0-rc1-427-g7f891a6a40e8 ***
I: No data from remote
I: Sent 14 bytes to host
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
I: Sent 14 bytes to host
I: Sent 14 bytes to remote

I guess it should be remote, as it is the host's log.

I: Read 14 bytes from remote, received 14
I: Basic core-communication HOST demo ended

.. code-block:: console

*** Booting Zephyr OS build v3.7.0-rc1-427-g7f891a6a40e8 ***
I: No data from host
I: Read 14 bytes from host, received 14
I: Sent 14 bytes to host
I: Basic core-communication REMOTE demo ended
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
soc {
reserved-memory {
#address-cells = <1>;
#size-cells = <1>;

sram_rx: memory@20018000 {
reg = <0x20018000 0x0800>;
};

sram_tx: memory@20020000 {
reg = <0x20020000 0x0800>;
};
};
};

mbox_consumer {
compatible = "vnd,mbox-consumer";
mboxes = <&cpuapp_vevif_rx 15>, <&cpuapp_vevif_tx 16>;
mbox-names = "rx", "tx";
};
};

&cpuapp_vevif_rx {
status = "okay";
};

&cpuapp_vevif_tx {
status = "okay";
};
31 changes: 31 additions & 0 deletions samples/subsys/ipc/basic/common/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef __COMMON_H__
#define __COMMON_H__

#include <stdatomic.h>

#define PACKET_SIZE_START (40)
#define DATA_SIZE (128)
#define SENDING_TIME_MS (1000)

typedef struct __attribute__((packed)) {

Check warning on line 16 in samples/subsys/ipc/basic/common/common.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

PREFER_PACKED

samples/subsys/ipc/basic/common/common.h:16 __packed is preferred over __attribute__((packed))
uint8_t some;
uint16_t data;
uint32_t to;
uint32_t send;
uint16_t trough;
uint8_t ipc;
} data_packet_t;

typedef struct {
atomic_bool lock;
unsigned long size;
unsigned char buffer[DATA_SIZE];
} shared_t;

#endif /* __COMMON_H__ */
4 changes: 4 additions & 0 deletions samples/subsys/ipc/basic/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_MBOX=y

CONFIG_LOG=y
CONFIG_LOG_MODE_MINIMAL=y
14 changes: 14 additions & 0 deletions samples/subsys/ipc/basic/remote/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Copyright (c) 2022 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
#

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(ipc_basic_remote)

target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../common)

target_sources(app PRIVATE src/main.c)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
soc {
reserved-memory {
#address-cells = <1>;
#size-cells = <1>;

sram_tx: memory@20018000 {
reg = <0x20018000 0x0800>;
};

sram_rx: memory@20020000 {
reg = <0x20020000 0x0800>;
};
};
};

mbox_consumer {
compatible = "vnd,mbox-consumer";
mboxes = <&cpuflpr_vevif_rx 16>, <&cpuflpr_vevif_tx 15>;
mbox-names = "rx", "tx";
};
};

&cpuflpr_vevif_rx {
status = "okay";
};

&cpuflpr_vevif_tx {
status = "okay";
};
6 changes: 6 additions & 0 deletions samples/subsys/ipc/basic/remote/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CONFIG_MBOX=y

CONFIG_LOG=y
CONFIG_LOG_MODE_MINIMAL=y

CONFIG_MULTITHREADING=n
Loading
Loading