Browse Source

sample: mbox: Introduce MBOX NRFX IPC sample

Make use of the new MBOX APIs to create a ping-pong sample application.
This sample is using the NRFX IPC peripheral to send and receive signals
on different channels

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
pull/39785/head
Carlo Caione 4 years ago committed by Carles Cufí
parent
commit
af94cf55d0
  1. 36
      samples/drivers/mbox/CMakeLists.txt
  2. 2
      samples/drivers/mbox/boards/nrf5340dk_nrf5340_cpuapp.conf
  3. 18
      samples/drivers/mbox/boards/nrf5340dk_nrf5340_cpuapp.overlay
  4. 2
      samples/drivers/mbox/prj.conf
  5. 18
      samples/drivers/mbox/remote/CMakeLists.txt
  6. 1
      samples/drivers/mbox/remote/boards/nrf5340dk_nrf5340_cpunet.conf
  7. 18
      samples/drivers/mbox/remote/boards/nrf5340dk_nrf5340_cpunet.overlay
  8. 2
      samples/drivers/mbox/remote/prj.conf
  9. 52
      samples/drivers/mbox/remote/src/main.c
  10. 9
      samples/drivers/mbox/sample.yaml
  11. 51
      samples/drivers/mbox/src/main.c

36
samples/drivers/mbox/CMakeLists.txt

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
#
# Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
#
# SPDX-License-Identifier: Apache-2.0
#
cmake_minimum_required(VERSION 3.20.0)
set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/mbox_ipc_remote-prefix/src/mbox_ipc_remote-build/zephyr)
if("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpuapp")
set(BOARD_REMOTE "nrf5340dk_nrf5340_cpunet")
else()
message(FATAL_ERROR "${BOARD} is not supported for this sample")
endif()
message(INFO " ${BOARD} compile as Main in this sample")
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(mbox_ipc)
enable_language(C ASM)
target_sources(app PRIVATE src/main.c)
include(ExternalProject)
ExternalProject_Add(
mbox_ipc_remote
SOURCE_DIR ${APPLICATION_SOURCE_DIR}/remote
INSTALL_COMMAND "" # This particular build system has no install command
CMAKE_CACHE_ARGS -DBOARD:STRING=${BOARD_REMOTE}
BUILD_BYPRODUCTS "${REMOTE_ZEPHYR_DIR}/${KERNEL_BIN_NAME}"
# NB: Do we need to pass on more CMake variables?
BUILD_ALWAYS True
)

2
samples/drivers/mbox/boards/nrf5340dk_nrf5340_cpuapp.conf

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
CONFIG_MBOX_NRFX=y
CONFIG_BOARD_ENABLE_CPUNET=y

18
samples/drivers/mbox/boards/nrf5340dk_nrf5340_cpuapp.overlay

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
/*
* Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
soc {
mbox: mbox@2a000 {
compatible = "nordic,mbox-nrf-ipc";
reg = <0x2a000 0x1000>;
tx-mask = <0x0000ffff>;
rx-mask = <0x0000ffff>;
interrupts = <42 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay";
};
};
};

2
samples/drivers/mbox/prj.conf

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
CONFIG_PRINTK=y
CONFIG_MBOX=y

18
samples/drivers/mbox/remote/CMakeLists.txt

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
#
# Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
#
# SPDX-License-Identifier: Apache-2.0
#
cmake_minimum_required(VERSION 3.20.0)
if("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpunet")
message(INFO " ${BOARD} compile as remote in this sample")
else()
message(FATAL_ERROR "${BOARD} is not supported for this sample")
endif()
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(mbox_ipc_remote)
target_sources(app PRIVATE src/main.c)

1
samples/drivers/mbox/remote/boards/nrf5340dk_nrf5340_cpunet.conf

@ -0,0 +1 @@ @@ -0,0 +1 @@
CONFIG_MBOX_NRFX=y

18
samples/drivers/mbox/remote/boards/nrf5340dk_nrf5340_cpunet.overlay

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
/*
* Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
soc {
mbox: mbox@41012000 {
compatible = "nordic,mbox-nrf-ipc";
reg = <0x41012000 0x1000>;
tx-mask = <0x0000ffff>;
rx-mask = <0x0000ffff>;
interrupts = <18 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay";
};
};
};

2
samples/drivers/mbox/remote/prj.conf

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
CONFIG_STDOUT_CONSOLE=n
CONFIG_MBOX=y

52
samples/drivers/mbox/remote/src/main.c

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
/*
* Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <stdlib.h>
#include <zephyr.h>
#include <drivers/mbox.h>
#define TX_ID (0)
#define RX_ID (1)
static void callback(const struct device *dev, uint32_t channel,
void *user_data, struct mbox_msg *data)
{
printk("Pong (on channel %d)\n", channel);
}
void main(void)
{
struct mbox_channel tx_channel;
struct mbox_channel rx_channel;
const struct device *dev;
printk("Hello from NET\n");
dev = DEVICE_DT_GET(DT_NODELABEL(mbox));
mbox_init_channel(&tx_channel, dev, TX_ID);
mbox_init_channel(&rx_channel, dev, RX_ID);
if (mbox_set_enabled(&rx_channel, 1)) {
printk("mbox_set_enable() error\n");
return;
}
mbox_register_callback(&rx_channel, callback, NULL);
while (1) {
printk("Ping (on channel %d)\n", tx_channel.id);
if (mbox_send(&tx_channel, NULL) < 0) {
printk("mbox_send() error\n");
return;
}
k_sleep(K_MSEC(3000));
}
}

9
samples/drivers/mbox/sample.yaml

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
sample:
name: MBOX IPC sample
tests:
sample.drivers.mbox:
platform_allow: nrf5340dk_nrf5340_cpuapp
integration_platforms:
- nrf5340dk_nrf5340_cpuapp
tags: mbox
build_only: true

51
samples/drivers/mbox/src/main.c

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
/*
* Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <stdlib.h>
#include <zephyr.h>
#include <drivers/mbox.h>
#define TX_ID (1)
#define RX_ID (0)
static void callback(const struct device *dev, uint32_t channel,
void *user_data, struct mbox_msg *data)
{
printk("Pong (on channel %d)\n", channel);
}
void main(void)
{
struct mbox_channel tx_channel;
struct mbox_channel rx_channel;
const struct device *dev;
printk("Hello from APP\n");
dev = DEVICE_DT_GET(DT_NODELABEL(mbox));
mbox_init_channel(&tx_channel, dev, TX_ID);
mbox_init_channel(&rx_channel, dev, RX_ID);
if (mbox_set_enabled(&rx_channel, 1)) {
printk("mbox_set_enable() error\n");
return;
}
mbox_register_callback(&rx_channel, callback, NULL);
while (1) {
k_sleep(K_MSEC(2000));
printk("Ping (on channel %d)\n", tx_channel.id);
if (mbox_send(&tx_channel, NULL) < 0) {
printk("mbox_send() error\n");
return;
}
}
}
Loading…
Cancel
Save