Skip to content

Commit 742f55a

Browse files
Karl Zhanggalak
Karl Zhang
authored andcommitted
samples: openamp: Remove exclusive compile of openAMP
Add configuable shared memory address for openAMP samples. There is a plan to add more platforms supported for openAMP in zephyr. Each platform can specify the shared memory address and device by device tree and add it's support in openAMP samples. Signed-off-by: Karl Zhang <[email protected]> Signed-off-by: Kumar Gala <[email protected]>
1 parent ccba01f commit 742f55a

File tree

8 files changed

+116
-21
lines changed

8 files changed

+116
-21
lines changed
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
cmake_minimum_required(VERSION 3.13.1)
22
# Copyright (c) 2018 Nordic Semiconductor ASA
3+
# Copyright (c) 2019 Linaro Limited
34
#
45
# SPDX-License-Identifier: Apache-2.0
56
#
6-
set(BOARD lpcxpresso54114_m4)
7+
8+
if("${BOARD}" STREQUAL "lpcxpresso54114_m4")
9+
set(BOARD_REMOTE "lpcxpresso54114_m0")
10+
else()
11+
message(FATAL_ERROR "${BOARD} was not supported for this sample")
12+
endif()
13+
14+
message(INFO " ${BOARD} compile as Master in this sample")
715

816
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
917
project(openamp)
1018

11-
if(NOT ("${BOARD}" STREQUAL "lpcxpresso54114_m4"))
12-
message(FATAL_ERROR "${BOARD} was specified, but this sample only supports lpcxpresso54114_m4")
13-
endif()
14-
1519
enable_language(C ASM)
1620

1721
target_sources(app PRIVATE src/main.c)
@@ -22,10 +26,15 @@ ExternalProject_Add(
2226
openamp_remote
2327
SOURCE_DIR ${APPLICATION_SOURCE_DIR}/remote
2428
INSTALL_COMMAND "" # This particular build system has no install command
29+
CMAKE_CACHE_ARGS -DBOARD:string=${BOARD_REMOTE}
30+
CMAKE_CACHE_ARGS -DDTC_OVERLAY_FILE:string=${DTC_OVERLAY_FILE}
2531
BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/openamp_remote-prefix/src/openamp_remote-build/zephyr/zephyr.bin"
2632
# NB: Do we need to pass on more CMake variables?
2733
BUILD_ALWAYS True
2834
)
29-
add_dependencies(core_m0_inc_target openamp_remote)
35+
36+
if(("${BOARD}" STREQUAL "lpcxpresso54114_m4"))
37+
add_dependencies(core_m0_inc_target openamp_remote)
38+
endif()
3039

3140
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

samples/subsys/ipc/openamp/Kconfig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Private config options for openamp sample app
2+
3+
# Copyright (c) 2020 Linaro Limited
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Workaround for not being able to have commas in macro arguments
7+
DT_CHOSEN_Z_IPC_SHM := zephyr,ipc_shm
8+
DT_CHOSEN_Z_IPC := zephyr,ipc
9+
10+
config OPENAMP_IPC_SHM_BASE_ADDRESS
11+
hex
12+
default "$(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_IPC_SHM))"
13+
help
14+
This option specifies base address of the memory region to
15+
be used for the OpenAMP IPC shared memory
16+
17+
config OPENAMP_IPC_SHM_SIZE
18+
hex
19+
default "$(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_IPC_SHM))"
20+
help
21+
This option specifies size of the memory region to be used
22+
for the OpenAMP IPC shared memory
23+
24+
config OPENAMP_IPC_DEV_NAME
25+
string
26+
default "$(dt_chosen_label,$(DT_CHOSEN_Z_IPC))"
27+
help
28+
This option specifies the device name for the IPC device to be used
29+
30+
source "Kconfig.zephyr"

samples/subsys/ipc/openamp/common.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
/*
22
* Copyright (c) 2018 Nordic Semiconductor ASA
3-
* Copyright (c) 2018 Linaro Limited
3+
* Copyright (c) 2018-2019 Linaro Limited
44
*
55
* SPDX-License-Identifier: Apache-2.0
66
*/
77

88
#ifndef COMMON_H__
99
#define COMMON_H__
1010

11-
#define SHM_START_ADDR 0x04000400
12-
#define SHM_SIZE 0x7c00
11+
#define VDEV_START_ADDR CONFIG_OPENAMP_IPC_SHM_BASE_ADDRESS
12+
#define VDEV_SIZE CONFIG_OPENAMP_IPC_SHM_SIZE
13+
14+
#define VDEV_STATUS_ADDR VDEV_START_ADDR
15+
#define VDEV_STATUS_SIZE 0x400
16+
17+
#define SHM_START_ADDR (VDEV_START_ADDR + VDEV_STATUS_SIZE)
18+
#define SHM_SIZE (VDEV_SIZE - VDEV_STATUS_SIZE)
1319
#define SHM_DEVICE_NAME "sramx.shm"
1420

