Skip to content

Commit ddf3eea

Browse files
zbus: add UART backend for multidomain communication
Implement UART backend for ZBus multidomain communication, enabling message forwarding between domains over UART connections. - UART-specific configuration structure with async buffers - Error handling and UART recovery mechanisms - Integration with proxy agent framework via API structure - Configurable buffer count for UART operations - Schedule ACK sending as work to avoid blocking RX callback The UART backend uses async UART APIs for non-blocking communication and implements proper buffer cycling for continuous reception. Signed-off-by: Trond F. Christiansen <[email protected]>
1 parent f3e3f87 commit ddf3eea

File tree

6 files changed

+442
-1
lines changed

6 files changed

+442
-1
lines changed

include/zephyr/zbus/multidomain/zbus_multidomain.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include <zephyr/zbus/zbus.h>
1515
#include <zephyr/zbus/multidomain/zbus_multidomain_types.h>
1616

17+
#if defined(CONFIG_ZBUS_MULTIDOMAIN_UART)
18+
#include <zephyr/zbus/multidomain/zbus_multidomain_uart.h>
19+
#endif
20+
1721
#ifdef __cplusplus
1822
extern "C" {
1923
#endif

include/zephyr/zbus/multidomain/zbus_multidomain_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extern "C" {
3131
* Zbus setup. Each type corresponds to a different communication backend.
3232
*/
3333
enum zbus_multidomain_type {
34+
ZBUS_MULTIDOMAIN_TYPE_UART
3435
};
3536

3637
/**
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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_UART_H_
8+
#define ZEPHYR_INCLUDE_ZBUS_MULTIDOMAIN_UART_H_
9+
10+
#include <zephyr/zbus/zbus.h>
11+
#include <zephyr/device.h>
12+
#include <string.h>
13+
#include <zephyr/drivers/uart.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+
struct zbus_multidomain_uart_config {
31+
/** UART device */
32+
const struct device *dev;
33+
34+
/** Asynchronous RX buffer */
35+
uint8_t async_rx_buf[CONFIG_ZBUS_MULTIDOMAIN_UART_BUF_COUNT]
36+
[sizeof(struct zbus_proxy_agent_msg)];
37+
38+
/** Index of the current async RX buffer */
39+
volatile uint8_t async_rx_buf_idx;
40+
41+
/** Semaphore to signal when TX is done */
42+
struct k_sem tx_busy_sem;
43+
44+
struct zbus_proxy_agent_msg tx_msg_copy;
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+
/* UART backend API structure */
65+
extern const struct zbus_proxy_agent_api zbus_multidomain_uart_api;
66+
67+
/**
68+
* @brief Macros to get the API and configuration for the UART backend.
69+
*
70+
* These macros are used to retrieve the API and configuration for the UART 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 UART type of proxy agent.
73+
*
74+
* @param _name The name of the proxy agent.
75+
*/
76+
#define _ZBUS_GET_API_ZBUS_MULTIDOMAIN_TYPE_UART() &zbus_multidomain_uart_api
77+
#define _ZBUS_GET_CONFIG_ZBUS_MULTIDOMAIN_TYPE_UART(_name) (void *)&_name##_uart_config
78+
79+
/**
80+
* @brief Macros to generate device specific backend configurations for the UART type.
81+
*
82+
* This macro generates the backend specific configurations for the UART type of
83+
* proxy agent. The macro is used in "zbus_multidomain.h" to create the
84+
* backend specific configurations for the UART type of proxy agent.
85+
*/
86+
#define _ZBUS_GENERATE_BACKEND_CONFIG_ZBUS_MULTIDOMAIN_TYPE_UART(_name, _nodelabel) \
87+
struct zbus_multidomain_uart_config _name##_uart_config = { \
88+
.dev = DEVICE_DT_GET(DT_NODELABEL(_nodelabel)), \
89+
.async_rx_buf = {{0}}, \
90+
.async_rx_buf_idx = 0, \
91+
}
92+
93+
/** @endcond */
94+
95+
/**
96+
* @}
97+
*/
98+
99+
#ifdef __cplusplus
100+
}
101+
#endif
102+
103+
#endif /* ZEPHYR_INCLUDE_ZBUS_MULTIDOMAIN_UART_H_ */

subsys/zbus/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ if(CONFIG_ZBUS_MULTIDOMAIN)
1212
zephyr_library_sources(multidomain/zbus_multidomain.c)
1313
endif()
1414

15+
if(CONFIG_ZBUS_MULTIDOMAIN_UART)
16+
zephyr_library_sources(multidomain/zbus_multidomain_uart.c)
17+
endif()
18+
1519
zephyr_library_sources(zbus_iterable_sections.c)

subsys/zbus/multidomain/Kconfig

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,27 @@ config ZBUS_MULTIDOMAIN_MAX_TRANSMIT_ATTEMPTS
6666
proxy agent. If an acknowledgment is not received after this many attempts, the message
6767
will be dropped. Setting this to 1 means no retransmissions will be attempted.
6868

69+
config ZBUS_MULTIDOMAIN_UART
70+
bool "ZBus multidomain UART backend"
71+
depends on UART_ASYNC_API
72+
help
73+
Enables the ZBus multidomain UART backend, allowing for ZBus between domains over UART.
74+
This feature is useful for systems that require inter-domain communication via UART.
75+
76+
if ZBUS_MULTIDOMAIN_UART
77+
78+
config ZBUS_MULTIDOMAIN_UART_BUF_COUNT
79+
int "ZBus multidomain UART buffer count"
80+
default 2
81+
range 2 128
82+
help
83+
Configures the number of buffers used for the ZBus multidomain UART backend.
84+
A minimum of 2 buffers is required for proper operation.
85+
86+
endif # ZBUS_MULTIDOMAIN_UART
87+
6988
module = ZBUS_MULTIDOMAIN
7089
module-str = zbus_multidomain
7190
source "subsys/logging/Kconfig.template.log_config"
7291

73-
endmenu # ZBus multidomain support
92+
endmenu # ZBus multidomain support

0 commit comments

Comments
 (0)