|
| 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_ */ |
0 commit comments