1 /*
2 * Copyright (c) 2019 - 2025, Nordic Semiconductor ASA
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33 #ifndef NRFX_IPC_H__
34 #define NRFX_IPC_H__
35
36 #include <nrfx.h>
37 #include <hal/nrf_ipc.h>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /**
44 * @defgroup nrfx_ipc IPC driver
45 * @{
46 * @ingroup nrf_ipc
47 * @brief Interprocessor Communication (IPC) peripheral driver.
48 */
49
50 /**
51 * @brief IPC driver handler type.
52 *
53 * @param[in] event_idx IPC event index.
54 * @param[in] p_context Context passed to the interrupt handler, set on initialization.
55 */
56 typedef void (*nrfx_ipc_handler_t)(uint8_t event_idx, void * p_context);
57
58 /** @brief IPC configuration structure. */
59 typedef struct
60 {
61 uint32_t send_task_config[IPC_CONF_NUM]; ///< Configuration of the connection between signals and IPC channels.
62 uint32_t receive_event_config[IPC_CONF_NUM]; ///< Configuration of the connection between events and IPC channels.
63 uint32_t receive_events_enabled; ///< Bitmask with events to be enabled to generate interrupt.
64 } nrfx_ipc_config_t;
65
66 /**
67 * @brief Function for initializing the IPC driver.
68 *
69 * @param irq_priority Interrupt priority.
70 * @param handler Event handler provided by the user.
71 * Must not be NULL.
72 * @param p_context Context passed to event handler.
73 *
74 * @retval NRFX_SUCCESS Initialization was successful.
75 * @retval NRFX_ERROR_ALREADY Driver is already initialized.
76 */
77 nrfx_err_t nrfx_ipc_init(uint8_t irq_priority, nrfx_ipc_handler_t handler, void * p_context);
78
79 /**
80 * @brief Function for loading configuration directly into IPC peripheral.
81 *
82 * @param p_config Pointer to the structure with the initial configuration.
83 */
84 void nrfx_ipc_config_load(nrfx_ipc_config_t const * p_config);
85
86 /**
87 * @brief Function for convey signal on configured channels.
88 *
89 * Events connected to the IPC channels configured within this signal will
90 * be set and can generate interrupts when configured.
91 *
92 * @param send_index Index of the SEND task to trigger.
93 */
94 NRFX_STATIC_INLINE void nrfx_ipc_signal(uint8_t send_index);
95
96 /**
97 * @brief Function for storing data in the general purpose memory register.
98 *
99 * @param mem_index Index of the memory cell.
100 * @param data Data to be saved.
101 */
102 NRFX_STATIC_INLINE void nrfx_ipc_gpmem_set(uint8_t mem_index, uint32_t data);
103
104 /**
105 * @brief Function for getting data from the general purpose memory register.
106 *
107 * @param mem_index Index of the memory cell.
108 *
109 * @return Saved data.
110 */
111 NRFX_STATIC_INLINE uint32_t nrfx_ipc_gpmem_get(uint8_t mem_index);
112
113 /** @brief Function for uninitializing the IPC module. */
114 void nrfx_ipc_uninit(void);
115
116 /**
117 * @brief Function for checking if the IPC driver is initialized.
118 *
119 * @retval true Driver is already initialized.
120 * @retval false Driver is not initialized.
121 */
122 bool nrfx_ipc_init_check(void);
123
124 /**
125 * @brief Function for enabling events to generate interrupt.
126 *
127 * @param event_index Index of event to be enabled.
128 */
129 void nrfx_ipc_receive_event_enable(uint8_t event_index);
130
131 /**
132 * @brief Function for disabling events from generate interrupt.
133 *
134 * @param event_index Index of event to be disabled.
135 */
136 void nrfx_ipc_receive_event_disable(uint8_t event_index);
137
138 /**
139 * @brief Function for enabling set of events to generate interrupt.
140 *
141 * @param event_bitmask Bitmask with events to be enabled.
142 */
143 void nrfx_ipc_receive_event_group_enable(uint32_t event_bitmask);
144
145 /**
146 * @brief Function for disabling set of events from generate interrupt.
147 *
148 * @param event_bitmask Bitmask with events to be disabled.
149 */
150 void nrfx_ipc_receive_event_group_disable(uint32_t event_bitmask);
151
152 /**
153 * @brief Function for assigning event to the IPC channel.
154 *
155 * @param event_index Index of the event to be configured.
156 * @param channel_index Index of the channel to which event will be connected.
157 */
158 void nrfx_ipc_receive_event_channel_assign(uint8_t event_index, uint8_t channel_index);
159
160 /**
161 * @brief Function for assigning signal to the IPC channel.
162 *
163 * @param send_index Index of the signal to be configured.
164 * @param channel_index Index of the instance of channel.
165 */
166 void nrfx_ipc_send_task_channel_assign(uint8_t send_index, uint8_t channel_index);
167
168 /**
169 * @brief Function for assigning event to the IPC channels.
170 *
171 * @param event_index Index of the event to be configured.
172 * @param channel_bitmask Bitmask with channels to which event will be connected.
173 */
174 NRFX_STATIC_INLINE void nrfx_ipc_receive_config_set(uint8_t event_index, uint32_t channel_bitmask);
175
176 /**
177 * @brief Function for assigning signal to the IPC channels.
178 *
179 * @param send_index Index of the signal to be configured.
180 * @param channel_bitmask Bitmask with channels to which signal will be connected.
181 */
182 NRFX_STATIC_INLINE void nrfx_ipc_send_config_set(uint8_t send_index, uint32_t channel_bitmask);
183
184 /** @} */
185
186
187 #ifndef NRFX_DECLARE_ONLY
188
nrfx_ipc_gpmem_set(uint8_t mem_index,uint32_t data)189 NRFX_STATIC_INLINE void nrfx_ipc_gpmem_set(uint8_t mem_index, uint32_t data)
190 {
191 NRFX_ASSERT(mem_index < NRFX_ARRAY_SIZE(NRF_IPC->GPMEM));
192 nrf_ipc_gpmem_set(NRF_IPC, mem_index, data);
193 }
194
nrfx_ipc_gpmem_get(uint8_t mem_index)195 NRFX_STATIC_INLINE uint32_t nrfx_ipc_gpmem_get(uint8_t mem_index)
196 {
197 NRFX_ASSERT(mem_index < NRFX_ARRAY_SIZE(NRF_IPC->GPMEM));
198 return nrf_ipc_gpmem_get(NRF_IPC, mem_index);
199 }
200
nrfx_ipc_signal(uint8_t send_index)201 NRFX_STATIC_INLINE void nrfx_ipc_signal(uint8_t send_index)
202 {
203 NRFX_ASSERT(send_index < IPC_CONF_NUM);
204 nrf_ipc_task_trigger(NRF_IPC, nrf_ipc_send_task_get(send_index));
205 }
206
nrfx_ipc_receive_config_set(uint8_t event_index,uint32_t channel_bitmask)207 NRFX_STATIC_INLINE void nrfx_ipc_receive_config_set(uint8_t event_index, uint32_t channel_bitmask)
208 {
209 NRFX_ASSERT(event_index < IPC_CONF_NUM);
210 nrf_ipc_receive_config_set(NRF_IPC, event_index, channel_bitmask);
211 }
212
nrfx_ipc_send_config_set(uint8_t send_index,uint32_t channel_bitmask)213 NRFX_STATIC_INLINE void nrfx_ipc_send_config_set(uint8_t send_index, uint32_t channel_bitmask)
214 {
215 NRFX_ASSERT(send_index < IPC_CONF_NUM);
216 nrf_ipc_send_config_set(NRF_IPC, send_index, channel_bitmask);
217 }
218
219 #endif // NRFX_DECLARE_ONLY
220
221
222 void nrfx_ipc_irq_handler(void);
223
224
225 #ifdef __cplusplus
226 }
227 #endif
228
229 #endif // NRFX_IPC_H__
230