Skip to content

Commit f26b0d0

Browse files
Hubert MiśPiotr Szkotak
andcommitted
ipc: RPMsg service to register multiple endpoints
This patch implements a service that adds multiendpoint capabilities to RPMsg. Multiple endpoints are intended to be used when multiple modules need services from a remote processor. Each module may register one or more RPMsg endpoints. The implementation separates backend from the service, what allows to extend this module to support other topologies like Linux <-> Zephyr. Co-authored-by: Piotr Szkotak <[email protected]> Signed-off-by: Hubert Miś <[email protected]>
1 parent dbf9d99 commit f26b0d0

File tree

11 files changed

+726
-0
lines changed

11 files changed

+726
-0
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@
552552
/subsys/fs/fuse_fs_access.c @vanwinkeljan
553553
/subsys/fs/littlefs_fs.c @pabigot
554554
/subsys/fs/nvs/ @Laczen
555+
/subsys/ipc/ @ioannisg
555556
/subsys/logging/ @nordic-krch
556557
/subsys/logging/log_backend_net.c @nordic-krch @jukkar
557558
/subsys/lorawan/ @Mani-Sadhasivam

include/ipc/rpmsg_service.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2020 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_RPMSG_SERVICE_RPMSG_SERVICE_H_
8+
#define ZEPHYR_INCLUDE_RPMSG_SERVICE_RPMSG_SERVICE_H_
9+
10+
#include <openamp/open_amp.h>
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
/**
17+
* @brief RPMsg service API
18+
* @defgroup rpmsg_service_api RPMsg service APIs
19+
* @{
20+
*/
21+
22+
/**
23+
* @brief Register IPC endpoint
24+
*
25+
* Registers IPC endpoint to enable communication with a remote device.
26+
* The endpoint is created when the slave device registers it.
27+
*
28+
* The same function registers endpoints for both master and slave devices.
29+
*
30+
* @param name String containing the name of the endpoint. Must be identical
31+
* for master and slave
32+
* @param cb Callback executed when data are available on given endpoint
33+
*
34+
* @retval >=0 id of registered endpoint on success;
35+
* @retval -EINPROGRESS when requested to register an endpoint after endpoints
36+
* creation procedure has started;
37+
* @retval -ENOMEM when there is not enough slots to register the endpoint;
38+
* @retval <0 an other negative errno code, reported by rpmsg.
39+
*/
40+
int rpmsg_service_register_endpoint(const char *name, rpmsg_ept_cb cb);
41+
42+
/**
43+
* @brief Send data using given IPC endpoint
44+
*
45+
* @param endpoint_id Id of registered endpoint, obtained by
46+
* @ref rpmsg_service_register_endpoint
47+
* @param data Pointer to the buffer to send through RPMsg service
48+
* @param len Number of bytes to send.
49+
*
50+
* @retval >=0 number of sent bytes;
51+
* @retval <0 an error code, reported by rpmsg.
52+
*/
53+
int rpmsg_service_send(int endpoint_id, const void *data, size_t len);
54+
55+
/**
56+
* @brief Check if endpoint is bound.
57+
*
58+
* Checks if remote endpoint has been created
59+
* and the master has bound its endpoint to it.
60+
*
61+
* @param endpoint_id Id of registered endpoint, obtained by
62+
* @ref rpmsg_service_register_endpoint
63+
*
64+
* @retval true endpoint is bound
65+
* @retval false endpoint not bound
66+
*/
67+
bool rpmsg_service_endpoint_is_bound(int endpoint_id);
68+
69+
/**
70+
* @}
71+
*/
72+
73+
74+
#ifdef __cplusplus
75+
}
76+
#endif
77+
78+
#endif /* ZEPHYR_INCLUDE_RPMSG_SERVICE_RPMSG_SERVICE_H_ */

subsys/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_subdirectory_ifdef(CONFIG_CPLUSPLUS cpp)
1010
add_subdirectory_ifdef(CONFIG_DISK_ACCESS disk)
1111
add_subdirectory_ifdef(CONFIG_EMUL emul)
1212
add_subdirectory(fs)
13+
add_subdirectory(ipc)
1314
add_subdirectory(mgmt)
1415
add_subdirectory_ifdef(CONFIG_MCUBOOT_IMG_MANAGER dfu)
1516
add_subdirectory_ifdef(CONFIG_NET_BUF net)

subsys/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Subsystem configuration options
22

33
# Copyright (c) 2016-2017 Intel Corporation
4+
# Copyright (c) 2021 Nordic Semiconductor
45
# SPDX-License-Identifier: Apache-2.0
56

67
menu "Sub Systems and OS Services"
@@ -23,6 +24,8 @@ source "subsys/fb/Kconfig"
2324

2425
source "subsys/fs/Kconfig"
2526

27+
source "subsys/ipc/Kconfig"
28+
2629
source "subsys/jwt/Kconfig"
2730

2831
source "subsys/logging/Kconfig"

subsys/ipc/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
add_subdirectory_ifdef(CONFIG_RPMSG_SERVICE rpmsg_service)

