Skip to content

Commit b4cf9b8

Browse files
zbus: add IPC backend for multidomain communication
Implement IPC backend for ZBus multidomain communication, enabling message forwarding between domains over IPC connections. - IPC-spesific configuration structures - Integration with proxy agent framework via API structure and macros - Schedule ACK sending as work to avoid blocking in interrupt context The IPC backend uses Zephyr's IPC service for inter-core communication with async operation and proper endpoint binding using semaphore synchronization for reliable zbus message forwarding. Signed-off-by: Trond F. Christiansen <[email protected]>
1 parent 1ba1ec4 commit b4cf9b8

File tree

6 files changed

+386
-1
lines changed

6 files changed

+386
-1
lines changed

include/zephyr/zbus/multidomain/zbus_multidomain.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#if defined(CONFIG_ZBUS_MULTIDOMAIN_UART)
1818
#include <zephyr/zbus/multidomain/zbus_multidomain_uart.h>
1919
#endif
20+
#if defined(CONFIG_ZBUS_MULTIDOMAIN_IPC)
21+
#include <zephyr/zbus/multidomain/zbus_multidomain_ipc.h>
22+
#endif
2023

2124
#ifdef __cplusplus
2225
extern "C" {
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_ZBUS_MULTIDOMAIN_IPC_H_
8+
#define ZEPHYR_INCLUDE_ZBUS_MULTIDOMAIN_IPC_H_
9+
10+
#include <zephyr/zbus/zbus.h>
11+
#include <zephyr/device.h>
12+
#include <string.h>
13+
#include <zephyr/ipc/ipc_service.h>
14+
#include <zephyr/zbus/multidomain/zbus_multidomain_types.h>
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
/**
21+
* @brief Zbus Multi-domain API
22+
* @defgroup zbus_multidomain_apis Zbus Multi-domain APIs
23+
* @ingroup zbus_apis
24+
* @since 3.3.0
25+
* @version 1.0.0
26+
* @ingroup os_services
27+
* @{
28+
*/
29+
30+
/**
31+
* @brief Structure for IPC backend configuration.
32+
*/
33+
struct zbus_multidomain_ipc_config {
34+
/** IPC device */
35+
const struct device *dev;
36+
37+
/** IPC endpoint */
38+
struct ipc_ept ipc_ept;
39+
40+
/** IPC endpoint configuration */
41+
struct ipc_ept_cfg *ept_cfg;
42+
43+
/** Semaphore to signal when the IPC endpoint is bound */
44+
struct k_sem ept_bound_sem;
45+
46+
/** Callback function for received messages */
47+
int (*recv_cb)(const struct zbus_proxy_agent_msg *msg);
48+
49+
/** Callback function for ACKs */
50+
int (*ack_cb)(uint32_t msg_id, void *user_data);
51+
52+
/** User data for the ACK callback */
53+
void *ack_cb_user_data;
54+
55+
/** Work item for sending ACKs */
56+
struct k_work ack_work;
57+
58+
/** Message ID to ACK */
59+
uint32_t ack_msg_id;
60+
};
61+
62+
/** @cond INTERNAL_HIDDEN */
63+
64+
/* IPC backend API structure */
65+
extern const struct zbus_proxy_agent_api zbus_multidomain_ipc_api;
66+
67+
/**
68+
* @brief Macros to get the API and configuration for the IPC backend.
69+
*
70+
* These macros are used to retrieve the API and configuration for the IPC backend
71+
* of the proxy agent. The macros are used in "zbus_multidomain.h" to define the
72+
* backend specific configurations and API for the IPC type of proxy agent.
73+
*
74+
* @param _name The name of the proxy agent.
75+
*/
76+
#define _ZBUS_GET_API_ZBUS_MULTIDOMAIN_TYPE_IPC() &zbus_multidomain_ipc_api
77+
#define _ZBUS_GET_CONFIG_ZBUS_MULTIDOMAIN_TYPE_IPC(_name) (void *)&_name##_ipc_config
78+
79+
/**
80+
* @brief Macros to generate device specific backend configurations for the IPC type.
81+
*
82+
* This macro generates the backend specific configurations for the IPC type of
83+
* proxy agent. The macro is used in "zbus_multidomain.h" to create the
84+
* backend specific configurations for the IPC type of proxy agent.
85+
*
86+
* @param _name The name of the proxy agent.
87+
* @param _nodelabel The device node label for the IPC device.
88+
*/
89+
#define _ZBUS_GENERATE_BACKEND_CONFIG_ZBUS_MULTIDOMAIN_TYPE_IPC(_name, _nodelabel) \
90+
static struct ipc_ept_cfg _name##_ipc_ept_cfg = { \
91+
.name = "ipc_ept_" #_name, \
92+
}; \
93+
static struct zbus_multidomain_ipc_config _name##_ipc_config = { \
94+
.dev = DEVICE_DT_GET(DT_NODELABEL(_nodelabel)), \
95+
.ept_cfg = &_name##_ipc_ept_cfg, \
96+
}
97+
98+
/** @endcond */
99+
100+
/**
101+
* @}
102+
*/
103+
104+
#ifdef __cplusplus
105+
}
106+
#endif
107+
108+
#endif /* ZEPHYR_INCLUDE_ZBUS_MULTIDOMAIN_IPC_H_ */

include/zephyr/zbus/multidomain/zbus_multidomain_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ extern "C" {
3131
* Zbus setup. Each type corresponds to a different communication backend.
3232
*/
3333
enum zbus_multidomain_type {
34-
ZBUS_MULTIDOMAIN_TYPE_UART
34+
ZBUS_MULTIDOMAIN_TYPE_UART,
35+
ZBUS_MULTIDOMAIN_TYPE_IPC
3536
};
3637

3738
/**

subsys/zbus/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ if(CONFIG_ZBUS_MULTIDOMAIN_UART)
1616
zephyr_library_sources(multidomain/zbus_multidomain_uart.c)
1717
endif()
1818

19+
if(CONFIG_ZBUS_MULTIDOMAIN_IPC)
20+
zephyr_library_sources(multidomain/zbus_multidomain_ipc.c)
21+
endif()
22+
1923
zephyr_library_sources(zbus_iterable_sections.c)

subsys/zbus/multidomain/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ config ZBUS_MULTIDOMAIN_UART_BUF_COUNT
8585

8686
endif # ZBUS_MULTIDOMAIN_UART
8787

88+
config ZBUS_MULTIDOMAIN_IPC
89+
bool "ZBus multidomain IPC backend"
90+
depends on MBOX
91+
depends on IPC_SERVICE
92+
help
93+
Enables the ZBus multidomain IPC backend, allowing communication between domains over IPC.
94+
This feature is useful for systems that require inter-domain communication via IPC.
95+
8896
module = ZBUS_MULTIDOMAIN
8997
module-str = zbus_multidomain
9098
source "subsys/logging/Kconfig.template.log_config"

0 commit comments

Comments
 (0)