1 /*
2  * Copyright (c) 2019 - 2024, 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 
34 #ifndef NRF_AAR_H__
35 #define NRF_AAR_H__
36 
37 #include <nrfx.h>
38 #ifdef EASYVDMA_PRESENT
39 #include <helpers/nrf_vdma.h>
40 #endif
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**
47  * @defgroup nrf_aar_hal AAR HAL
48  * @{
49  * @ingroup nrf_aar
50  * @brief   Hardware access layer for managing the Accelerated Address Resolver (AAR) peripheral.
51  */
52 
53 #if defined(AAR_EVENTS_ERROR_EVENTS_ERROR_Msk) || defined(AAR_INTENSET_ERROR_Msk) || \
54     defined(AAR_ERRORSTATUS_ERRORSTATUS_Msk) || defined(__NRFX_DOXYGEN__)
55 /** @brief Presence of the ERROR event and ERRORSTATUS register. */
56 #define NRF_AAR_HAS_ERROR 1
57 #else
58 #define NRF_AAR_HAS_ERROR 0
59 #endif
60 
61 #if defined(AAR_OUT_AMOUNT_AMOUNT_Msk) || defined(__NRFX_DOXYGEN__)
62 /** @brief Presence of the OUT.AMOUNT register. */
63 #define NRF_AAR_HAS_OUT_AMOUNT 1
64 #else
65 #define NRF_AAR_HAS_OUT_AMOUNT 0
66 #endif
67 
68 #if defined(AAR_NIRK_NIRK_Msk) || defined(NRF51) || defined(__NRFX_DOXYGEN__)
69 /** @brief Presence of the NIRK register. */
70 #define NRF_AAR_HAS_NIRK 1
71 #else
72 #define NRF_AAR_HAS_NIRK 0
73 #endif
74 
75 #if defined(AAR_IRKPTR_IRKPTR_Msk) || defined(NRF51) || defined(__NRFX_DOXYGEN__)
76 /** @brief Presence of the IRKPTR register. */
77 #define NRF_AAR_HAS_IRKPTR 1
78 #else
79 #define NRF_AAR_HAS_IRKPTR 0
80 #endif
81 
82 #if defined(AAR_IN_PTR_PTR_Msk) || defined(__NRFX_DOXYGEN__)
83 /** @brief Presence of the IN.PTR register. */
84 #define NRF_AAR_HAS_IN_PTR 1
85 #else
86 #define NRF_AAR_HAS_IN_PTR 0
87 #endif
88 
89 #if defined(AAR_OUT_PTR_PTR_Msk) || defined(__NRFX_DOXYGEN__)
90 /** @brief Presence of the OUT.PTR register. */
91 #define NRF_AAR_HAS_OUT_PTR 1
92 #else
93 #define NRF_AAR_HAS_OUT_PTR 0
94 #endif
95 
96 #if defined(AAR_ADDRPTR_ADDRPTR_Msk) || defined(NRF51) || defined(__NRFX_DOXYGEN__)
97 /** @brief Presence of the ADDRPTR register. */
98 #define NRF_AAR_HAS_ADDRPTR 1
99 #else
100 #define NRF_AAR_HAS_ADDRPTR 0
101 #endif
102 
103 #if defined(AAR_SCRATCHPTR_SCRATCHPTR_Msk) || defined(NRF51) || defined(__NRFX_DOXYGEN__)
104 /** @brief Presence of the SCRATCHPTR register. */
105 #define NRF_AAR_HAS_SCRATCHPTR 1
106 #else
107 #define NRF_AAR_HAS_SCRATCHPTR 0
108 #endif
109 
110 #if defined(AAR_STATUS_STATUS_Msk) || defined(__NRFX_DOXYGEN__)
111 /** @brief Presence of the STATUS register. */
112 #define NRF_AAR_HAS_STATUS 1
113 #else
114 #define NRF_AAR_HAS_STATUS 0
115 #endif
116 
117 #if defined(AAR_MAXRESOLVED_MAXRESOLVED_Msk) || defined(__NRFX_DOXYGEN__)
118 /** @brief Presence of the MAXRESOLVED register. */
119 #define NRF_AAR_HAS_MAXRESOLVED 1
120 #else
121 #define NRF_AAR_HAS_MAXRESOLVED 0
122 #endif
123 
124 /** @brief AAR events. */
125 typedef enum
126 {
127     NRF_AAR_EVENT_END         = offsetof(NRF_AAR_Type, EVENTS_END),         ///< Address resolution procedure complete.
128     NRF_AAR_EVENT_RESOLVED    = offsetof(NRF_AAR_Type, EVENTS_RESOLVED),    ///< Address resolved.
129     NRF_AAR_EVENT_NOTRESOLVED = offsetof(NRF_AAR_Type, EVENTS_NOTRESOLVED), ///< Address not resolved.
130 #if NRF_AAR_HAS_ERROR
131     NRF_AAR_EVENT_ERROR       = offsetof(NRF_AAR_Type, EVENTS_ERROR),       ///< Address resolution procedure aborted due to STOP task or error.
132 #endif
133 } nrf_aar_event_t;
134 
135 /** @brief AAR interrupts. */
136 typedef enum
137 {
138     NRF_AAR_INT_END_MASK         = AAR_INTENSET_END_Msk,         ///< Interrupt on END event.
139     NRF_AAR_INT_RESOLVED_MASK    = AAR_INTENSET_RESOLVED_Msk,    ///< Interrupt on RESOLVED event.
140     NRF_AAR_INT_NOTRESOLVED_MASK = AAR_INTENSET_NOTRESOLVED_Msk, ///< Interrupt on NOTRESOLVED event.
141 #if NRF_AAR_HAS_ERROR
142     NRF_AAR_INT_ERROR_MASK       = AAR_INTENSET_ERROR_Msk, ///< Interrupt on NOTRESOLVED event.
143 #endif
144 } nrf_aar_int_mask_t;
145 
146 #if NRF_AAR_HAS_ERROR
147 /** @brief AAR error status when ERROR event is generated. */
148 typedef enum
149 {
150     NRF_AAR_ERROR_NO_ERROR             = AAR_ERRORSTATUS_ERRORSTATUS_NoError,            ///< No errors have occurred.
151     NRF_AAR_ERROR_PREMATURE_INPTR_END  = AAR_ERRORSTATUS_ERRORSTATUS_PrematureInptrEnd,  ///< End of INPTR job list before data structure was read.
152     NRF_AAR_ERROR_PREMATURE_OUTPTR_END = AAR_ERRORSTATUS_ERRORSTATUS_PrematureOutptrEnd, ///< End of OUTPTR job list before data structure was read.
153     NRF_AAR_ERROR_DMA_ERROR            = AAR_ERRORSTATUS_ERRORSTATUS_DmaError,           ///< Bus error during DMA access.
154 } nrf_aar_error_t;
155 #endif
156 
157 /** @brief AAR tasks. */
158 typedef enum
159 {
160     NRF_AAR_TASK_START = offsetof(NRF_AAR_Type, TASKS_START), ///< Start address resolution procedure.
161     NRF_AAR_TASK_STOP  = offsetof(NRF_AAR_Type, TASKS_STOP),  ///< Stop address resolution procedure.
162 } nrf_aar_task_t;
163 
164 /**
165  * @brief Function for retrieving the state of the AAR event.
166  *
167  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
168  * @param[in] event Event to be checked.
169  *
170  * @retval true  Event is set.
171  * @retval false Event is not set.
172  */
173 NRF_STATIC_INLINE bool nrf_aar_event_check(NRF_AAR_Type const * p_reg,
174                                            nrf_aar_event_t      event);
175 
176 /**
177  * @brief Function for clearing the specified AAR event.
178  *
179  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
180  * @param[in] event Event to be cleared.
181  */
182 NRF_STATIC_INLINE void nrf_aar_event_clear(NRF_AAR_Type *  p_reg,
183                                            nrf_aar_event_t event);
184 
185 /**
186  * @brief Function for getting the address of the specified AAR event register.
187  *
188  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
189  * @param[in] event Event to get the address of.
190  *
191  * @return Address of the specified event register.
192  */
193 NRF_STATIC_INLINE uint32_t nrf_aar_event_address_get(NRF_AAR_Type const * p_reg,
194                                                      nrf_aar_event_t      event);
195 
196 /**
197  * @brief Function for enabling the specified interrupts.
198  *
199  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
200  * @param[in] mask  Mask of interrupts to be enabled.
201  *                  Use @ref nrf_aar_int_mask_t values for bit masking.
202  */
203 NRF_STATIC_INLINE void nrf_aar_int_enable(NRF_AAR_Type * p_reg, uint32_t mask);
204 
205 /**
206  * @brief Function for checking if the specified interrupts are enabled.
207  *
208  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
209  * @param[in] mask  Mask of interrupts to be checked.
210  *                  Use @ref nrf_aar_int_mask_t values for bit masking.
211  *
212  * @return Mask of enabled interrupts.
213  */
214 NRF_STATIC_INLINE uint32_t nrf_aar_int_enable_check(NRF_AAR_Type const * p_reg, uint32_t mask);
215 
216 /**
217  * @brief Function for disabling the specified interrupts.
218  *
219  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
220  * @param[in] mask  Mask of interrupts to be disabled.
221  *                  Use @ref nrf_aar_int_mask_t values for bit masking.
222  */
223 NRF_STATIC_INLINE void nrf_aar_int_disable(NRF_AAR_Type * p_reg, uint32_t mask);
224 
225 /**
226  * @brief Function for starting an AAR task.
227  *
228  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
229  * @param[in] task  Task to be activated.
230  */
231 NRF_STATIC_INLINE void nrf_aar_task_trigger(NRF_AAR_Type * p_reg, nrf_aar_task_t task);
232 
233 /**
234  * @brief Function for getting the address of a specific AAR task register.
235  *
236  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
237  * @param[in] task  Requested AAR task.
238  *
239  * @return Address of the specified task register.
240  */
241 NRF_STATIC_INLINE uint32_t nrf_aar_task_address_get(NRF_AAR_Type const * p_reg,
242                                                     nrf_aar_task_t       task);
243 
244 /**
245  * @brief Function for enabling AAR.
246  *
247  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
248  */
249 NRF_STATIC_INLINE void nrf_aar_enable(NRF_AAR_Type * p_reg);
250 
251 /**
252  * @brief Function for disabling AAR.
253  *
254  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
255  */
256 NRF_STATIC_INLINE void nrf_aar_disable(NRF_AAR_Type * p_reg);
257 
258 #if NRF_AAR_HAS_ERROR
259 /**
260  * @brief Function for getting the error status when ERROR event is generated.
261  *
262  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
263  *
264  * @retval Error status when the ERROR event is generated.
265  */
266 NRF_STATIC_INLINE nrf_aar_error_t nrf_aar_error_get(NRF_AAR_Type const * p_reg);
267 #endif // NRF_AAR_HAS_ERROR
268 
269 #if NRF_AAR_HAS_IRKPTR
270 /**
271  * @brief Function for setting the pointer to the Identity Resolving Keys (IRK) data structure.
272  *
273  * The size of the provided data structure must correspond to the number of keys available.
274  * Each key occupies 16 bytes.
275  *
276  * @param[in] p_reg   Pointer to the structure of registers of the peripheral.
277  * @param[in] irk_ptr Pointer to the IRK data structure. Must point to the Data RAM region.
278  *
279  * @sa nrf_aar_irk_number_set
280  */
281 NRF_STATIC_INLINE void nrf_aar_irk_pointer_set(NRF_AAR_Type * p_reg, uint8_t const * irk_ptr);
282 
283 /**
284  * @brief Function for getting the pointer to the Identity Resolving Keys
285  *        data structure.
286  *
287  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
288  *
289  * @return Pointer to the IRK data structure.
290  */
291 NRF_STATIC_INLINE uint8_t const * nrf_aar_irk_pointer_get(NRF_AAR_Type const * p_reg);
292 #endif // NRF_AAR_HAS_IRKPTR
293 
294 #if NRF_AAR_HAS_NIRK
295 /**
296  * @brief Function for setting the number of keys available in the Identity Resolving Keys
297  *        data structure.
298  *
299  * @param[in] p_reg   Pointer to the structure of registers of the peripheral.
300  * @param[in] irk_num Number of keys available in the IRK data structure. Maximum is 16.
301  *                    Must correspond to the size of the provided IRK data structure.
302  *
303  * @sa nrf_aar_irk_pointer_set
304  */
305 NRF_STATIC_INLINE void nrf_aar_irk_number_set(NRF_AAR_Type * p_reg, uint8_t irk_num);
306 
307 /**
308  * @brief Function for getting the number of keys available in the Identity Resolving Keys
309  *        data structure.
310  *
311  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
312  *
313  * @return Number of keys in the IRK data structure.
314  */
315 NRF_STATIC_INLINE uint8_t nrf_aar_irk_number_get(NRF_AAR_Type const * p_reg);
316 #endif // NRF_AAR_HAS_NIRK
317 
318 #if NRF_AAR_HAS_MAXRESOLVED
319 /**
320  * @brief Function for setting maximum number of Identity Resolving Keys to resolve.
321  *
322  * @param[in] p_reg       Pointer to the structure of registers of the peripheral.
323  * @param[in] maxresolved Maximum number of Identity Resolving Keys to resolve.
324  *
325  * @sa nrf_aar_irk_pointer_set
326  */
327 NRF_STATIC_INLINE void nrf_aar_maxresolved_set(NRF_AAR_Type * p_reg, uint16_t maxresolved);
328 
329 /**
330  * @brief Function for getting maximum number of Identity Resolving Keys to resolve.
331  *
332  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
333  *
334  * @return Maximum number of Identity Resolving Keys to resolve.
335  */
336 NRF_STATIC_INLINE uint16_t nrf_aar_maxresolved_get(NRF_AAR_Type const * p_reg);
337 #endif
338 
339 #if NRF_AAR_HAS_ADDRPTR
340 /**
341  * @brief Function for setting the pointer to the resolvable address.
342  *
343  * The resolvable address must consist of 6 bytes.
344  *
345  * @param[in] p_reg    Pointer to the structure of registers of the peripheral.
346  * @param[in] addr_ptr Pointer to the address to resolve using the available IRK keys.
347  *                     Must point to the Data RAM region.
348  */
349 NRF_STATIC_INLINE void nrf_aar_addr_pointer_set(NRF_AAR_Type * p_reg, uint8_t const * addr_ptr);
350 
351 /**
352  * @brief Function for getting the pointer to the resolvable address.
353  *
354  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
355  *
356  * @return Pointer to the address to resolve.
357  */
358 NRF_STATIC_INLINE uint8_t const * nrf_aar_addr_pointer_get(NRF_AAR_Type const * p_reg);
359 #endif // NRF_AAR_HAS_ADDRPTR
360 
361 #if NRF_AAR_HAS_OUT_PTR
362 /**
363  * @brief Function for setting the pointer to a job list containing description to store
364  *        resolved addresses.
365  *
366  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
367  * @param[in] p_job Pointer to a job list.
368  */
369 NRF_STATIC_INLINE void nrf_aar_out_ptr_set(NRF_AAR_Type *         p_reg,
370                                            nrf_vdma_job_t const * p_job);
371 
372 /**
373  * @brief Function for getting the pointer to a job list containing description to store
374  *        resolved addresses.
375  *
376  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
377  *
378  * @return Pointer to the job list.
379  */
380 NRF_STATIC_INLINE nrf_vdma_job_t * nrf_aar_out_ptr_get(NRF_AAR_Type const * p_reg);
381 #endif // NRF_AAR_HAS_OUT_PTR
382 
383 #if NRF_AAR_HAS_IN_PTR
384 /**
385  * @brief Function for setting the pointer to a job list containing both
386  *        the Hash and Prand parts of the private resolvable address (DEVICEADDR)
387  *        field from the Bluetooth packet, and a number of Identity Resolving Keys (IRK).
388  *
389  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
390  * @param[in] p_job Pointer to a job list.
391  */
392 NRF_STATIC_INLINE void nrf_aar_in_ptr_set(NRF_AAR_Type *         p_reg,
393                                           nrf_vdma_job_t const * p_job);
394 
395 /**
396  * @brief Function for getting the pointer to a job list containing both
397  *        the Hash and Prand parts of the private resolvable address (DEVICEADDR)
398  *        field from the Bluetooth packet, and a number of Identity Resolving Keys (IRK).
399  *
400  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
401  *
402  * @return Pointer to the job list.
403  */
404 NRF_STATIC_INLINE nrf_vdma_job_t * nrf_aar_in_ptr_get(NRF_AAR_Type const * p_reg);
405 #endif // NRF_AAR_HAS_IN_PTR
406 
407 #if NRF_AAR_HAS_OUT_AMOUNT
408 /**
409  * @brief Function for getting number of bytes available in the output data,
410  *        not including the job list structure.
411  *
412  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
413  *
414  * @return Number of bytes available in the output data.
415  */
416 NRF_STATIC_INLINE uint32_t nrf_aar_out_amount_get(NRF_AAR_Type const * p_reg);
417 #endif // NRF_AAR_HAS_OUT_AMOUNT
418 
419 #if NRF_AAR_HAS_SCRATCHPTR
420 /**
421  * @brief Function for setting the pointer to the scratch data area.
422  *
423  * The scratch data area is used for temporary storage during the address resolution procedure.
424  * A space of minimum 3 bytes must be reserved for the scratch data area.
425  *
426  * @param[in] p_reg       Pointer to the structure of registers of the peripheral.
427  * @param[in] scratch_ptr Pointer to the scratch data area. Must point to the Data RAM region.
428  */
429 NRF_STATIC_INLINE void nrf_aar_scratch_pointer_set(NRF_AAR_Type * p_reg, uint8_t * scratch_ptr);
430 
431 /**
432  * @brief Function for getting the pointer to the scratch data area.
433  *
434  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
435  *
436  * @return Pointer to the scratch data area.
437  */
438 NRF_STATIC_INLINE uint8_t * nrf_aar_scratch_pointer_get(NRF_AAR_Type const * p_reg);
439 #endif // NRF_AAR_HAS_SCRATCHPTR
440 
441 #if NRF_AAR_HAS_STATUS
442 /**
443  * @brief Function for getting the index of the Identity Resolving Key that was used
444  *        the last time an address was resolved.
445  *
446  * This function can be used to get the IRK index that matched the resolvable address,
447  * provided that @ref NRF_AAR_EVENT_RESOLVED occured. Otherwise, it will return
448  * the index of the last IRK stored in the IRK data structure.
449  *
450  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
451  *
452  * @return The index of the IRK that was used the last time an address was resolved.
453  */
454 NRF_STATIC_INLINE uint8_t nrf_aar_resolution_status_get(NRF_AAR_Type const * p_reg);
455 #endif // NRF_AAR_HAS_STATUS
456 
457 #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
458 /**
459  * @brief Function for setting the subscribe configuration for a given
460  *        AAR task.
461  *
462  * @param[in] p_reg   Pointer to the structure of registers of the peripheral.
463  * @param[in] task    Task for which to set the configuration.
464  * @param[in] channel Channel through which to subscribe events.
465  */
466 NRF_STATIC_INLINE void nrf_aar_subscribe_set(NRF_AAR_Type * p_reg,
467                                              nrf_aar_task_t task,
468                                              uint8_t        channel);
469 
470 /**
471  * @brief Function for clearing the subscribe configuration for a given
472  *        AAR task.
473  *
474  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
475  * @param[in] task  Task for which to clear the configuration.
476  */
477 NRF_STATIC_INLINE void nrf_aar_subscribe_clear(NRF_AAR_Type * p_reg,
478                                                nrf_aar_task_t task);
479 
480 /**
481  * @brief Function for setting the publish configuration for a given
482  *        AAR event.
483  *
484  * @param[in] p_reg   Pointer to the structure of registers of the peripheral.
485  * @param[in] event   Event for which to set the configuration.
486  * @param[in] channel Channel through which to publish the event.
487  */
488 NRF_STATIC_INLINE void nrf_aar_publish_set(NRF_AAR_Type *  p_reg,
489                                            nrf_aar_event_t event,
490                                            uint8_t         channel);
491 
492 /**
493  * @brief Function for clearing the publish configuration for a given
494  *        AAR event.
495  *
496  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
497  * @param[in] event Event for which to clear the configuration.
498  */
499 NRF_STATIC_INLINE void nrf_aar_publish_clear(NRF_AAR_Type *  p_reg,
500                                              nrf_aar_event_t event);
501 #endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
502 
503 #ifndef NRF_DECLARE_ONLY
nrf_aar_event_check(NRF_AAR_Type const * p_reg,nrf_aar_event_t aar_event)504 NRF_STATIC_INLINE bool nrf_aar_event_check(NRF_AAR_Type const * p_reg,
505                                            nrf_aar_event_t      aar_event)
506 {
507     return nrf_event_check(p_reg, aar_event);
508 }
509 
nrf_aar_event_clear(NRF_AAR_Type * p_reg,nrf_aar_event_t aar_event)510 NRF_STATIC_INLINE void nrf_aar_event_clear(NRF_AAR_Type *  p_reg,
511                                            nrf_aar_event_t aar_event)
512 {
513     *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)aar_event)) = 0;
514     nrf_event_readback((uint8_t *)p_reg + (uint32_t)aar_event);
515 }
516 
nrf_aar_event_address_get(NRF_AAR_Type const * p_reg,nrf_aar_event_t aar_event)517 NRF_STATIC_INLINE uint32_t nrf_aar_event_address_get(NRF_AAR_Type const * p_reg,
518                                                      nrf_aar_event_t      aar_event)
519 {
520     return nrf_task_event_address_get(p_reg, aar_event);
521 }
522 
nrf_aar_int_enable(NRF_AAR_Type * p_reg,uint32_t mask)523 NRF_STATIC_INLINE void nrf_aar_int_enable(NRF_AAR_Type * p_reg, uint32_t mask)
524 {
525     p_reg->INTENSET = mask;
526 }
527 
nrf_aar_int_enable_check(NRF_AAR_Type const * p_reg,uint32_t mask)528 NRF_STATIC_INLINE uint32_t nrf_aar_int_enable_check(NRF_AAR_Type const * p_reg, uint32_t mask)
529 {
530     return p_reg->INTENSET & mask;
531 }
532 
nrf_aar_int_disable(NRF_AAR_Type * p_reg,uint32_t mask)533 NRF_STATIC_INLINE void nrf_aar_int_disable(NRF_AAR_Type * p_reg, uint32_t mask)
534 {
535     p_reg->INTENCLR = mask;
536 }
537 
nrf_aar_task_trigger(NRF_AAR_Type * p_reg,nrf_aar_task_t task)538 NRF_STATIC_INLINE void nrf_aar_task_trigger(NRF_AAR_Type * p_reg, nrf_aar_task_t task)
539 {
540     *(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task) = 1;
541 }
542 
nrf_aar_task_address_get(NRF_AAR_Type const * p_reg,nrf_aar_task_t task)543 NRF_STATIC_INLINE uint32_t nrf_aar_task_address_get(NRF_AAR_Type const * p_reg,
544                                                     nrf_aar_task_t       task)
545 {
546     return nrf_task_event_address_get(p_reg, task);
547 }
548 
nrf_aar_enable(NRF_AAR_Type * p_reg)549 NRF_STATIC_INLINE void nrf_aar_enable(NRF_AAR_Type * p_reg)
550 {
551     p_reg->ENABLE = AAR_ENABLE_ENABLE_Enabled << AAR_ENABLE_ENABLE_Pos;
552 }
553 
nrf_aar_disable(NRF_AAR_Type * p_reg)554 NRF_STATIC_INLINE void nrf_aar_disable(NRF_AAR_Type * p_reg)
555 {
556     p_reg->ENABLE = AAR_ENABLE_ENABLE_Disabled << AAR_ENABLE_ENABLE_Pos;
557 }
558 
559 #if NRF_AAR_HAS_IRKPTR
nrf_aar_irk_pointer_set(NRF_AAR_Type * p_reg,uint8_t const * irk_ptr)560 NRF_STATIC_INLINE void nrf_aar_irk_pointer_set(NRF_AAR_Type * p_reg, uint8_t const * irk_ptr)
561 {
562     p_reg->IRKPTR = (uint32_t)irk_ptr;
563 }
564 
nrf_aar_irk_pointer_get(NRF_AAR_Type const * p_reg)565 NRF_STATIC_INLINE uint8_t const * nrf_aar_irk_pointer_get(NRF_AAR_Type const * p_reg)
566 {
567     return (uint8_t const *)(p_reg->IRKPTR);
568 }
569 #endif // NRF_AAR_HAS_IRKPTR
570 
571 #if NRF_AAR_HAS_NIRK
nrf_aar_irk_number_set(NRF_AAR_Type * p_reg,uint8_t irk_num)572 NRF_STATIC_INLINE void nrf_aar_irk_number_set(NRF_AAR_Type * p_reg, uint8_t irk_num)
573 {
574     p_reg->NIRK = irk_num;
575 }
576 
nrf_aar_irk_number_get(NRF_AAR_Type const * p_reg)577 NRF_STATIC_INLINE uint8_t nrf_aar_irk_number_get(NRF_AAR_Type const * p_reg)
578 {
579     return (uint8_t)(p_reg->NIRK);
580 }
581 #endif // NRF_AAR_HAS_NIRK
582 
583 #if NRF_AAR_HAS_ADDRPTR
nrf_aar_addr_pointer_set(NRF_AAR_Type * p_reg,uint8_t const * addr_ptr)584 NRF_STATIC_INLINE void nrf_aar_addr_pointer_set(NRF_AAR_Type * p_reg, uint8_t const * addr_ptr)
585 {
586     p_reg->ADDRPTR = (uint32_t)addr_ptr;
587 }
588 
nrf_aar_addr_pointer_get(NRF_AAR_Type const * p_reg)589 NRF_STATIC_INLINE uint8_t const * nrf_aar_addr_pointer_get(NRF_AAR_Type const * p_reg)
590 {
591     return (uint8_t const *)(p_reg->ADDRPTR);
592 }
593 #endif // NRF_AAR_HAS_ADDRPTR
594 
595 #if NRF_AAR_HAS_SCRATCHPTR
nrf_aar_scratch_pointer_set(NRF_AAR_Type * p_reg,uint8_t * scratch_ptr)596 NRF_STATIC_INLINE void nrf_aar_scratch_pointer_set(NRF_AAR_Type * p_reg, uint8_t * scratch_ptr)
597 {
598     p_reg->SCRATCHPTR = (uint32_t)scratch_ptr;
599 }
600 
nrf_aar_scratch_pointer_get(NRF_AAR_Type const * p_reg)601 NRF_STATIC_INLINE uint8_t * nrf_aar_scratch_pointer_get(NRF_AAR_Type const * p_reg)
602 {
603     return (uint8_t *)(p_reg->SCRATCHPTR);
604 }
605 #endif // NRF_AAR_HAS_SCRATCHPTR
606 
607 #if NRF_AAR_HAS_STATUS
nrf_aar_resolution_status_get(NRF_AAR_Type const * p_reg)608 NRF_STATIC_INLINE uint8_t nrf_aar_resolution_status_get(NRF_AAR_Type const * p_reg)
609 {
610     return (uint8_t)(p_reg->STATUS);
611 }
612 #endif // NRF_AAR_HAS_STATUS
613 
614 #if NRF_AAR_HAS_ERROR
nrf_aar_error_get(NRF_AAR_Type const * p_reg)615 NRF_STATIC_INLINE nrf_aar_error_t nrf_aar_error_get(NRF_AAR_Type const * p_reg)
616 {
617     return (nrf_aar_error_t)(p_reg->ERRORSTATUS);
618 }
619 #endif // NRF_AAR_HAS_ERROR
620 
621 #if NRF_AAR_HAS_MAXRESOLVED
nrf_aar_maxresolved_set(NRF_AAR_Type * p_reg,uint16_t maxresolved)622 NRF_STATIC_INLINE void nrf_aar_maxresolved_set(NRF_AAR_Type * p_reg, uint16_t maxresolved)
623 {
624     p_reg->MAXRESOLVED = maxresolved;
625 }
626 
nrf_aar_maxresolved_get(NRF_AAR_Type const * p_reg)627 NRF_STATIC_INLINE uint16_t nrf_aar_maxresolved_get(NRF_AAR_Type const * p_reg)
628 {
629     return (uint16_t)(p_reg->MAXRESOLVED);
630 }
631 #endif // NRF_AAR_HAS_MAXRESOLVED
632 
633 #if NRF_AAR_HAS_IN_PTR
nrf_aar_in_ptr_set(NRF_AAR_Type * p_reg,nrf_vdma_job_t const * p_job)634 NRF_STATIC_INLINE void nrf_aar_in_ptr_set(NRF_AAR_Type *         p_reg,
635                                           nrf_vdma_job_t const * p_job)
636 {
637     p_reg->IN.PTR = (uint32_t)p_job;
638 }
639 
nrf_aar_in_ptr_get(NRF_AAR_Type const * p_reg)640 NRF_STATIC_INLINE nrf_vdma_job_t * nrf_aar_in_ptr_get(NRF_AAR_Type const * p_reg)
641 {
642     return (nrf_vdma_job_t *)(p_reg->IN.PTR);
643 }
644 #endif // NRF_AAR_HAS_IN_PTR
645 
646 #if NRF_AAR_HAS_OUT_PTR
nrf_aar_out_ptr_set(NRF_AAR_Type * p_reg,nrf_vdma_job_t const * p_job)647 NRF_STATIC_INLINE void nrf_aar_out_ptr_set(NRF_AAR_Type *         p_reg,
648                                            nrf_vdma_job_t const * p_job)
649 {
650     p_reg->OUT.PTR = (uint32_t)p_job;
651 }
652 
nrf_aar_out_ptr_get(NRF_AAR_Type const * p_reg)653 NRF_STATIC_INLINE nrf_vdma_job_t * nrf_aar_out_ptr_get(NRF_AAR_Type const * p_reg)
654 {
655     return (nrf_vdma_job_t *)(p_reg->OUT.PTR);
656 }
657 #endif // NRF_AAR_HAS_OUT_PTR
658 
659 #if NRF_AAR_HAS_OUT_AMOUNT
nrf_aar_out_amount_get(NRF_AAR_Type const * p_reg)660 NRF_STATIC_INLINE uint32_t nrf_aar_out_amount_get(NRF_AAR_Type const * p_reg)
661 {
662     return p_reg->OUT.AMOUNT;
663 }
664 #endif // NRF_AAR_HAS_OUT_AMOUNT
665 
666 #if defined(DPPI_PRESENT)
nrf_aar_subscribe_set(NRF_AAR_Type * p_reg,nrf_aar_task_t task,uint8_t channel)667 NRF_STATIC_INLINE void nrf_aar_subscribe_set(NRF_AAR_Type * p_reg,
668                                              nrf_aar_task_t task,
669                                              uint8_t        channel)
670 {
671     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
672             ((uint32_t)channel | NRF_SUBSCRIBE_PUBLISH_ENABLE);
673 }
674 
nrf_aar_subscribe_clear(NRF_AAR_Type * p_reg,nrf_aar_task_t task)675 NRF_STATIC_INLINE void nrf_aar_subscribe_clear(NRF_AAR_Type * p_reg,
676                                                nrf_aar_task_t task)
677 {
678     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
679 }
680 
nrf_aar_publish_set(NRF_AAR_Type * p_reg,nrf_aar_event_t event,uint8_t channel)681 NRF_STATIC_INLINE void nrf_aar_publish_set(NRF_AAR_Type *  p_reg,
682                                            nrf_aar_event_t event,
683                                            uint8_t         channel)
684 {
685     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) =
686             ((uint32_t)channel | NRF_SUBSCRIBE_PUBLISH_ENABLE);
687 }
688 
nrf_aar_publish_clear(NRF_AAR_Type * p_reg,nrf_aar_event_t event)689 NRF_STATIC_INLINE void nrf_aar_publish_clear(NRF_AAR_Type *  p_reg,
690                                              nrf_aar_event_t event)
691 {
692     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) = 0;
693 }
694 #endif // defined(DPPI_PRESENT)
695 
696 #endif // NRF_DECLARE_ONLY
697 
698 /** @} */
699 
700 #ifdef __cplusplus
701 }
702 #endif
703 
704 #endif // NRF_AAR_H__
705