1521
#define VRING_COUNT 2
16-
#define VRING_RX_ADDRESS 0x04007800
17-
#define VRING_TX_ADDRESS 0x04007C00
22+
#define VRING_RX_ADDRESS (VDEV_START_ADDR + SHM_SIZE - VDEV_STATUS_SIZE)
23+
#define VRING_TX_ADDRESS (VDEV_START_ADDR + SHM_SIZE)
1824
#define VRING_ALIGNMENT 4
1925
#define VRING_SIZE 16
2026

21-
#define VDEV_STATUS_ADDR 0x04000000
2227

2328
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2019 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
chosen {
9+
/*
10+
* shared memory reserved for the inter-processor communication
11+
*/
12+
zephyr,ipc_shm = &sramx1;
13+
zephyr,ipc = &mailbox0;
14+
};
15+
16+
sramx1:memory@4000000{
17+
compatible = "mmio-sram";
18+
reg = <0x4000000 0x8000>;
19+
};
20+
};
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
cmake_minimum_required(VERSION 3.13.1)
22
# Copyright (c) 2018 Nordic Semiconductor ASA
3+
# Copyright (c) 2019 Linaro Limited
34
#
45
# SPDX-License-Identifier: Apache-2.0
56
#
6-
set(BOARD lpcxpresso54114_m0)
7+
if(("${BOARD}" STREQUAL "lpcxpresso54114_m0"))
8+
message(INFO " ${BOARD} compile as slave in this sample")
9+
else()
10+
message(FATAL_ERROR "${BOARD} was not supported for this sample")
11+
endif()
712

813
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
914
project(openamp_remote)
1015

11-
if(NOT ("${BOARD}" STREQUAL "lpcxpresso54114_m0"))
12-
message(FATAL_ERROR "${BOARD} was specified, but this sample only supports lpcxpresso54114_m0")
13-
endif()
14-
1516
target_sources(app PRIVATE src/main.c)
1617
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Private config options for openamp sample app
2+
3+
# Copyright (c) 2020 Linaro Limited
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Workaround for not being able to have commas in macro arguments
7+
DT_CHOSEN_Z_IPC_SHM := zephyr,ipc_shm
8+
DT_CHOSEN_Z_IPC := zephyr,ipc
9+
10+
config OPENAMP_IPC_SHM_BASE_ADDRESS
11+
hex
12+
default "$(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_IPC_SHM))"
13+
help
14+
This option specifies base address of the memory region to
15+
be used for the OpenAMP IPC shared memory
16+
17+
config OPENAMP_IPC_SHM_SIZE
18+
hex
19+
default "$(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_IPC_SHM))"
20+
help
21+
This option specifies size of the memory region to be used
22+
for the OpenAMP IPC shared memory
23+
24+
config OPENAMP_IPC_DEV_NAME
25+
string
26+
default "$(dt_chosen_label,$(DT_CHOSEN_Z_IPC))"
27+
help
28+
This option specifies the device name for the IPC device to be used
29+
30+
source "Kconfig.zephyr"

samples/subsys/ipc/openamp/remote/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (c) 2018, NXP
33
* Copyright (c) 2018, Nordic Semiconductor ASA
4-
* Copyright (c) 2018, Linaro Limited
4+
* Copyright (c) 2018-2019, Linaro Limited
55
*
66
* SPDX-License-Identifier: Apache-2.0
77
*/
@@ -168,7 +168,7 @@ void app_task(void *arg1, void *arg2, void *arg3)
168168
}
169169

170170
/* setup IPM */
171-
ipm_handle = device_get_binding("MAILBOX_0");
171+
ipm_handle = device_get_binding(CONFIG_OPENAMP_IPC_DEV_NAME);
172172
if (ipm_handle == NULL) {
173173
printk("device_get_binding failed to find device\n");
174174
return;

samples/subsys/ipc/openamp/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (c) 2018, NXP
33
* Copyright (c) 2018, Nordic Semiconductor ASA
4-
* Copyright (c) 2018, Linaro Limited
4+
* Copyright (c) 2018-2019, Linaro Limited
55
*
66
* SPDX-License-Identifier: Apache-2.0
77
*/
@@ -192,7 +192,7 @@ void app_task(void *arg1, void *arg2, void *arg3)
192192
}
193193

194194
/* setup IPM */
195-
ipm_handle = device_get_binding("MAILBOX_0");
195+
ipm_handle = device_get_binding(CONFIG_OPENAMP_IPC_DEV_NAME);
196196
if (ipm_handle == NULL) {
197197
printk("device_get_binding failed to find device\n");
198198
return;

0 commit comments

Comments
 (0)