|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * @file nrf_modem_os_rpc.h |
| 9 | + * |
| 10 | + * @brief RPC transport glue. |
| 11 | + * |
| 12 | + * @defgroup nrf_modem_os_rpc Modem Library RPC transport glue |
| 13 | + * @{ |
| 14 | + */ |
| 15 | +#ifndef NRF_MODEM_OS_RPC_H__ |
| 16 | +#define NRF_MODEM_OS_RPC_H__ |
| 17 | + |
| 18 | +#include <stdbool.h> |
| 19 | +#include <stddef.h> |
| 20 | +#include <stdint.h> |
| 21 | + |
| 22 | +#ifdef __cplusplus |
| 23 | +extern "C" { |
| 24 | +#endif |
| 25 | + |
| 26 | +typedef void (*nrf_modem_os_rpc_signal_cb_t)(uint32_t ch, void *priv); |
| 27 | + |
| 28 | +/** |
| 29 | + * @brief Parameters for configuring an nrf_modem rpc instance. |
| 30 | + * |
| 31 | + * Passed when invoking @c nrf_modem_os_rpc_open. |
| 32 | + */ |
| 33 | +struct nrf_modem_os_rpc_config { |
| 34 | + struct { |
| 35 | + /** Remote signal device. */ |
| 36 | + uintptr_t sigdev; |
| 37 | + /** TX channel number. */ |
| 38 | + uint32_t ch; |
| 39 | + /** TX shared memory start address. */ |
| 40 | + uintptr_t addr; |
| 41 | + /** TX shared memory size. */ |
| 42 | + size_t size; |
| 43 | + } tx; |
| 44 | + struct { |
| 45 | + /** Local signal device. */ |
| 46 | + uintptr_t sigdev; |
| 47 | + /** RX channel number. */ |
| 48 | + uint32_t ch; |
| 49 | + /** RX shared memory start address. */ |
| 50 | + uintptr_t addr; |
| 51 | + /** RX shared memory size. */ |
| 52 | + size_t size; |
| 53 | + } rx; |
| 54 | + struct { |
| 55 | + /** Pointer to private context passed as an argument to callbacks. */ |
| 56 | + void *priv; |
| 57 | + /** |
| 58 | + * @brief Bind was successful. |
| 59 | + * |
| 60 | + * Invoked when the local and remote rpc endpoints |
| 61 | + * have bound successfully. |
| 62 | + * |
| 63 | + * @param priv Private user data. |
| 64 | + */ |
| 65 | + void (*bound)(void *priv); |
| 66 | + /** |
| 67 | + * @brief New message has arrived. |
| 68 | + * |
| 69 | + * Invoked when new data is received. |
| 70 | + * |
| 71 | + * @param data Pointer to data buffer. |
| 72 | + * @param len Length of @a data. |
| 73 | + * @param priv Private user data. |
| 74 | + */ |
| 75 | + void (*received)(const void *data, size_t len, void *priv); |
| 76 | + } cb; |
| 77 | +}; |
| 78 | + |
| 79 | +/** |
| 80 | + * @brief Parameters for configuring an nrf_modem signaling instance. |
| 81 | + * |
| 82 | + * Passed when invoking @c nrf_modem_os_rpc_signal_init. |
| 83 | + */ |
| 84 | +struct nrf_modem_os_rpc_signal_config { |
| 85 | + /** Signal device. */ |
| 86 | + uintptr_t sigdev; |
| 87 | + /** Channel number. */ |
| 88 | + uint32_t ch; |
| 89 | + /** Pointer to private context passed as an argument to callbacks. */ |
| 90 | + void *priv; |
| 91 | + /** Invoked when signal with channel num @a ch is raised. |
| 92 | + * See @c nrf_modem_os_rpc_signal_cb_t. |
| 93 | + */ |
| 94 | + nrf_modem_os_rpc_signal_cb_t recv; |
| 95 | +}; |
| 96 | + |
| 97 | +/** |
| 98 | + * @brief RPC instance declaration used internally in nrf_modem. |
| 99 | + * |
| 100 | + * This structure must be defined in the glue. |
| 101 | + */ |
| 102 | +struct nrf_modem_os_rpc; |
| 103 | + |
| 104 | +/** |
| 105 | + * @brief Signaling instance declaration used internally in nrf_modem. |
| 106 | + * |
| 107 | + * This structure must be defined in the glue. |
| 108 | + */ |
| 109 | +struct nrf_modem_os_rpc_signal; |
| 110 | + |
| 111 | +/** |
| 112 | + * @brief RPC instances used by nrf_modem and defined externally. |
| 113 | + */ |
| 114 | +extern struct nrf_modem_os_rpc inst_ctrl; |
| 115 | +extern struct nrf_modem_os_rpc inst_data; |
| 116 | + |
| 117 | +/** |
| 118 | + * @brief Signaling instances used by nrf_modem and defined externally. |
| 119 | + */ |
| 120 | +extern struct nrf_modem_os_rpc_signal inst_app_fault; |
| 121 | +extern struct nrf_modem_os_rpc_signal inst_modem_fault; |
| 122 | +extern struct nrf_modem_os_rpc_signal inst_modem_sysoff; |
| 123 | + |
| 124 | +/** |
| 125 | + * @brief Get address of the application signal device. |
| 126 | + * |
| 127 | + * @return Address of application signal device. |
| 128 | + */ |
| 129 | +uintptr_t nrf_modem_os_rpc_sigdev_app_get(void); |
| 130 | + |
| 131 | +/** |
| 132 | + * @brief Get address of the modem signal device. |
| 133 | + * |
| 134 | + * @return Address of modem signal device. |
| 135 | + */ |
| 136 | +uintptr_t nrf_modem_os_rpc_sigdev_modem_get(void); |
| 137 | + |
| 138 | +/** |
| 139 | + * @brief Open an RPC instance. |
| 140 | + * |
| 141 | + * @param instance Pointer to RPC instance. |
| 142 | + * @param conf Parameters for configuring the instance before it is opened. |
| 143 | + * |
| 144 | + * @return 0 on success, a negative errno otherwise. |
| 145 | + */ |
| 146 | +int nrf_modem_os_rpc_open(struct nrf_modem_os_rpc *instance, |
| 147 | + const struct nrf_modem_os_rpc_config *conf); |
| 148 | + |
| 149 | +/** |
| 150 | + * @brief Send a message with the RPC instance. |
| 151 | + * |
| 152 | + * @param instance Pointer to RPC instance. |
| 153 | + * @param msg Pointer to a buffer containing data to send. |
| 154 | + * @param len Size of data in the @p msg buffer. |
| 155 | + * |
| 156 | + * @retval 0 on success. |
| 157 | + * @retval -NRF_EBUSY when the instance is closed or handshaking. |
| 158 | + * @retval -NRF_ENOMEM when there are not enough memory in circular buffer. |
| 159 | + * @retval other errno codes from dependent modules. |
| 160 | + */ |
| 161 | +int nrf_modem_os_rpc_send(struct nrf_modem_os_rpc *instance, const void *msg, size_t len); |
| 162 | + |
| 163 | +/** |
| 164 | + * @brief Close an RPC instance. |
| 165 | + * |
| 166 | + * @param instance pointer to RPC instance. |
| 167 | + * |
| 168 | + * @return 0 on success, a negative errno otherwise. |
| 169 | + */ |
| 170 | +int nrf_modem_os_rpc_close(struct nrf_modem_os_rpc *instance); |
| 171 | + |
| 172 | +/** |
| 173 | + * @brief Suspend processing of incoming messages on the RPC instance. |
| 174 | + * |
| 175 | + * @param instance Pointer to RPC instance. |
| 176 | + * |
| 177 | + * @return 0 on success, a negative errno otherwise. |
| 178 | + */ |
| 179 | +int nrf_modem_os_rpc_rx_suspend(struct nrf_modem_os_rpc *instance); |
| 180 | + |
| 181 | +/** |
| 182 | + * @brief Resume processing of incoming messages on the RPC instance. |
| 183 | + * |
| 184 | + * @param instance Pointer to RPC instance. |
| 185 | + * |
| 186 | + * @return 0 on success, a negative errno otherwise. |
| 187 | + */ |
| 188 | +int nrf_modem_os_rpc_rx_resume(struct nrf_modem_os_rpc *instance); |
| 189 | + |
| 190 | +/** |
| 191 | + * @brief Configure and enable the signaling instance. |
| 192 | + * |
| 193 | + * @param instance Signaling instance. |
| 194 | + * @param conf Parameters for configuring the instance before it is enabled. |
| 195 | + * |
| 196 | + * @return 0 on success, a negative errno otherwise. |
| 197 | + */ |
| 198 | +int nrf_modem_os_rpc_signal_init(struct nrf_modem_os_rpc_signal *instance, |
| 199 | + struct nrf_modem_os_rpc_signal_config *conf); |
| 200 | + |
| 201 | +/** |
| 202 | + * @brief Signal with the signaling instance. |
| 203 | + * |
| 204 | + * @param instance Signaling instance. |
| 205 | + * |
| 206 | + * @return 0 on success, a negative errno otherwise. |
| 207 | + */ |
| 208 | +int nrf_modem_os_rpc_signal_send(struct nrf_modem_os_rpc_signal *instance); |
| 209 | + |
| 210 | +/** |
| 211 | + * @brief Disable the signaling instance. |
| 212 | + * |
| 213 | + * @param instance Signaling instance. |
| 214 | + * |
| 215 | + * @return 0 on success, a negative errno otherwise. |
| 216 | + */ |
| 217 | +int nrf_modem_os_rpc_signal_deinit(struct nrf_modem_os_rpc_signal *instance); |
| 218 | + |
| 219 | +/** |
| 220 | + * @brief Flush address range in cache. |
| 221 | + * |
| 222 | + * @param addr Starting address to flush. |
| 223 | + * @param size Range size. |
| 224 | + * |
| 225 | + * @return 0 on success, a negative errno otherwise. |
| 226 | + */ |
| 227 | +int nrf_modem_os_rpc_cache_data_flush(void *addr, size_t size); |
| 228 | + |
| 229 | +/** |
| 230 | + * @brief Invalidate address range in cache. |
| 231 | + * |
| 232 | + * @param addr Starting address to invalidate. |
| 233 | + * @param size Range size. |
| 234 | + * |
| 235 | + * @return 0 on success, a negative errno otherwise. |
| 236 | + */ |
| 237 | +int nrf_modem_os_rpc_cache_data_invalidate(void *addr, size_t size); |
| 238 | + |
| 239 | + |
| 240 | + |
| 241 | +#ifdef __cplusplus |
| 242 | +} |
| 243 | +#endif |
| 244 | + |
| 245 | +#endif /* NRF_MODEM_OS_RPC_H__ */ |
| 246 | +/** @} */ |
0 commit comments