subsys/ipc/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# IPC subsystem configuration options
2+
3+
# Copyright (c) 2021 Nordic Semiconductor
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
menu "Inter Processor Communication"
7+
8+
source "subsys/ipc/rpmsg_service/Kconfig"
9+
10+
endmenu
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
zephyr_sources(rpmsg_backend.c)
4+
zephyr_sources(rpmsg_service.c)

subsys/ipc/rpmsg_service/Kconfig

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Copyright (c) 2020-2021 Nordic Semiconductor (ASA)
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Workaround for not being able to have commas in macro arguments
5+
DT_CHOSEN_Z_IPC_SHM := zephyr,ipc_shm
6+
DT_CHOSEN_Z_IPC := zephyr,ipc
7+
DT_CHOSEN_Z_IPC_TX := zephyr,ipc_tx
8+
DT_CHOSEN_Z_IPC_RX := zephyr,ipc_rx
9+
10+
config RPMSG_SERVICE_SINGLE_IPM_SUPPORT
11+
bool
12+
default $(dt_chosen_enabled,$(DT_CHOSEN_Z_IPC))
13+
help
14+
This option must be selected when single IPM is used for
15+
both TX and RX communication
16+
17+
config RPMSG_SERVICE_DUAL_IPM_SUPPORT
18+
bool
19+
default $(dt_chosen_enabled,$(DT_CHOSEN_Z_IPC_TX)) && \
20+
$(dt_chosen_enabled,$(DT_CHOSEN_Z_IPC_RX))
21+
help
22+
This option must be selected when separate IPMs are used for
23+
TX and RX communication
24+
25+
menuconfig RPMSG_SERVICE
26+
bool "RPMsg service for multiple users"
27+
select IPM
28+
select OPENAMP
29+
help
30+
Enables support for a service that can be shared by multiple
31+
users to establish RPMsg endpoints for given channel.
32+
33+
if RPMSG_SERVICE
34+
35+
config RPMSG_SERVICE_SHM_BASE_ADDRESS
36+
hex
37+
default "$(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_IPC_SHM))"
38+
help
39+
This option specifies base address of the memory region to
40+
be used for the OpenAMP IPC shared memory
41+
42+
config RPMSG_SERVICE_SHM_SIZE
43+
hex
44+
default "$(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_IPC_SHM))"
45+
help
46+
This option specifies size of the memory region to be used
47+
for the OpenAMP IPC shared memory
48+
49+
if RPMSG_SERVICE_SINGLE_IPM_SUPPORT
50+
51+
config RPMSG_SERVICE_IPM_NAME
52+
string
53+
default "$(dt_chosen_label,$(DT_CHOSEN_Z_IPC))"
54+
help
55+
This option specifies the IPM device name to be used
56+
57+
endif # RPMSG_SERVICE_SINGLE_IPM_SUPPORT
58+
59+
if RPMSG_SERVICE_DUAL_IPM_SUPPORT
60+
61+
config RPMSG_SERVICE_IPM_TX_NAME
62+
string
63+
default "$(dt_chosen_label,$(DT_CHOSEN_Z_IPC_TX))"
64+
help
65+
This option specifies the IPM device name to be used for
66+
TX communication
67+
68+
config RPMSG_SERVICE_IPM_RX_NAME
69+
string
70+
default "$(dt_chosen_label,$(DT_CHOSEN_Z_IPC_RX))"
71+
help
72+
This option specifies the IPM device name to be used for
73+
RX communication
74+
75+
endif # RPMSG_SERVICE_DUAL_IPM_SUPPORT
76+
77+
choice RPMSG_SERVICE_MODE
78+
prompt "RPMsg Service mode"
79+
80+
config RPMSG_SERVICE_MODE_MASTER
81+
bool "RPMsg master"
82+
select OPENAMP_MASTER
83+
84+
config RPMSG_SERVICE_MODE_REMOTE
85+
bool "RPMsg remote"
86+
select OPENAMP_SLAVE
87+
88+
endchoice
89+
90+
config RPMSG_SERVICE_NUM_ENDPOINTS
91+
int "Max number of registered endpoints"
92+
default 2
93+
help
94+
Maximal number of endpoints that can be registered for given
95+
RPMsg service.
96+
97+
config RPMSG_SERVICE_WORK_QUEUE_STACK_SIZE
98+
int "Size of RX work queue stack"
99+
default 2048
100+
help
101+
Size of stack used by work queue RX thread. This work queue is
102+
created in the RPMsg Service backend module to prevent notifying
103+
service users about received data from the system work queue.
104+
105+
config RPMSG_SERVICE_INIT_PRIORITY
106+
int "Initialization priority of RPMsg service"
107+
default 48
108+
help
109+
The order of RPMsg Service initialization and endpoints registration
110+
is important to avoid race conditions in RPMsg endpoints handshake.
111+
112+
If in doubt, do not modify this value.
113+
114+
config RPMSG_SERVICE_EP_REG_PRIORITY
115+
int "Initialization priority of modules registering RPMsg endpoints"
116+
default 47
117+
help
118+
The endpoints must be registered before RPMsg Service is initialized.
119+
120+
If in doubt, do not modify this value.
121+
122+
endif # RPMSG_SERVICE

0 commit comments

Comments
 (0)