1 /*
2  * Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  *    list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  *    contributors may be used to endorse or promote products derived from this
17  *    software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef NRF_CCM_H__
33 #define NRF_CCM_H__
34 
35 #include <nrfx.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /**
42  * @defgroup nrf_ccm_hal AES CCM HAL
43  * @{
44  * @ingroup nrf_ccm
45  * @brief   Hardware access layer for managing the AES CCM peripheral.
46  */
47 
48 /** @brief CCM tasks. */
49 typedef enum
50 {
51     NRF_CCM_TASK_KSGEN        = offsetof(NRF_CCM_Type, TASKS_KSGEN),        ///< Start generation of key-stream.
52     NRF_CCM_TASK_CRYPT        = offsetof(NRF_CCM_Type, TASKS_CRYPT),        ///< Start encryption/decryption.
53     NRF_CCM_TASK_STOP         = offsetof(NRF_CCM_Type, TASKS_STOP),         ///< Stop encryption/decryption.
54 #if defined(CCM_RATEOVERRIDE_RATEOVERRIDE_Pos) || defined(__NRFX_DOXYGEN__)
55     NRF_CCM_TASK_RATEOVERRIDE = offsetof(NRF_CCM_Type, TASKS_RATEOVERRIDE), ///< Override DATARATE setting in MODE register.
56 #endif
57 } nrf_ccm_task_t;
58 
59 /** @brief CCM events. */
60 typedef enum
61 {
62     NRF_CCM_EVENT_ENDKSGEN = offsetof(NRF_CCM_Type, EVENTS_ENDKSGEN), ///< Keystream generation complete.
63     NRF_CCM_EVENT_ENDCRYPT = offsetof(NRF_CCM_Type, EVENTS_ENDCRYPT), ///< Encrypt/decrypt complete.
64     NRF_CCM_EVENT_ERROR    = offsetof(NRF_CCM_Type, EVENTS_ERROR),    ///< CCM error event.
65 } nrf_ccm_event_t;
66 
67 /** @brief Types of CCM shorts. */
68 typedef enum
69 {
70     NRF_CCM_SHORT_ENDKSGEN_CRYPT_MASK = CCM_SHORTS_ENDKSGEN_CRYPT_Msk, ///< Shortcut for starting encryption/decryption when the key-stream generation is complete.
71 } nrf_ccm_short_mask_t;
72 
73 /** @brief CCM interrupts. */
74 typedef enum
75 {
76     NRF_CCM_INT_ENDKSGEN_MASK  = CCM_INTENSET_ENDKSGEN_Msk, ///< Interrupt on ENDKSGEN event.
77     NRF_CCM_INT_ENDCRYPT_MASK  = CCM_INTENSET_ENDCRYPT_Msk, ///< Interrupt on ENDCRYPT event.
78     NRF_CCM_INT_ERROR_MASK     = CCM_INTENSET_ERROR_Msk,    ///< Interrupt on ERROR event.
79 } nrf_ccm_int_mask_t;
80 
81 /** @brief CCM modes of operation. */
82 typedef enum
83 {
84     NRF_CCM_MODE_ENCRYPTION = CCM_MODE_MODE_Encryption, ///< Encryption mode.
85     NRF_CCM_MODE_DECRYPTION = CCM_MODE_MODE_Decryption, ///< Decryption mode.
86 } nrf_ccm_mode_t;
87 
88 #if defined(CCM_MODE_DATARATE_Pos) || defined(__NRFX_DOXYGEN__)
89 /** @brief CCM data rates. */
90 typedef enum
91 {
92     NRF_CCM_DATARATE_1M   = CCM_MODE_DATARATE_1Mbit,   ///< 1 Mbps.
93     NRF_CCM_DATARATE_2M   = CCM_MODE_DATARATE_2Mbit,   ///< 2 Mbps.
94 #if defined(CCM_MODE_DATARATE_125Kbps) || defined(__NRFX_DOXYGEN__)
95     NRF_CCM_DATARATE_125K = CCM_MODE_DATARATE_125Kbps, ///< 125 Kbps.
96 #endif
97 #if defined(CCM_MODE_DATARATE_500Kbps) || defined(__NRFX_DOXYGEN__)
98     NRF_CCM_DATARATE_500K = CCM_MODE_DATARATE_500Kbps, ///< 500 Kbps.
99 #endif
100 } nrf_ccm_datarate_t;
101 #endif // defined(CCM_MODE_DATARATE_Pos) || defined(__NRFX_DOXYGEN__)
102 
103 #if defined(CCM_MODE_LENGTH_Pos) || defined(__NRFX_DOXYGEN__)
104 /** @brief CCM packet length options. */
105 typedef enum
106 {
107     NRF_CCM_LENGTH_DEFAULT  = CCM_MODE_LENGTH_Default,  ///< Default length.
108     NRF_CCM_LENGTH_EXTENDED = CCM_MODE_LENGTH_Extended, ///< Extended length.
109 } nrf_ccm_length_t;
110 #endif // defined(CCM_MODE_LENGTH_Pos) || defined(__NRFX_DOXYGEN__)
111 
112 /** @brief CCM configuration. */
113 typedef struct {
114     nrf_ccm_mode_t     mode;     ///< Operation mode.
115 #if defined(CCM_MODE_DATARATE_Pos) || defined(__NRFX_DOXYGEN__)
116     nrf_ccm_datarate_t datarate; ///< Data rate.
117 #endif
118 #if defined(CCM_MODE_LENGTH_Pos) || defined(__NRFX_DOXYGEN__)
119     nrf_ccm_length_t   length;   ///< Lenght of the CCM packet.
120 #endif
121 } nrf_ccm_config_t;
122 
123 /**
124  * @brief Function for activating a specific CCM task.
125  *
126  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
127  * @param[in] task  Task to be activated.
128  */
129 NRF_STATIC_INLINE void nrf_ccm_task_trigger(NRF_CCM_Type * p_reg,
130                                             nrf_ccm_task_t task);
131 
132 /**
133  * @brief Function for getting the address of a specific CCM task register.
134  *
135  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
136  * @param[in] task  Requested task.
137  *
138  * @return Address of the specified task register.
139  */
140 NRF_STATIC_INLINE uint32_t nrf_ccm_task_address_get(NRF_CCM_Type const * p_reg,
141                                                     nrf_ccm_task_t       task);
142 
143 /**
144  * @brief Function for clearing a specific CCM event.
145  *
146  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
147  * @param[in] event Event to clear.
148  */
149 NRF_STATIC_INLINE void nrf_ccm_event_clear(NRF_CCM_Type *  p_reg,
150                                            nrf_ccm_event_t event);
151 
152 /**
153  * @brief Function for retrieving the state of a specific CCM event.
154  *
155  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
156  * @param[in] event Event to be checked.
157  *
158  * @retval true  The event has been generated.
159  * @retval false The event has not been generated.
160  */
161 NRF_STATIC_INLINE bool nrf_ccm_event_check(NRF_CCM_Type const * p_reg,
162                                            nrf_ccm_event_t      event);
163 
164 /**
165  * @brief Function for getting the address of a specific CCM event register.
166  *
167  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
168  * @param[in] event Requested event.
169  *
170  * @return Address of the specified event register.
171  */
172 NRF_STATIC_INLINE uint32_t nrf_ccm_event_address_get(NRF_CCM_Type const * p_reg,
173                                                      nrf_ccm_event_t      event);
174 
175 /**
176  * @brief Function for enabling the specified shortcuts.
177  *
178  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
179  * @param[in] mask  Shortcuts to be enabled.
180  */
181 NRF_STATIC_INLINE void nrf_ccm_shorts_enable(NRF_CCM_Type * p_reg,
182                                              uint32_t       mask);
183 
184 /**
185  * @brief Function for disabling the specified shortcuts.
186  *
187  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
188  * @param[in] mask  Shortcuts to be disabled.
189  */
190 NRF_STATIC_INLINE void nrf_ccm_shorts_disable(NRF_CCM_Type * p_reg,
191                                               uint32_t       mask);
192 
193 /**
194  * @brief Function for setting the specified shortcuts.
195  *
196  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
197  * @param[in] mask  Shortcuts to be set.
198  */
199 NRF_STATIC_INLINE void nrf_ccm_shorts_set(NRF_CCM_Type * p_reg,
200                                           uint32_t       mask);
201 
202 /**
203  * @brief Function for enabling specified interrupts.
204  *
205  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
206  * @param[in] mask  Interrupts to be enabled.
207  */
208 NRF_STATIC_INLINE void nrf_ccm_int_enable(NRF_CCM_Type * p_reg, uint32_t mask);
209 
210 /**
211  * @brief Function for disabling specified interrupts.
212  *
213  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
214  * @param[in] mask  Interrupts to be disabled.
215  */
216 NRF_STATIC_INLINE void nrf_ccm_int_disable(NRF_CCM_Type * p_reg, uint32_t mask);
217 
218 /**
219  * @brief Function for checking if the specified interrupts are enabled.
220  *
221  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
222  * @param[in] mask  Mask of interrupts to be checked.
223  *
224  * @return Mask of enabled interrupts.
225  */
226 NRF_STATIC_INLINE uint32_t nrf_ccm_int_enable_check(NRF_CCM_Type const * p_reg, uint32_t mask);
227 
228 /**
229  * @brief Function for enabling the CCM peripheral.
230  *
231  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
232  */
233 NRF_STATIC_INLINE void nrf_ccm_enable(NRF_CCM_Type * p_reg);
234 
235 /**
236  * @brief Function for disabling the CCM peripheral.
237  *
238  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
239  */
240 NRF_STATIC_INLINE void nrf_ccm_disable(NRF_CCM_Type * p_reg);
241 
242 /**
243  * @brief Function for setting the CCM peripheral configuration.
244  *
245  * @param[in] p_reg    Pointer to the structure of registers of the peripheral.
246  * @param[in] p_config Pointer to the structure with configuration to be set.
247  */
248 NRF_STATIC_INLINE void nrf_ccm_configure(NRF_CCM_Type *           p_reg,
249                                          nrf_ccm_config_t const * p_config);
250 
251 #if defined(CCM_MAXPACKETSIZE_MAXPACKETSIZE_Pos) || defined(__NRFX_DOXYGEN__)
252 /**
253  * @brief Function for setting the length of key-stream generated
254  *        when the packet length is configured as extended.
255  *
256  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
257  * @param[in] size  Maximum length of the key-stream.
258  */
259 NRF_STATIC_INLINE void nrf_ccm_maxpacketsize_set(NRF_CCM_Type * p_reg,
260                                                  uint8_t        size);
261 #endif // defined(CCM_MAXPACKETSIZE_MAXPACKETSIZE_Pos) || defined(__NRFX_DOXYGEN__)
262 
263 /**
264  * @brief Function for getting the MIC check result.
265  *
266  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
267  *
268  * @retval true  The MIC check passed.
269  * @retval false The MIC check failed.
270  */
271 NRF_STATIC_INLINE bool nrf_ccm_micstatus_get(NRF_CCM_Type const * p_reg);
272 
273 /**
274  * @brief Function for setting the pointer to the data structure
275  *        holding the AES key and the CCM NONCE vector.
276  *
277  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
278  * @param[in] p_data Pointer to the data structure.
279  */
280 NRF_STATIC_INLINE void nrf_ccm_cnfptr_set(NRF_CCM_Type *   p_reg,
281                                           uint32_t const * p_data);
282 
283 /**
284  * @brief Function for getting the pointer to the data structure
285  *        holding the AES key and the CCM NONCE vector.
286  *
287  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
288  *
289  * @return Pointer to the data structure.
290  */
291 NRF_STATIC_INLINE uint32_t * nrf_ccm_cnfptr_get(NRF_CCM_Type const * p_reg);
292 
293 /**
294  * @brief Function for setting the input data pointer.
295  *
296  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
297  * @param[in] p_data Input data pointer.
298  */
299 NRF_STATIC_INLINE void nrf_ccm_inptr_set(NRF_CCM_Type *   p_reg,
300                                          uint32_t const * p_data);
301 
302 /**
303  * @brief Function for getting the input data pointer.
304  *
305  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
306  *
307  * @return Input data pointer.
308  */
309 NRF_STATIC_INLINE uint32_t * nrf_ccm_inptr_get(NRF_CCM_Type const * p_reg);
310 
311 /**
312  * @brief Function for setting the output data pointer.
313  *
314  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
315  * @param[in] p_data Output data pointer.
316  */
317 NRF_STATIC_INLINE void nrf_ccm_outptr_set(NRF_CCM_Type *   p_reg,
318                                           uint32_t const * p_data);
319 
320 /**
321  * @brief Function for getting the output data pointer.
322  *
323  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
324  *
325  * @return Output data pointer.
326  */
327 NRF_STATIC_INLINE uint32_t * nrf_ccm_outptr_get(NRF_CCM_Type const * p_reg);
328 
329 /**
330  * @brief Function for setting the pointer to the scratch area used for
331  *        temporary storage.
332  *
333  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
334  * @param[in] p_area Pointer to the scratch area.
335  */
336 NRF_STATIC_INLINE void nrf_ccm_scratchptr_set(NRF_CCM_Type *   p_reg,
337                                               uint32_t const * p_area);
338 
339 /**
340  * @brief Function for getting the pointer to the scratch area.
341  *
342  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
343  *
344  * @return Pointer to the scratch area.
345  */
346 NRF_STATIC_INLINE uint32_t * nrf_ccm_stratchptr_get(NRF_CCM_Type const * p_reg);
347 
348 #if defined(CCM_RATEOVERRIDE_RATEOVERRIDE_Pos) || defined(__NRFX_DOXYGEN__)
349 /**
350  * @brief Function for setting the data rate override value.
351  *
352  * @param[in] p_reg    Pointer to the structure of registers of the peripheral.
353  * @param[in] datarate Override value to be applied when the RATEOVERRIDE task
354  *                     is triggered.
355  */
356 NRF_STATIC_INLINE void nrf_ccm_datarate_override_set(NRF_CCM_Type *     p_reg,
357                                                      nrf_ccm_datarate_t datarate);
358 #endif // defined(CCM_RATEOVERRIDE_RATEOVERRIDE_Pos) || defined(__NRFX_DOXYGEN__)
359 
360 #ifndef NRF_DECLARE_ONLY
361 
nrf_ccm_task_trigger(NRF_CCM_Type * p_reg,nrf_ccm_task_t task)362 NRF_STATIC_INLINE void nrf_ccm_task_trigger(NRF_CCM_Type * p_reg,
363                                             nrf_ccm_task_t task)
364 {
365     *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
366 }
367 
nrf_ccm_task_address_get(NRF_CCM_Type const * p_reg,nrf_ccm_task_t task)368 NRF_STATIC_INLINE uint32_t nrf_ccm_task_address_get(NRF_CCM_Type const * p_reg,
369                                                     nrf_ccm_task_t       task)
370 {
371     return ((uint32_t)p_reg + (uint32_t)task);
372 }
373 
nrf_ccm_event_clear(NRF_CCM_Type * p_reg,nrf_ccm_event_t event)374 NRF_STATIC_INLINE void nrf_ccm_event_clear(NRF_CCM_Type *  p_reg,
375                                            nrf_ccm_event_t event)
376 {
377     *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL;
378     nrf_event_readback((uint8_t *)p_reg + (uint32_t)event);
379 }
380 
nrf_ccm_event_check(NRF_CCM_Type const * p_reg,nrf_ccm_event_t event)381 NRF_STATIC_INLINE bool nrf_ccm_event_check(NRF_CCM_Type const * p_reg,
382                                            nrf_ccm_event_t      event)
383 {
384     return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
385 }
386 
nrf_ccm_event_address_get(NRF_CCM_Type const * p_reg,nrf_ccm_event_t event)387 NRF_STATIC_INLINE uint32_t nrf_ccm_event_address_get(NRF_CCM_Type const * p_reg,
388                                                      nrf_ccm_event_t      event)
389 {
390     return ((uint32_t)p_reg + (uint32_t)event);
391 }
392 
393 
nrf_ccm_shorts_enable(NRF_CCM_Type * p_reg,uint32_t mask)394 NRF_STATIC_INLINE void nrf_ccm_shorts_enable(NRF_CCM_Type * p_reg,
395                                              uint32_t       mask)
396 {
397     p_reg->SHORTS |= mask;
398 }
399 
nrf_ccm_shorts_disable(NRF_CCM_Type * p_reg,uint32_t mask)400 NRF_STATIC_INLINE void nrf_ccm_shorts_disable(NRF_CCM_Type * p_reg,
401                                               uint32_t       mask)
402 {
403     p_reg->SHORTS &= ~(mask);
404 }
405 
nrf_ccm_shorts_set(NRF_CCM_Type * p_reg,uint32_t mask)406 NRF_STATIC_INLINE void nrf_ccm_shorts_set(NRF_CCM_Type * p_reg,
407                                           uint32_t       mask)
408 {
409     p_reg->SHORTS = mask;
410 }
411 
nrf_ccm_int_enable(NRF_CCM_Type * p_reg,uint32_t mask)412 NRF_STATIC_INLINE void nrf_ccm_int_enable(NRF_CCM_Type * p_reg, uint32_t mask)
413 {
414     p_reg->INTENSET = mask;
415 }
416 
nrf_ccm_int_disable(NRF_CCM_Type * p_reg,uint32_t mask)417 NRF_STATIC_INLINE void nrf_ccm_int_disable(NRF_CCM_Type * p_reg, uint32_t mask)
418 {
419     p_reg->INTENCLR = mask;
420 }
421 
nrf_ccm_int_enable_check(NRF_CCM_Type const * p_reg,uint32_t mask)422 NRF_STATIC_INLINE uint32_t nrf_ccm_int_enable_check(NRF_CCM_Type const * p_reg, uint32_t mask)
423 {
424     return p_reg->INTENSET & mask;
425 }
426 
nrf_ccm_enable(NRF_CCM_Type * p_reg)427 NRF_STATIC_INLINE void nrf_ccm_enable(NRF_CCM_Type * p_reg)
428 {
429     p_reg->ENABLE = (CCM_ENABLE_ENABLE_Enabled << CCM_ENABLE_ENABLE_Pos);
430 }
431 
nrf_ccm_disable(NRF_CCM_Type * p_reg)432 NRF_STATIC_INLINE void nrf_ccm_disable(NRF_CCM_Type * p_reg)
433 {
434     p_reg->ENABLE = (CCM_ENABLE_ENABLE_Disabled << CCM_ENABLE_ENABLE_Pos);
435 }
436 
nrf_ccm_configure(NRF_CCM_Type * p_reg,nrf_ccm_config_t const * p_config)437 NRF_STATIC_INLINE void nrf_ccm_configure(NRF_CCM_Type *           p_reg,
438                                          nrf_ccm_config_t const * p_config)
439 {
440     p_reg->MODE = (((uint32_t)p_config->mode     << CCM_MODE_MODE_Pos) |
441 #if defined(CCM_MODE_DATARATE_Pos)
442                    ((uint32_t)p_config->datarate << CCM_MODE_DATARATE_Pos) |
443 #endif
444 #if defined(CCM_MODE_LENGTH_Pos)
445                    ((uint32_t)p_config->length   << CCM_MODE_LENGTH_Pos) |
446 #endif
447                    0);
448 }
449 
450 #if defined(CCM_MAXPACKETSIZE_MAXPACKETSIZE_Pos)
nrf_ccm_maxpacketsize_set(NRF_CCM_Type * p_reg,uint8_t size)451 NRF_STATIC_INLINE void nrf_ccm_maxpacketsize_set(NRF_CCM_Type * p_reg,
452                                                  uint8_t        size)
453 {
454     NRFX_ASSERT((size >= 0x1B) && (size <= 0xFB));
455 
456     p_reg->MAXPACKETSIZE = size;
457 }
458 #endif // defined(CCM_MAXPACKETSIZE_MAXPACKETSIZE_Pos)
459 
nrf_ccm_micstatus_get(NRF_CCM_Type const * p_reg)460 NRF_STATIC_INLINE bool nrf_ccm_micstatus_get(NRF_CCM_Type const * p_reg)
461 {
462     return (bool)(p_reg->MICSTATUS);
463 }
464 
nrf_ccm_cnfptr_set(NRF_CCM_Type * p_reg,uint32_t const * p_data)465 NRF_STATIC_INLINE void nrf_ccm_cnfptr_set(NRF_CCM_Type *   p_reg,
466                                           uint32_t const * p_data)
467 {
468     p_reg->CNFPTR = (uint32_t)p_data;
469 }
470 
nrf_ccm_cnfptr_get(NRF_CCM_Type const * p_reg)471 NRF_STATIC_INLINE uint32_t * nrf_ccm_cnfptr_get(NRF_CCM_Type const * p_reg)
472 {
473 #if defined(NRF5340_XXAA_NETWORK)
474     // Apply workaround for anomaly 10.
475     return (uint32_t *)(p_reg->CNFPTR | 0x01000000);
476 #else
477     return (uint32_t *)(p_reg->CNFPTR);
478 #endif
479 }
480 
nrf_ccm_inptr_set(NRF_CCM_Type * p_reg,uint32_t const * p_data)481 NRF_STATIC_INLINE void nrf_ccm_inptr_set(NRF_CCM_Type *   p_reg,
482                                          uint32_t const * p_data)
483 {
484     p_reg->INPTR = (uint32_t)p_data;
485 }
486 
nrf_ccm_inptr_get(NRF_CCM_Type const * p_reg)487 NRF_STATIC_INLINE uint32_t * nrf_ccm_inptr_get(NRF_CCM_Type const * p_reg)
488 {
489 #if defined(NRF5340_XXAA_NETWORK)
490     // Apply workaround for anomaly 10.
491     return (uint32_t *)(p_reg->INPTR | 0x01000000);
492 #else
493     return (uint32_t *)(p_reg->INPTR);
494 #endif
495 }
496 
nrf_ccm_outptr_set(NRF_CCM_Type * p_reg,uint32_t const * p_data)497 NRF_STATIC_INLINE void nrf_ccm_outptr_set(NRF_CCM_Type *   p_reg,
498                                           uint32_t const * p_data)
499 {
500     p_reg->OUTPTR = (uint32_t)p_data;
501 }
502 
nrf_ccm_outptr_get(NRF_CCM_Type const * p_reg)503 NRF_STATIC_INLINE uint32_t * nrf_ccm_outptr_get(NRF_CCM_Type const * p_reg)
504 {
505 #if defined(NRF5340_XXAA_NETWORK)
506     // Apply workaround for anomaly 10.
507     return (uint32_t *)(p_reg->OUTPTR | 0x01000000);
508 #else
509     return (uint32_t *)(p_reg->OUTPTR);
510 #endif
511 }
512 
nrf_ccm_scratchptr_set(NRF_CCM_Type * p_reg,uint32_t const * p_area)513 NRF_STATIC_INLINE void nrf_ccm_scratchptr_set(NRF_CCM_Type *   p_reg,
514                                               uint32_t const * p_area)
515 {
516     p_reg->SCRATCHPTR = (uint32_t)p_area;
517 }
518 
nrf_ccm_stratchptr_get(NRF_CCM_Type const * p_reg)519 NRF_STATIC_INLINE uint32_t * nrf_ccm_stratchptr_get(NRF_CCM_Type const * p_reg)
520 {
521 #if defined(NRF5340_XXAA_NETWORK)
522     // Apply workaround for anomaly 10.
523     return (uint32_t *)(p_reg->SCRATCHPTR | 0x01000000);
524 #else
525     return (uint32_t *)(p_reg->SCRATCHPTR);
526 #endif
527 }
528 
529 #if defined(CCM_RATEOVERRIDE_RATEOVERRIDE_Pos)
nrf_ccm_datarate_override_set(NRF_CCM_Type * p_reg,nrf_ccm_datarate_t datarate)530 NRF_STATIC_INLINE void nrf_ccm_datarate_override_set(NRF_CCM_Type *     p_reg,
531                                                      nrf_ccm_datarate_t datarate)
532 {
533     p_reg->RATEOVERRIDE = ((uint32_t)datarate << CCM_RATEOVERRIDE_RATEOVERRIDE_Pos);
534 }
535 #endif
536 
537 #endif // NRF_DECLARE_ONLY
538 
539 /** @} */
540 
541 #ifdef __cplusplus
542 }
543 #endif
544 
545 #endif  // NRF_CCM_H__
546