3737#include <nrfx.h>
3838#include <haly/nrfy_dppi.h>
3939
40+ /* On devices with single instance (with no ID) use instance 0. */
41+ #if defined(NRF_DPPIC ) && defined(NRFX_DPPI_ENABLED ) && !defined(NRFX_DPPI0_ENABLED )
42+ #define NRFX_DPPI0_ENABLED 1
43+ #endif
44+
4045/**
4146 * @defgroup nrfx_dppi DPPI allocator
4247 * @{
4348 * @ingroup nrf_dppi
4449 * @brief Distributed Programmable Peripheral Interconnect (DPPI) allocator.
4550 */
4651
52+ /** @brief Data structure of the Distributed programmable peripheral interconnect (DPPI) driver instance. */
53+ typedef struct
54+ {
55+ NRF_DPPIC_Type * p_reg ; ///< Pointer to a structure containing DPPIC registers.
56+ uint8_t drv_inst_idx ; ///< Index of the driver instance. For internal use only.
57+ } nrfx_dppi_t ;
58+
59+ #ifndef __NRFX_DOXYGEN__
60+ enum {
61+ /* List all enabled driver instances (in the format NRFX_\<instance_name\>_INST_IDX). */
62+ NRFX_INSTANCE_ENUM_LIST (DPPI )
63+ NRFX_DPPI_ENABLED_COUNT
64+ };
65+ #endif
66+
67+ /** @brief Macro for creating an instance of the DPPIC driver. */
68+ #define NRFX_DPPI_INSTANCE (id ) \
69+ { \
70+ .p_reg = NRFX_CONCAT(NRF_, DPPIC, id), \
71+ .drv_inst_idx = NRFX_CONCAT(NRFX_DPPI, id, _INST_IDX), \
72+ }
73+
4774#ifdef __cplusplus
4875extern "C" {
4976#endif
5077
51- /** @brief Function for freeing all allocated channels and groups. */
52- void nrfx_dppi_free (void );
78+ #if NRFX_API_VER_AT_LEAST (3 , 8 , 0 ) || defined(__NRFX_DOXYGEN__ )
79+
80+ /**
81+ * @brief Function for freeing all allocated channels and groups.
82+ *
83+ * @param[in] p_instance Pointer to the driver instance structure.
84+ */
85+ void nrfx_dppi_free (nrfx_dppi_t const * p_instance );
5386
5487/**
5588 * @brief Function for allocating a DPPI channel.
5689 * @details This function allocates the first unused DPPI channel.
5790 *
5891 * @note Function is thread safe as it uses @ref nrfx_flag32_alloc.
5992 *
60- * @param[out] p_channel Pointer to the DPPI channel number that has been allocated.
93+ * @param[in] p_instance Pointer to the driver instance structure.
94+ * @param[out] p_channel Pointer to the DPPI channel number that has been allocated.
6195 *
6296 * @retval NRFX_SUCCESS The channel was successfully allocated.
6397 * @retval NRFX_ERROR_NO_MEM There is no available channel to be used.
6498 */
65- nrfx_err_t nrfx_dppi_channel_alloc (uint8_t * p_channel );
99+ nrfx_err_t nrfx_dppi_channel_alloc (nrfx_dppi_t const * p_instance , uint8_t * p_channel );
66100
67101/**
68102 * @brief Function for freeing a DPPI channel.
@@ -71,125 +105,181 @@ nrfx_err_t nrfx_dppi_channel_alloc(uint8_t * p_channel);
71105 *
72106 * @note Function is thread safe as it uses @ref nrfx_flag32_free.
73107 *
74- * @param[in] channel DPPI channel to be freed.
108+ * @param[in] p_instance Pointer to the driver instance structure.
109+ * @param[in] channel DPPI channel to be freed.
75110 *
76111 * @retval NRFX_SUCCESS The channel was successfully freed.
77112 * @retval NRFX_ERROR_INVALID_PARAM The specified channel is not allocated.
78113 */
79- nrfx_err_t nrfx_dppi_channel_free (uint8_t channel );
114+ nrfx_err_t nrfx_dppi_channel_free (nrfx_dppi_t const * p_instance , uint8_t channel );
80115
81116/**
82117 * @brief Function for enabling a DPPI channel.
83118 *
84- * @param[in] channel DPPI channel to be enabled.
119+ * @param[in] p_instance Pointer to the driver instance structure.
120+ * @param[in] channel DPPI channel to be enabled.
85121 *
86122 * @retval NRFX_SUCCESS The channel was successfully enabled.
87123 * @retval NRFX_ERROR_INVALID_PARAM The specified channel is not allocated.
88124 */
89- nrfx_err_t nrfx_dppi_channel_enable (uint8_t channel );
125+ nrfx_err_t nrfx_dppi_channel_enable (nrfx_dppi_t const * p_instance , uint8_t channel );
90126
91127/**
92128 * @brief Function for disabling a DPPI channel.
93129 *
94130 * @note Disabling channel does not modify PUBLISH/SUBSCRIBE registers configured to use
95131 * that channel.
96132 *
97- * @param[in] channel DPPI channel to be disabled.
133+ * @param[in] p_instance Pointer to the driver instance structure.
134+ * @param[in] channel DPPI channel to be disabled.
98135 *
99136 * @retval NRFX_SUCCESS The channel was successfully disabled.
100137 * @retval NRFX_ERROR_INVALID_PARAM The specified channel is not allocated.
101138 */
102- nrfx_err_t nrfx_dppi_channel_disable (uint8_t channel );
139+ nrfx_err_t nrfx_dppi_channel_disable (nrfx_dppi_t const * p_instance , uint8_t channel );
103140
104141/**
105142 * @brief Function for allocating a DPPI channel group.
106143 * @details This function allocates the first unused DPPI group.
107144 *
108145 * @note Function is thread safe as it uses @ref nrfx_flag32_alloc.
109146 *
110- * @param[out] p_group Pointer to the DPPI channel group that has been allocated.
147+ * @param[in] p_instance Pointer to the driver instance structure.
148+ * @param[out] p_group Pointer to the DPPI channel group that has been allocated.
111149 *
112150 * @retval NRFX_SUCCESS The channel group was successfully allocated.
113151 * @retval NRFX_ERROR_NO_MEM There is no available channel group to be used.
114152 */
115- nrfx_err_t nrfx_dppi_group_alloc (nrf_dppi_channel_group_t * p_group );
153+ nrfx_err_t nrfx_dppi_group_alloc (nrfx_dppi_t const * p_instance ,
154+ nrf_dppi_channel_group_t * p_group );
116155
117156/**
118157 * @brief Function for freeing a DPPI channel group.
119158 * @details This function also disables the chosen group.
120159 *
121160 * @note Function is thread safe as it uses @ref nrfx_flag32_free.
122161 *
123- * @param[in] group DPPI channel group to be freed.
162+ * @param[in] p_instance Pointer to the driver instance structure.
163+ * @param[in] group DPPI channel group to be freed.
124164 *
125165 * @retval NRFX_SUCCESS The channel group was successfully freed.
126166 * @retval NRFX_ERROR_INVALID_PARAM The specified group is not allocated.
127167 */
128- nrfx_err_t nrfx_dppi_group_free (nrf_dppi_channel_group_t group );
168+ nrfx_err_t nrfx_dppi_group_free (nrfx_dppi_t const * p_instance , nrf_dppi_channel_group_t group );
129169
130170/**
131171 * @brief Function for including a DPPI channel in a channel group.
132172 *
133- * @param[in] channel DPPI channel to be added.
134- * @param[in] group Channel group in which to include the channel.
173+ * @param[in] p_instance Pointer to the driver instance structure.
174+ * @param[in] channel DPPI channel to be added.
175+ * @param[in] group Channel group in which to include the channel.
135176 *
136177 * @warning Channel group configuration can be modified only if subscriptions for tasks
137178 * associated with this group are disabled.
138179 *
139180 * @retval NRFX_SUCCESS The channel was successfully included.
140181 * @retval NRFX_ERROR_INVALID_PARAM The specified group or channel is not allocated.
141182 */
142- nrfx_err_t nrfx_dppi_channel_include_in_group (uint8_t channel ,
183+ nrfx_err_t nrfx_dppi_channel_include_in_group (nrfx_dppi_t const * p_instance ,
184+ uint8_t channel ,
143185 nrf_dppi_channel_group_t group );
144186
145187/**
146188 * @brief Function for removing a DPPI channel from a channel group.
147189 *
148- * @param[in] channel DPPI channel to be removed.
149- * @param[in] group Channel group from which to remove the channel.
190+ * @param[in] p_instance Pointer to the driver instance structure.
191+ * @param[in] channel DPPI channel to be removed.
192+ * @param[in] group Channel group from which to remove the channel.
150193 *
151194 * @warning Channel group configuration can be modified only if subscriptions for tasks
152195 * associated with this group are disabled.
153196 *
154197 * @retval NRFX_SUCCESS The channel was successfully removed.
155198 * @retval NRFX_ERROR_INVALID_PARAM The specified group or channel is not allocated.
156199 */
157- nrfx_err_t nrfx_dppi_channel_remove_from_group (uint8_t channel ,
200+ nrfx_err_t nrfx_dppi_channel_remove_from_group (nrfx_dppi_t const * p_instance ,
201+ uint8_t channel ,
158202 nrf_dppi_channel_group_t group );
159203
160204/**
161205 * @brief Function for clearing a DPPI channel group.
162206 *
163- * @param[in] group Channel group to be cleared.
207+ * @param[in] p_instance Pointer to the driver instance structure.
208+ * @param[in] group Channel group to be cleared.
164209 *
165210 * @warning Channel group configuration can be modified only if subscriptions for tasks
166211 * associated with this group are disabled.
167212 *
168213 * @retval NRFX_SUCCESS The group was successfully cleared.
169214 * @retval NRFX_ERROR_INVALID_PARAM The specified group is not allocated.
170215 */
171- nrfx_err_t nrfx_dppi_group_clear (nrf_dppi_channel_group_t group );
216+ nrfx_err_t nrfx_dppi_group_clear (nrfx_dppi_t const * p_instance , nrf_dppi_channel_group_t group );
172217
173218/**
174219 * @brief Function for enabling a DPPI channel group.
175220 *
176- * @param[in] group Channel group to be enabled.
221+ * @param[in] p_instance Pointer to the driver instance structure.
222+ * @param[in] group Channel group to be enabled.
177223 *
178224 * @retval NRFX_SUCCESS The group was successfully enabled.
179225 * @retval NRFX_ERROR_INVALID_PARAM The specified group is not allocated.
180226 */
181- nrfx_err_t nrfx_dppi_group_enable (nrf_dppi_channel_group_t group );
227+ nrfx_err_t nrfx_dppi_group_enable (nrfx_dppi_t const * p_instance ,
228+ nrf_dppi_channel_group_t group );
182229
183230/**
184231 * @brief Function for disabling a DPPI channel group.
185232 *
186- * @param[in] group Channel group to be disabled.
233+ * @param[in] p_instance Pointer to the driver instance structure.
234+ * @param[in] group Channel group to be disabled.
187235 *
188236 * @retval NRFX_SUCCESS The group was successfully disabled.
189237 * @retval NRFX_ERROR_INVALID_PARAM The specified group is not allocated.
190238 */
239+ nrfx_err_t nrfx_dppi_group_disable (nrfx_dppi_t const * p_instance ,
240+ nrf_dppi_channel_group_t group );
241+
242+ #else
243+
244+ #if !defined(NRF_DPPIC_INDEX )
245+ /* Choose the instance to use in case of using deprecated single-instance driver variant. */
246+ #if defined(HALTIUM_XXAA )
247+ #define NRF_DPPIC_INDEX 130
248+ #elif defined(LUMOS_XXAA )
249+ #define NRF_DPPIC_INDEX 20
250+ #else
251+ #define NRF_DPPIC_INDEX 0
252+ #endif
253+ #endif
254+
255+ void nrfx_dppi_free (void );
256+
257+ nrfx_err_t nrfx_dppi_channel_alloc (uint8_t * p_channel );
258+
259+ nrfx_err_t nrfx_dppi_channel_free (uint8_t channel );
260+
261+ nrfx_err_t nrfx_dppi_channel_enable (uint8_t channel );
262+
263+ nrfx_err_t nrfx_dppi_channel_disable (uint8_t channel );
264+
265+ nrfx_err_t nrfx_dppi_group_alloc (nrf_dppi_channel_group_t * p_group );
266+
267+ nrfx_err_t nrfx_dppi_group_free (nrf_dppi_channel_group_t group );
268+
269+ nrfx_err_t nrfx_dppi_channel_include_in_group (uint8_t channel ,
270+ nrf_dppi_channel_group_t group );
271+
272+ nrfx_err_t nrfx_dppi_channel_remove_from_group (uint8_t channel ,
273+ nrf_dppi_channel_group_t group );
274+
275+ nrfx_err_t nrfx_dppi_group_clear (nrf_dppi_channel_group_t group );
276+
277+ nrfx_err_t nrfx_dppi_group_enable (nrf_dppi_channel_group_t group );
278+
191279nrfx_err_t nrfx_dppi_group_disable (nrf_dppi_channel_group_t group );
192280
281+ #endif
282+
193283/** @} */
194284
195285#ifdef __cplusplus
0 commit comments