1 /*
2  * Copyright (c) 2018 - 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 
34 #ifndef NRF_CCM_H__
35 #define NRF_CCM_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 #if defined(CCM_MODE_DATARATE_125Kbps)
47 #define NRF_CCM_MODE_DATARATE_125K CCM_MODE_DATARATE_125Kbps
48 #define NRF_CCM_MODE_DATARATE_500K CCM_MODE_DATARATE_500Kbps
49 #else
50 #define NRF_CCM_MODE_DATARATE_125K CCM_MODE_DATARATE_125Kbit
51 #define NRF_CCM_MODE_DATARATE_500K CCM_MODE_DATARATE_500Kbit
52 #endif
53 
54 /**
55  * @defgroup nrf_ccm_hal AES CCM HAL
56  * @{
57  * @ingroup nrf_ccm
58  * @brief   Hardware access layer for managing the AES CCM peripheral.
59  */
60 
61 #if defined(CCM_TASKS_KSGEN_TASKS_KSGEN_Msk) || defined(NRF51) || defined(__NRFX_DOXYGEN__)
62 /** @brief Presence of the KSGEN task. */
63 #define NRF_CCM_HAS_TASK_KSGEN 1
64 #else
65 #define NRF_CCM_HAS_TASK_KSGEN 0
66 #endif
67 
68 #if defined(CCM_TASKS_CRYPT_TASKS_CRYPT_Msk) || defined(NRF51) || defined(__NRFX_DOXYGEN__)
69 /** @brief Presence of the CRYPT task. */
70 #define NRF_CCM_HAS_TASK_CRYPT 1
71 #else
72 #define NRF_CCM_HAS_TASK_CRYPT 0
73 #endif
74 
75 #if defined(CCM_TASKS_RATEOVERRIDE_TASKS_RATEOVERRIDE_Msk) || defined(__NRFX_DOXYGEN__)
76 /** @brief Presence of the RATEOVERRIDE task. */
77 #define NRF_CCM_HAS_TASK_RATEOVERRIDE 1
78 #else
79 #define NRF_CCM_HAS_TASK_RATEOVERRIDE 0
80 #endif
81 
82 #if defined(CCM_EVENTS_ENDKSGEN_EVENTS_ENDKSGEN_Msk) || defined(CCM_INTENSET_ENDKSGEN_Msk) || \
83     defined(__NRFX_DOXYGEN__)
84 /** @brief Presence of the ENDKSGEN event. */
85 #define NRF_CCM_HAS_EVENT_ENDKSGEN 1
86 #else
87 #define NRF_CCM_HAS_EVENT_ENDKSGEN 0
88 #endif
89 
90 #if defined(CCM_EVENTS_ENDCRYPT_EVENTS_ENDCRYPT_Msk) || defined(CCM_INTENSET_ENDCRYPT_Msk) || \
91     defined(__NRFX_DOXYGEN__)
92 /** @brief Presence of the ENDCRYPT event. */
93 #define NRF_CCM_HAS_EVENT_ENDCRYPT 1
94 #else
95 #define NRF_CCM_HAS_EVENT_ENDCRYPT 0
96 #endif
97 
98 #if defined(CCM_ADATAMASK_ADATAMASK_Msk) || defined(__NRFX_DOXYGEN__)
99 /** @brief Presence of the ADATAMASK register. */
100 #define NRF_CCM_HAS_ADATAMASK 1
101 #else
102 #define NRF_CCM_HAS_ADATAMASK 0
103 #endif
104 
105 #if defined(CCM_CNFPTR_CNFPTR_Msk) || defined(__NRFX_DOXYGEN__)
106 /** @brief Presence of the CNFPTR register. */
107 #define NRF_CCM_HAS_CNFPTR 1
108 #else
109 #define NRF_CCM_HAS_CNFPTR 0
110 #endif
111 
112 #if defined(CCM_IN_AMOUNT_AMOUNT_Msk) || defined(__NRFX_DOXYGEN__)
113 /** @brief Presence of the IN.AMOUNT register. */
114 #define NRF_CCM_HAS_IN_AMOUNT 1
115 #else
116 #define NRF_CCM_HAS_IN_AMOUNT 0
117 #endif
118 
119 #if defined(CCM_OUT_AMOUNT_AMOUNT_Msk) || defined(__NRFX_DOXYGEN__)
120 /** @brief Presence of the OUT.AMOUNT register. */
121 #define NRF_CCM_HAS_OUT_AMOUNT 1
122 #else
123 #define NRF_CCM_HAS_OUT_AMOUNT 0
124 #endif
125 
126 #if defined(CCM_RATEOVERRIDE_RATEOVERRIDE_Pos) || defined(__NRFX_DOXYGEN__)
127 /** @brief Presence of the RATEOVERRIDE register. */
128 #define NRF_CCM_HAS_RATEOVERRIDE 1
129 #else
130 #define NRF_CCM_HAS_RATEOVERRIDE 0
131 #endif
132 
133 #if defined(CCM_ERRORSTATUS_ERRORSTATUS_Msk) || defined(__NRFX_DOXYGEN__)
134 /** @brief Presence of the ERRORSTATUS register. */
135 #define NRF_CCM_HAS_ERRORSTATUS 1
136 #else
137 #define NRF_CCM_HAS_ERRORSTATUS 0
138 #endif
139 
140 #if defined(CCM_MICSTATUS_MICSTATUS_Msk) || defined(__NRFX_DOXYGEN__)
141 /** @brief Presence of the MICSTATUS register. */
142 #define NRF_CCM_HAS_MICSTATUS 1
143 #else
144 #define NRF_CCM_HAS_MICSTATUS 0
145 #endif
146 
147 #if defined(CCM_MACSTATUS_MACSTATUS_Msk) || defined(__NRFX_DOXYGEN__)
148 /** @brief Presence of the MACSTATUS register. */
149 #define NRF_CCM_HAS_MACSTATUS 1
150 #else
151 #define NRF_CCM_HAS_MACSTATUS 0
152 #endif
153 
154 #if defined(CCM_KEY_VALUE_VALUE_Msk) || defined(__NRFX_DOXYGEN__)
155 /** @brief Presence of the KEY register. */
156 #define NRF_CCM_HAS_KEY 1
157 #else
158 #define NRF_CCM_HAS_KEY 0
159 #endif
160 
161 #if defined(CCM_NONCE_VALUE_VALUE_Msk) || defined(__NRFX_DOXYGEN__)
162 /** @brief Presence of the NONCE register. */
163 #define NRF_CCM_HAS_NONCE 1
164 #else
165 #define NRF_CCM_HAS_NONCE 0
166 #endif
167 
168 #if defined(CCM_INPTR_INPTR_Msk) || defined(__NRFX_DOXYGEN__)
169 /** @brief Presence of the INPTR register. */
170 #define NRF_CCM_HAS_INPTR 1
171 #else
172 #define NRF_CCM_HAS_INPTR 0
173 #endif
174 
175 #if defined(CCM_OUTPTR_OUTPTR_Msk) || defined(__NRFX_DOXYGEN__)
176 /** @brief Presence of the OUTPTR register. */
177 #define NRF_CCM_HAS_OUTPTR 1
178 #else
179 #define NRF_CCM_HAS_OUTPTR 0
180 #endif
181 
182 #if defined(CCM_IN_PTR_PTR_Msk) || defined(__NRFX_DOXYGEN__)
183 /** @brief Presence of the IN.PTR register. */
184 #define NRF_CCM_HAS_IN_PTR 1
185 #else
186 #define NRF_CCM_HAS_IN_PTR 0
187 #endif
188 
189 #if defined(CCM_OUT_PTR_PTR_Msk) || defined(__NRFX_DOXYGEN__)
190 /** @brief Presence of the OUT.PTR register. */
191 #define NRF_CCM_HAS_OUT_PTR 1
192 #else
193 #define NRF_CCM_HAS_OUT_PTR 0
194 #endif
195 
196 #if defined(CCM_SCRATCHPTR_SCRATCHPTR_Msk) || defined(__NRFX_DOXYGEN__)
197 /** @brief Presence of the SCRATCHPTR register. */
198 #define NRF_CCM_HAS_SCRATCHPTR 1
199 #else
200 #define NRF_CCM_HAS_SCRATCHPTR 0
201 #endif
202 
203 #if defined(CCM_MAXPACKETSIZE_MAXPACKETSIZE_Pos) || defined(__NRFX_DOXYGEN__)
204 /** @brief Presence of the MAXPACKETSIZE. */
205 #define NRF_CCM_HAS_MAXPACKETSIZE 1
206 #else
207 #define NRF_CCM_HAS_MAXPACKETSIZE 0
208 #endif
209 
210 #if defined(CCM_MODE_MODE_FastDecryption) || defined(__NRFX_DOXYGEN__)
211 /** Presence of AES fast decrypt mode. */
212 #define NRF_CCM_HAS_MODE_FAST_DECRYPTION 1
213 #else
214 #define NRF_CCM_HAS_MODE_FAST_DECRYPTION 0
215 #endif
216 
217 #if defined(CCM_MODE_PROTOCOL_Msk) || defined(__NRFX_DOXYGEN__)
218 /** @brief Presence of protocol and packet format selection. */
219 #define NRF_CCM_HAS_MODE_PROTOCOL 1
220 #else
221 #define NRF_CCM_HAS_MODE_PROTOCOL 0
222 #endif
223 
224 #if defined(CCM_MODE_PROTOCOL_Ble) || defined(__NRFX_DOXYGEN__)
225 /** @brief Presence of the BLE packet format. */
226 #define NRF_CCM_HAS_MODE_PROTOCOL_BLE 1
227 #else
228 #define NRF_CCM_HAS_MODE_PROTOCOL_BLE 0
229 #endif
230 
231 #if defined(CCM_MODE_PROTOCOL_Ieee802154) || defined(__NRFX_DOXYGEN__)
232 /** @brief Presence of the 802.15.4 packet format. */
233 #define NRF_CCM_HAS_MODE_PROTOCOL_IEEE802154 1
234 #else
235 #define NRF_CCM_HAS_MODE_PROTOCOL_IEEE802154 0
236 #endif
237 
238 #if defined(CCM_MODE_LENGTH_Msk) || defined(__NRFX_DOXYGEN__)
239 /** @brief Presence of the packet lengh configuration. */
240 #define NRF_CCM_HAS_MODE_LENGTH 1
241 #else
242 #define NRF_CCM_HAS_MODE_LENGTH 0
243 #endif
244 
245 #if defined(CCM_MODE_DATARATE_125Kbit) || defined(CCM_MODE_DATARATE_125Kbps) || \
246     defined(__NRFX_DOXYGEN__)
247 /** @brief Support for 125 Kbit radio data rate. */
248 #define NRF_CCM_HAS_MODE_DATARATE_125K 1
249 #else
250 #define NRF_CCM_HAS_MODE_DATARATE_125K 0
251 #endif
252 
253 #if defined(CCM_MODE_DATARATE_250Kbit) || defined(__NRFX_DOXYGEN__)
254 /** @brief Support for 250 Kbit radio data rate. */
255 #define NRF_CCM_HAS_MODE_DATARATE_250K 1
256 #else
257 #define NRF_CCM_HAS_MODE_DATARATE_250K 0
258 #endif
259 
260 #if defined(CCM_MODE_DATARATE_500Kbit) || defined(CCM_MODE_DATARATE_500Kbps) || \
261     defined(__NRFX_DOXYGEN__)
262 /** @brief Support for 500 Kbit radio data rate. */
263 #define NRF_CCM_HAS_MODE_DATARATE_500K 1
264 #else
265 #define NRF_CCM_HAS_MODE_DATARATE_500K 0
266 #endif
267 
268 #if defined(CCM_MODE_DATARATE_4Mbit) || defined(__NRFX_DOXYGEN__)
269 /** @brief Support for 4 Mbit radio data rate. */
270 #define NRF_CCM_HAS_MODE_DATARATE_4M 1
271 #else
272 #define NRF_CCM_HAS_MODE_DATARATE_4M 0
273 #endif
274 
275 #if defined(CCM_MODE_MACLEN_Msk) || defined(__NRFX_DOXYGEN__)
276 /** @brief Presence of the CCM MAC length. */
277 #define NRF_CCM_HAS_MODE_MACLEN 1
278 #else
279 #define NRF_CCM_HAS_MODE_MACLEN 0
280 #endif
281 
282 #if defined(CCM_MODE_DATARATE_Pos) || defined(__NRFX_DOXYGEN__)
283 /** @brief Presence of the radio data rate that the CCM shall run synchronous with. */
284 #define NRF_CCM_HAS_DATARATE 1
285 #else
286 #define NRF_CCM_HAS_DATARATE 0
287 #endif
288 
289 #if defined(CCM_HEADERMASK_HEADERMASK_Msk) || defined(__NRFX_DOXYGEN__)
290 /** @brief Presence of the HEADERMASK register. */
291 #define NRF_CCM_HAS_HEADERMASK 1
292 #else
293 #define NRF_CCM_HAS_HEADERMASK 0
294 #endif
295 
296 #if NRF_CCM_HAS_CNFPTR
297 /** @brief AES key size. */
298 #define NRF_CCM_KEY_SIZE    16
299 /** @brief Initialization vector size. */
300 #define NRF_CCM_IV_SIZE     8
301 /** @brief Packet counter configuration size. */
302 #define NRF_CCM_PKTCTR_SIZE 9
303 
304 /** @brief CCM data structure. */
305 typedef struct __PACKED
306 {
307     uint8_t key[NRF_CCM_KEY_SIZE];       ///< 16-byte AES key.
308     uint8_t pktctr[NRF_CCM_PKTCTR_SIZE]; ///< Packet counter configuration.
309     uint8_t iv[NRF_CCM_IV_SIZE];         ///< 8-byte initialization vector (IV).
310 } nrf_ccm_cnf_t;
311 #endif
312 
313 /** @brief CCM tasks. */
314 typedef enum
315 {
316 #if NRF_CCM_HAS_TASK_KSGEN
317     NRF_CCM_TASK_KSGEN        = offsetof(NRF_CCM_Type, TASKS_KSGEN),        ///< Start generation of key-stream.
318 #endif
319 #if NRF_CCM_HAS_TASK_CRYPT
320     NRF_CCM_TASK_START        = offsetof(NRF_CCM_Type, TASKS_CRYPT),        ///< Start encryption/decryption.
321 #else
322     NRF_CCM_TASK_START        = offsetof(NRF_CCM_Type, TASKS_START),        ///< Start encryption/decryption.
323 #endif
324     NRF_CCM_TASK_STOP         = offsetof(NRF_CCM_Type, TASKS_STOP),         ///< Stop encryption/decryption.
325 #if NRF_CCM_HAS_TASK_RATEOVERRIDE
326     NRF_CCM_TASK_RATEOVERRIDE = offsetof(NRF_CCM_Type, TASKS_RATEOVERRIDE), ///< Override DATARATE setting in MODE register.
327 #endif
328 } nrf_ccm_task_t;
329 
330 /** @brief CCM events. */
331 typedef enum
332 {
333 #if NRF_CCM_HAS_EVENT_ENDKSGEN
334     NRF_CCM_EVENT_ENDKSGEN = offsetof(NRF_CCM_Type, EVENTS_ENDKSGEN),  ///< Keystream generation complete.
335 #endif
336 #if NRF_CCM_HAS_EVENT_ENDCRYPT
337     NRF_CCM_EVENT_END      = offsetof(NRF_CCM_Type, EVENTS_ENDCRYPT),  ///< Encrypt/decrypt complete.
338 #else
339     NRF_CCM_EVENT_END      = offsetof(NRF_CCM_Type, EVENTS_END),       ///< Encrypt/decrypt complete.
340 #endif
341     NRF_CCM_EVENT_ERROR    = offsetof(NRF_CCM_Type, EVENTS_ERROR),     ///< CCM error event.
342 } nrf_ccm_event_t;
343 
344 #if NRF_CCM_HAS_EVENT_ENDKSGEN
345 /** @brief Types of CCM shorts. */
346 typedef enum
347 {
348     NRF_CCM_SHORT_ENDKSGEN_START_MASK = CCM_SHORTS_ENDKSGEN_CRYPT_Msk, ///< Shortcut for starting encryption/decryption when the key-stream generation is complete.
349 } nrf_ccm_short_mask_t;
350 #endif // NRF_CCM_HAS_EVENT_ENDKSGEN
351 
352 /** @brief CCM interrupts. */
353 typedef enum
354 {
355 #if NRF_CCM_HAS_EVENT_ENDKSGEN
356     NRF_CCM_INT_ENDKSGEN_MASK = CCM_INTENSET_ENDKSGEN_Msk,  ///< Interrupt on ENDKSGEN event.
357 #endif
358 #if NRF_CCM_HAS_EVENT_ENDCRYPT
359     NRF_CCM_INT_END_MASK      = CCM_INTENSET_ENDCRYPT_Msk,  ///< Interrupt on encrypt/decrypt complete event.
360 #else
361     NRF_CCM_INT_END_MASK      = CCM_INTENSET_END_Msk,       ///< Interrupt on encrypt/decrypt complete event.
362 #endif
363     NRF_CCM_INT_ERROR_MASK    = CCM_INTENSET_ERROR_Msk,     ///< Interrupt on ERROR event.
364 } nrf_ccm_int_mask_t;
365 
366 #if NRF_CCM_HAS_ERRORSTATUS
367 /** @brief CCM error status when ERROR event is generated. */
368 typedef enum
369 {
370     NRF_CCM_ERROR_NO_ERROR             = CCM_ERRORSTATUS_ERRORSTATUS_NoError,            ///< No errors have occurred.
371     NRF_CCM_ERROR_PREMATURE_INPTR_END  = CCM_ERRORSTATUS_ERRORSTATUS_PrematureInptrEnd,  ///< End of INPTR job list before CCM data structure was read.
372     NRF_CCM_ERROR_PREMATURE_OUTPTR_END = CCM_ERRORSTATUS_ERRORSTATUS_PrematureOutptrEnd, ///< End of OUTPTR job list before CCM data structure was read.
373     NRF_CCM_ERROR_ENCRYPTION_TOO_SLOW  = CCM_ERRORSTATUS_ERRORSTATUS_EncryptionTooSlow,  ///< Encryption did not complete in time.
374 } nrf_ccm_error_t;
375 #endif
376 
377 /** @brief CCM modes of operation. */
378 typedef enum
379 {
380     NRF_CCM_MODE_ENCRYPTION      = CCM_MODE_MODE_Encryption,     ///< Encryption mode.
381     NRF_CCM_MODE_DECRYPTION      = CCM_MODE_MODE_Decryption,     ///< Decryption mode.
382 #if NRF_CCM_HAS_MODE_FAST_DECRYPTION
383     NRF_CCM_MODE_FAST_DECRYPTION = CCM_MODE_MODE_FastDecryption, ///< Fast decryption mode.
384 #endif
385 } nrf_ccm_mode_t;
386 
387 #if NRF_CCM_HAS_DATARATE
388 /** @brief CCM data rates. */
389 typedef enum
390 {
391 #if NRF_CCM_HAS_MODE_DATARATE_125K
392     NRF_CCM_DATARATE_125K = NRF_CCM_MODE_DATARATE_125K, ///< 125 Kbps.
393 #endif
394 #if NRF_CCM_HAS_MODE_DATARATE_250K
395     NRF_CCM_DATARATE_250K = CCM_MODE_DATARATE_250Kbit,  ///< 250 Kbps.
396 #endif
397 #if NRF_CCM_HAS_MODE_DATARATE_500K
398     NRF_CCM_DATARATE_500K = NRF_CCM_MODE_DATARATE_500K, ///< 500 Kbps.
399 #endif
400     NRF_CCM_DATARATE_1M   = CCM_MODE_DATARATE_1Mbit,    ///< 1 Mbps.
401     NRF_CCM_DATARATE_2M   = CCM_MODE_DATARATE_2Mbit,    ///< 2 Mbps.
402 #if NRF_CCM_HAS_MODE_DATARATE_4M
403     NRF_CCM_DATARATE_4M   = CCM_MODE_DATARATE_4Mbit,    ///< 4 Mbps.
404 #endif
405 } nrf_ccm_datarate_t;
406 #endif // NRF_CCM_HAS_DATARATE
407 
408 #if NRF_CCM_HAS_MODE_PROTOCOL
409 /** @brief CCM protocol and packet format. */
410 typedef enum
411 {
412 #if NRF_CCM_HAS_MODE_PROTOCOL_BLE
413     NRF_CCM_MODE_PROTOCOL_BLE        = CCM_MODE_PROTOCOL_Ble,        ///< BLE packet format.
414 #endif
415 #if NRF_CCM_HAS_MODE_PROTOCOL_IEEE802154
416     NRF_CCM_MODE_PROTOCOL_IEEE802154 = CCM_MODE_PROTOCOL_Ieee802154, ///< 802.15.4 packet format.
417 #endif
418 } nrf_ccm_protocol_t;
419 #endif // NRF_CCM_HAS_MODE_PROTOCOL
420 
421 #if NRF_CCM_HAS_MODE_LENGTH
422 /** @brief CCM packet length options. */
423 typedef enum
424 {
425     NRF_CCM_LENGTH_DEFAULT  = CCM_MODE_LENGTH_Default,  ///< Default length.
426     NRF_CCM_LENGTH_EXTENDED = CCM_MODE_LENGTH_Extended, ///< Extended length.
427 } nrf_ccm_length_t;
428 #endif // NRF_CCM_HAS_MODE_LENGTH
429 
430 #if NRF_CCM_HAS_MODE_MACLEN
431 /** @brief CCM MAC length. */
432 typedef enum
433 {
434     NRF_CCM_MODE_MACLEN_M0  = CCM_MODE_MACLEN_M0,  ///< 0 bytes.
435     NRF_CCM_MODE_MACLEN_M4  = CCM_MODE_MACLEN_M4,  ///< 4 bytes.
436     NRF_CCM_MODE_MACLEN_M6  = CCM_MODE_MACLEN_M6,  ///< 6 bytes.
437     NRF_CCM_MODE_MACLEN_M8  = CCM_MODE_MACLEN_M8,  ///< 8 bytes.
438     NRF_CCM_MODE_MACLEN_M10 = CCM_MODE_MACLEN_M10, ///< 10 bytes.
439     NRF_CCM_MODE_MACLEN_M12 = CCM_MODE_MACLEN_M12, ///< 12 bytes.
440     NRF_CCM_MODE_MACLEN_M14 = CCM_MODE_MACLEN_M14, ///< 14 bytes.
441     NRF_CCM_MODE_MACLEN_M16 = CCM_MODE_MACLEN_M16, ///< 16 bytes.
442 } nrf_ccm_maclen_t;
443 #endif // NRF_CCM_HAS_MODE_MACLEN
444 
445 /** @brief CCM configuration. */
446 typedef struct
447 {
448     nrf_ccm_mode_t     mode;       ///< Operation mode.
449 #if NRF_CCM_HAS_MODE_PROTOCOL
450     nrf_ccm_protocol_t protocol;   ///< Protocol and packet format.
451 #endif
452 #if NRF_CCM_HAS_DATARATE
453     nrf_ccm_datarate_t datarate;   ///< Data rate.
454 #endif
455 #if NRF_CCM_HAS_MODE_LENGTH
456     nrf_ccm_length_t   length;     ///< Length of the CCM packet.
457 #endif
458 #if NRF_CCM_HAS_MODE_MACLEN
459     nrf_ccm_maclen_t   mac_length; ///< Length of the CCM MAC.
460 #endif
461 } nrf_ccm_config_t;
462 
463 /**
464  * @brief Function for activating a specific CCM task.
465  *
466  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
467  * @param[in] task  Task to be activated.
468  */
469 NRF_STATIC_INLINE void nrf_ccm_task_trigger(NRF_CCM_Type * p_reg,
470                                             nrf_ccm_task_t task);
471 
472 /**
473  * @brief Function for getting the address of a specific CCM task register.
474  *
475  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
476  * @param[in] task  Requested task.
477  *
478  * @return Address of the specified task register.
479  */
480 NRF_STATIC_INLINE uint32_t nrf_ccm_task_address_get(NRF_CCM_Type const * p_reg,
481                                                     nrf_ccm_task_t       task);
482 
483 /**
484  * @brief Function for clearing a specific CCM event.
485  *
486  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
487  * @param[in] event Event to clear.
488  */
489 NRF_STATIC_INLINE void nrf_ccm_event_clear(NRF_CCM_Type *  p_reg,
490                                            nrf_ccm_event_t event);
491 
492 /**
493  * @brief Function for retrieving the state of a specific CCM event.
494  *
495  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
496  * @param[in] event Event to be checked.
497  *
498  * @retval true  The event has been generated.
499  * @retval false The event has not been generated.
500  */
501 NRF_STATIC_INLINE bool nrf_ccm_event_check(NRF_CCM_Type const * p_reg,
502                                            nrf_ccm_event_t      event);
503 
504 /**
505  * @brief Function for getting the address of a specific CCM event register.
506  *
507  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
508  * @param[in] event Requested event.
509  *
510  * @return Address of the specified event register.
511  */
512 NRF_STATIC_INLINE uint32_t nrf_ccm_event_address_get(NRF_CCM_Type const * p_reg,
513                                                      nrf_ccm_event_t      event);
514 
515 #if NRF_CCM_HAS_EVENT_ENDKSGEN
516 /**
517  * @brief Function for enabling the specified shortcuts.
518  *
519  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
520  * @param[in] mask  Shortcuts to be enabled.
521  */
522 NRF_STATIC_INLINE void nrf_ccm_shorts_enable(NRF_CCM_Type * p_reg,
523                                              uint32_t       mask);
524 
525 /**
526  * @brief Function for disabling the specified shortcuts.
527  *
528  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
529  * @param[in] mask  Shortcuts to be disabled.
530  */
531 NRF_STATIC_INLINE void nrf_ccm_shorts_disable(NRF_CCM_Type * p_reg,
532                                               uint32_t       mask);
533 
534 /**
535  * @brief Function for setting the specified shortcuts.
536  *
537  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
538  * @param[in] mask  Shortcuts to be set.
539  */
540 NRF_STATIC_INLINE void nrf_ccm_shorts_set(NRF_CCM_Type * p_reg,
541                                           uint32_t       mask);
542 #endif // NRF_CCM_HAS_EVENT_ENDKSGEN
543 
544 /**
545  * @brief Function for enabling specified interrupts.
546  *
547  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
548  * @param[in] mask  Mask of interrupts to be enabled.
549  *                  Use @ref nrf_ccm_int_mask_t values for bit masking.
550  */
551 NRF_STATIC_INLINE void nrf_ccm_int_enable(NRF_CCM_Type * p_reg, uint32_t mask);
552 
553 /**
554  * @brief Function for disabling specified interrupts.
555  *
556  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
557  * @param[in] mask  Mask of interrupts to be disabled.
558  *                  Use @ref nrf_ccm_int_mask_t values for bit masking.
559  */
560 NRF_STATIC_INLINE void nrf_ccm_int_disable(NRF_CCM_Type * p_reg, uint32_t mask);
561 
562 /**
563  * @brief Function for checking if the specified interrupts are enabled.
564  *
565  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
566  * @param[in] mask  Mask of interrupts to be checked.
567  *                  Use @ref nrf_ccm_int_mask_t values for bit masking.
568  *
569  * @return Mask of enabled interrupts.
570  */
571 NRF_STATIC_INLINE uint32_t nrf_ccm_int_enable_check(NRF_CCM_Type const * p_reg, uint32_t mask);
572 
573 /**
574  * @brief Function for enabling the CCM peripheral.
575  *
576  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
577  */
578 NRF_STATIC_INLINE void nrf_ccm_enable(NRF_CCM_Type * p_reg);
579 
580 /**
581  * @brief Function for disabling the CCM peripheral.
582  *
583  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
584  */
585 NRF_STATIC_INLINE void nrf_ccm_disable(NRF_CCM_Type * p_reg);
586 
587 /**
588  * @brief Function for setting the CCM peripheral configuration.
589  *
590  * @param[in] p_reg    Pointer to the structure of registers of the peripheral.
591  * @param[in] p_config Pointer to the structure with configuration to be set.
592  */
593 NRF_STATIC_INLINE void nrf_ccm_configure(NRF_CCM_Type *           p_reg,
594                                          nrf_ccm_config_t const * p_config);
595 
596 #if NRF_CCM_HAS_MAXPACKETSIZE
597 /**
598  * @brief Function for setting the length of key-stream generated
599  *        when the packet length is configured as extended.
600  *
601  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
602  * @param[in] size  Maximum length of the key-stream.
603  */
604 NRF_STATIC_INLINE void nrf_ccm_maxpacketsize_set(NRF_CCM_Type * p_reg,
605                                                  uint8_t        size);
606 #endif // NRF_CCM_HAS_MAXPACKETSIZE
607 
608 #if NRF_CCM_HAS_MICSTATUS
609 /**
610  * @brief Function for getting the MIC check result.
611  *
612  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
613  *
614  * @retval true  The MIC check passed.
615  * @retval false The MIC check failed.
616  */
617 NRF_STATIC_INLINE bool nrf_ccm_micstatus_get(NRF_CCM_Type const * p_reg);
618 #endif // NRF_CCM_HAS_MICSTATUS
619 
620 #if NRF_CCM_HAS_MACSTATUS
621 /**
622  * @brief Function for getting the MAC check result.
623  *
624  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
625  *
626  * @retval true  The MAC check passed.
627  * @retval false The MAC check failed.
628  */
629 NRF_STATIC_INLINE bool nrf_ccm_macstatus_get(NRF_CCM_Type const * p_reg);
630 #endif // NRF_CCM_HAS_MACSTATUS
631 
632 #if NRF_CCM_HAS_ERRORSTATUS
633 /**
634  * @brief Function for getting the error status when ERROR event is generated.
635  *
636  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
637  *
638  * @retval Error status when the ERROR event is generated.
639  */
640 NRF_STATIC_INLINE nrf_ccm_error_t nrf_ccm_errorstatus_get(NRF_CCM_Type const * p_reg);
641 #endif // NRF_CCM_HAS_ERRORSTATUS
642 
643 #if NRF_CCM_HAS_CNFPTR
644 /**
645  * @brief Function for setting the pointer to the data structure
646  *        holding the AES key and the CCM NONCE vector.
647  *
648  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
649  * @param[in] p_data Pointer to the data structure.
650  */
651 NRF_STATIC_INLINE void nrf_ccm_cnfptr_set(NRF_CCM_Type *        p_reg,
652                                           nrf_ccm_cnf_t const * p_data);
653 
654 /**
655  * @brief Function for getting the pointer to the data structure
656  *        holding the AES key and the CCM NONCE vector.
657  *
658  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
659  *
660  * @return Pointer to the data structure.
661  */
662 NRF_STATIC_INLINE nrf_ccm_cnf_t * nrf_ccm_cnfptr_get(NRF_CCM_Type const * p_reg);
663 #endif // NRF_CCM_HAS_CNFPTR
664 
665 #if NRF_CCM_HAS_KEY
666 /**
667  * @brief Function for setting the AES key.
668  *
669  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
670  * @param[in] p_key Pointer to the AES 128-bit key value. The key shall be stored
671  *                  in big endian byte order.
672  */
673 NRF_STATIC_INLINE void nrf_ccm_key_set(NRF_CCM_Type   * p_reg,
674                                        uint32_t const * p_key);
675 /**
676  * @brief Function for getting the AES key.
677  *
678  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
679  *
680  * @return Pointer to the AES 128-bit key value. The key is stored in big endian byte order.
681  */
682 NRF_STATIC_INLINE uint32_t const volatile * nrf_ccm_key_get(NRF_CCM_Type const * p_reg);
683 
684 #endif // NRF_CCM_HAS_KEY
685 
686 #if NRF_CCM_HAS_NONCE
687 /**
688  * @brief Function for setting the AES nonce.
689  *
690  * @param[in] p_reg   Pointer to the structure of registers of the peripheral.
691  * @param[in] p_nonce Pointer to the AES 13-byte nonce value. The nonce shall be stored
692  *                    in big endian byte order.
693  */
694 NRF_STATIC_INLINE void nrf_ccm_nonce_set(NRF_CCM_Type *   p_reg,
695                                          uint32_t const * p_nonce);
696 
697 /**
698  * @brief Function for getting the AES nonce.
699  *
700  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
701  *
702  * @return Pointer to the AES 13-byte nonce value. The nonce is stored in big endian byte order.
703  */
704 NRF_STATIC_INLINE uint32_t const volatile * nrf_ccm_nonce_get(NRF_CCM_Type const * p_reg);
705 #endif // NRF_CCM_HAS_NONCE
706 
707 #if NRF_CCM_HAS_IN_AMOUNT
708 /**
709  * @brief Function for getting number of bytes read from the input data,
710  *        not including the job list structure.
711  *
712  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
713  *
714  * @return Number of bytes read from the input data.
715  */
716 NRF_STATIC_INLINE uint32_t nrf_ccm_in_amount_get(NRF_CCM_Type const * p_reg);
717 #endif // NRF_CCM_HAS_IN_AMOUNT
718 
719 #if NRF_CCM_HAS_INPTR
720 /**
721  * @brief Function for setting the input data pointer.
722  *
723  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
724  * @param[in] p_data Input data pointer.
725  */
726 NRF_STATIC_INLINE void nrf_ccm_inptr_set(NRF_CCM_Type *   p_reg,
727                                          uint32_t const * p_data);
728 
729 /**
730  * @brief Function for getting the input data pointer.
731  *
732  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
733  *
734  * @return Input data pointer.
735  */
736 NRF_STATIC_INLINE uint32_t * nrf_ccm_inptr_get(NRF_CCM_Type const * p_reg);
737 #endif // NRF_CCM_HAS_INPTR
738 
739 #if NRF_CCM_HAS_IN_PTR
740 /**
741  * @brief Function for setting the pointer to a job list containing unencrypted
742  *        CCM data structure in Encryption mode or encrypted CCM data structure
743  *        in Decryption mode.
744  *
745  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
746  * @param[in] p_job Pointer to a job list.
747  */
748 NRF_STATIC_INLINE void nrf_ccm_in_ptr_set(NRF_CCM_Type *         p_reg,
749                                           nrf_vdma_job_t const * p_job);
750 
751 /**
752  * @brief Function for getting the pointer to job list containing unencrypted
753  *        CCM data structure in Encryption mode or encrypted CCM data structure
754  *        in Decryption mode.
755  *
756  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
757  *
758  * @return Pointer to a job list.
759  */
760 NRF_STATIC_INLINE nrf_vdma_job_t * nrf_ccm_in_ptr_get(NRF_CCM_Type const * p_reg);
761 #endif // NRF_CCM_HAS_IN_PTR
762 
763 #if NRF_CCM_HAS_OUTPTR
764 /**
765  * @brief Function for setting the output data pointer.
766  *
767  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
768  * @param[in] p_data Output data pointer.
769  */
770 NRF_STATIC_INLINE void nrf_ccm_outptr_set(NRF_CCM_Type *   p_reg,
771                                           uint32_t const * p_data);
772 
773 /**
774  * @brief Function for getting the output data pointer.
775  *
776  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
777  *
778  * @return Output data pointer.
779  */
780 NRF_STATIC_INLINE uint32_t * nrf_ccm_outptr_get(NRF_CCM_Type const * p_reg);
781 #endif // NRF_CCM_HAS_OUTPTR
782 
783 #if NRF_CCM_HAS_OUT_PTR
784 /**
785  * @brief Function for setting the pointer to a job list containing encrypted
786  *        CCM data structure in Encryption mode or decrypted CCM data structure
787  *        in Decryption mode.
788  *
789  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
790  * @param[in] p_job Pointer to a job list.
791  */
792 NRF_STATIC_INLINE void nrf_ccm_out_ptr_set(NRF_CCM_Type *         p_reg,
793                                            nrf_vdma_job_t const * p_job);
794 
795 /**
796  * @brief Function for getting the pointer to a job list containing encrypted
797  *        CCM data structure in Encryption mode or decrypted CCM data structure
798  *        in Decryption mode.
799  *
800  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
801  *
802  * @return Pointer to the job list.
803  */
804 NRF_STATIC_INLINE nrf_vdma_job_t * nrf_ccm_out_ptr_get(NRF_CCM_Type const * p_reg);
805 #endif // NRF_CCM_HAS_OUT_PTR
806 
807 #if NRF_CCM_HAS_OUT_AMOUNT
808 /**
809  * @brief Function for getting number of bytes available in the output data,
810  *        not including the job list structure.
811  *
812  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
813  *
814  * @return Number of bytes available in the output data.
815  */
816 NRF_STATIC_INLINE uint32_t nrf_ccm_out_amount_get(NRF_CCM_Type const * p_reg);
817 #endif // NRF_CCM_HAS_OUT_AMOUNT
818 
819 #if NRF_CCM_HAS_SCRATCHPTR
820 /**
821  * @brief Function for setting the pointer to the scratch area used for
822  *        temporary storage.
823  *
824  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
825  * @param[in] p_area Pointer to the scratch area.
826  */
827 NRF_STATIC_INLINE void nrf_ccm_scratchptr_set(NRF_CCM_Type *   p_reg,
828                                               uint32_t const * p_area);
829 
830 /**
831  * @brief Function for getting the pointer to the scratch area.
832  *
833  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
834  *
835  * @return Pointer to the scratch area.
836  */
837 NRF_STATIC_INLINE uint32_t * nrf_ccm_scratchptr_get(NRF_CCM_Type const * p_reg);
838 #endif // NRF_CCM_HAS_SCRATCHPTR
839 
840 #if NRF_CCM_HAS_RATEOVERRIDE
841 /**
842  * @brief Function for setting the data rate override value.
843  *
844  * @param[in] p_reg    Pointer to the structure of registers of the peripheral.
845  * @param[in] datarate Override value to be applied when the RATEOVERRIDE task
846  *                     is triggered.
847  */
848 NRF_STATIC_INLINE void nrf_ccm_datarate_override_set(NRF_CCM_Type *     p_reg,
849                                                      nrf_ccm_datarate_t datarate);
850 
851 /**
852  * @brief Function for getting data override setting.
853  *
854  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
855  *
856  * @return Data override setting.
857  */
858 NRF_STATIC_INLINE nrf_ccm_datarate_t nrf_ccm_datarate_override_get(NRF_CCM_Type const * p_reg);
859 #endif // NRF_CCM_HAS_RATEOVERRIDE
860 
861 #if NRF_CCM_HAS_ADATAMASK
862 /**
863  * @brief Function for setting the CCM adata mask.
864  *
865  * @param[in] p_reg     Pointer to the structure of registers of the peripheral.
866  * @param[in] adata_msk CCM adata mask.
867  */
868 NRF_STATIC_INLINE void nrf_ccm_adatamask_set(NRF_CCM_Type * p_reg,
869                                              uint8_t        adata_msk);
870 
871 /**
872  * @brief Function for getting bitmask for the first adata byte.
873  *
874  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
875  *
876  * @return CCM adata mask.
877  */
878 NRF_STATIC_INLINE uint32_t nrf_ccm_adatamask_get(NRF_CCM_Type const * p_reg);
879 #endif // NRF_CCM_HAS_ADATAMASK
880 
881 #if NRF_CCM_HAS_HEADERMASK
882 /**
883  * @brief Function for setting the CCM header mask.
884  *
885  * @param[in] p_reg      Pointer to the structure of registers of the peripheral.
886  * @param[in] header_msk CCM header mask.
887  */
888 NRF_STATIC_INLINE void nrf_ccm_headermask_set(NRF_CCM_Type * p_reg,
889                                               uint8_t        header_msk);
890 
891 /**
892  * @brief Function for getting the bitmask for packet header (S0) before MIC
893  *        generation/authentication.
894  *
895  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
896  *
897  * @return CCM header mask.
898  */
899 NRF_STATIC_INLINE uint32_t nrf_ccm_headermask_get(NRF_CCM_Type const * p_reg);
900 #endif // NRF_CCM_HAS_HEADERMASK
901 
902 #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
903 /**
904  * @brief Function for setting the subscribe configuration for a given
905  *        CCM task.
906  *
907  * @param[in] p_reg   Pointer to the structure of registers of the peripheral.
908  * @param[in] task    Task for which to set the configuration.
909  * @param[in] channel Channel through which to subscribe events.
910  */
911 NRF_STATIC_INLINE void nrf_ccm_subscribe_set(NRF_CCM_Type * p_reg,
912                                              nrf_ccm_task_t task,
913                                              uint8_t        channel);
914 
915 /**
916  * @brief Function for clearing the subscribe configuration for a given
917  *        CCM task.
918  *
919  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
920  * @param[in] task  Task for which to clear the configuration.
921  */
922 NRF_STATIC_INLINE void nrf_ccm_subscribe_clear(NRF_CCM_Type * p_reg,
923                                                nrf_ccm_task_t task);
924 
925 /**
926  * @brief Function for setting the publish configuration for a given
927  *        CCM event.
928  *
929  * @param[in] p_reg   Pointer to the structure of registers of the peripheral.
930  * @param[in] event   Event for which to set the configuration.
931  * @param[in] channel Channel through which to publish the event.
932  */
933 NRF_STATIC_INLINE void nrf_ccm_publish_set(NRF_CCM_Type *  p_reg,
934                                            nrf_ccm_event_t event,
935                                            uint8_t         channel);
936 
937 /**
938  * @brief Function for clearing the publish configuration for a given
939  *        CCM event.
940  *
941  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
942  * @param[in] event Event for which to clear the configuration.
943  */
944 NRF_STATIC_INLINE void nrf_ccm_publish_clear(NRF_CCM_Type *  p_reg,
945                                              nrf_ccm_event_t event);
946 #endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
947 
948 #ifndef NRF_DECLARE_ONLY
949 
nrf_ccm_task_trigger(NRF_CCM_Type * p_reg,nrf_ccm_task_t task)950 NRF_STATIC_INLINE void nrf_ccm_task_trigger(NRF_CCM_Type * p_reg,
951                                             nrf_ccm_task_t task)
952 {
953     *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
954 }
955 
nrf_ccm_task_address_get(NRF_CCM_Type const * p_reg,nrf_ccm_task_t task)956 NRF_STATIC_INLINE uint32_t nrf_ccm_task_address_get(NRF_CCM_Type const * p_reg,
957                                                     nrf_ccm_task_t       task)
958 {
959     return ((uint32_t)p_reg + (uint32_t)task);
960 }
961 
nrf_ccm_event_clear(NRF_CCM_Type * p_reg,nrf_ccm_event_t event)962 NRF_STATIC_INLINE void nrf_ccm_event_clear(NRF_CCM_Type *  p_reg,
963                                            nrf_ccm_event_t event)
964 {
965     *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL;
966     nrf_event_readback((uint8_t *)p_reg + (uint32_t)event);
967 }
968 
nrf_ccm_event_check(NRF_CCM_Type const * p_reg,nrf_ccm_event_t event)969 NRF_STATIC_INLINE bool nrf_ccm_event_check(NRF_CCM_Type const * p_reg,
970                                            nrf_ccm_event_t      event)
971 {
972     return nrf_event_check(p_reg, event);
973 }
974 
nrf_ccm_event_address_get(NRF_CCM_Type const * p_reg,nrf_ccm_event_t event)975 NRF_STATIC_INLINE uint32_t nrf_ccm_event_address_get(NRF_CCM_Type const * p_reg,
976                                                      nrf_ccm_event_t      event)
977 {
978     return ((uint32_t)p_reg + (uint32_t)event);
979 }
980 
981 #if NRF_CCM_HAS_EVENT_ENDKSGEN
nrf_ccm_shorts_enable(NRF_CCM_Type * p_reg,uint32_t mask)982 NRF_STATIC_INLINE void nrf_ccm_shorts_enable(NRF_CCM_Type * p_reg,
983                                              uint32_t       mask)
984 {
985     p_reg->SHORTS |= mask;
986 }
987 
nrf_ccm_shorts_disable(NRF_CCM_Type * p_reg,uint32_t mask)988 NRF_STATIC_INLINE void nrf_ccm_shorts_disable(NRF_CCM_Type * p_reg,
989                                               uint32_t       mask)
990 {
991     p_reg->SHORTS &= ~(mask);
992 }
993 
nrf_ccm_shorts_set(NRF_CCM_Type * p_reg,uint32_t mask)994 NRF_STATIC_INLINE void nrf_ccm_shorts_set(NRF_CCM_Type * p_reg,
995                                           uint32_t       mask)
996 {
997     p_reg->SHORTS = mask;
998 }
999 #endif // NRF_CCM_HAS_EVENT_ENDKSGEN
1000 
nrf_ccm_int_enable(NRF_CCM_Type * p_reg,uint32_t mask)1001 NRF_STATIC_INLINE void nrf_ccm_int_enable(NRF_CCM_Type * p_reg, uint32_t mask)
1002 {
1003     p_reg->INTENSET = mask;
1004 }
1005 
nrf_ccm_int_disable(NRF_CCM_Type * p_reg,uint32_t mask)1006 NRF_STATIC_INLINE void nrf_ccm_int_disable(NRF_CCM_Type * p_reg, uint32_t mask)
1007 {
1008     p_reg->INTENCLR = mask;
1009 }
1010 
nrf_ccm_int_enable_check(NRF_CCM_Type const * p_reg,uint32_t mask)1011 NRF_STATIC_INLINE uint32_t nrf_ccm_int_enable_check(NRF_CCM_Type const * p_reg, uint32_t mask)
1012 {
1013     return p_reg->INTENSET & mask;
1014 }
1015 
nrf_ccm_enable(NRF_CCM_Type * p_reg)1016 NRF_STATIC_INLINE void nrf_ccm_enable(NRF_CCM_Type * p_reg)
1017 {
1018     p_reg->ENABLE = (CCM_ENABLE_ENABLE_Enabled << CCM_ENABLE_ENABLE_Pos);
1019 }
1020 
nrf_ccm_disable(NRF_CCM_Type * p_reg)1021 NRF_STATIC_INLINE void nrf_ccm_disable(NRF_CCM_Type * p_reg)
1022 {
1023     p_reg->ENABLE = (CCM_ENABLE_ENABLE_Disabled << CCM_ENABLE_ENABLE_Pos);
1024 }
1025 
nrf_ccm_configure(NRF_CCM_Type * p_reg,nrf_ccm_config_t const * p_config)1026 NRF_STATIC_INLINE void nrf_ccm_configure(NRF_CCM_Type *           p_reg,
1027                                          nrf_ccm_config_t const * p_config)
1028 {
1029     p_reg->MODE = (((uint32_t)p_config->mode       << CCM_MODE_MODE_Pos)     |
1030 #if NRF_CCM_HAS_MODE_PROTOCOL
1031                    ((uint32_t)p_config->protocol   << CCM_MODE_PROTOCOL_Pos) |
1032 #endif
1033 #if NRF_CCM_HAS_DATARATE
1034                    ((uint32_t)p_config->datarate   << CCM_MODE_DATARATE_Pos) |
1035 #endif
1036 #if NRF_CCM_HAS_MODE_LENGTH
1037                    ((uint32_t)p_config->length     << CCM_MODE_LENGTH_Pos)   |
1038 #endif
1039 #if NRF_CCM_HAS_MODE_MACLEN
1040                    ((uint32_t)p_config->mac_length << CCM_MODE_MACLEN_Pos)   |
1041 #endif
1042                    0);
1043 }
1044 
1045 #if NRF_CCM_HAS_MAXPACKETSIZE
nrf_ccm_maxpacketsize_set(NRF_CCM_Type * p_reg,uint8_t size)1046 NRF_STATIC_INLINE void nrf_ccm_maxpacketsize_set(NRF_CCM_Type * p_reg,
1047                                                  uint8_t        size)
1048 {
1049     NRFX_ASSERT((size >= 0x1B) && (size <= 0xFB));
1050 
1051     p_reg->MAXPACKETSIZE = size;
1052 }
1053 #endif // defined(NRF_CCM_HAS_MAXPACKETSIZE)
1054 
1055 #if NRF_CCM_HAS_MICSTATUS
nrf_ccm_micstatus_get(NRF_CCM_Type const * p_reg)1056 NRF_STATIC_INLINE bool nrf_ccm_micstatus_get(NRF_CCM_Type const * p_reg)
1057 {
1058     return (bool)(p_reg->MICSTATUS);
1059 }
1060 #endif // NRF_CCM_HAS_MICSTATUS
1061 
1062 #if NRF_CCM_HAS_MACSTATUS
nrf_ccm_macstatus_get(NRF_CCM_Type const * p_reg)1063 NRF_STATIC_INLINE bool nrf_ccm_macstatus_get(NRF_CCM_Type const * p_reg)
1064 {
1065     return (bool)(p_reg->MACSTATUS);
1066 }
1067 #endif // NRF_CCM_HAS_MACSTATUS
1068 
1069 #if NRF_CCM_HAS_ERRORSTATUS
nrf_ccm_errorstatus_get(NRF_CCM_Type const * p_reg)1070 NRF_STATIC_INLINE nrf_ccm_error_t nrf_ccm_errorstatus_get(NRF_CCM_Type const * p_reg)
1071 {
1072     return (nrf_ccm_error_t)(p_reg->ERRORSTATUS);
1073 }
1074 #endif // NRF_CCM_HAS_ERRORSTATUS
1075 
1076 #if NRF_CCM_HAS_CNFPTR
nrf_ccm_cnfptr_set(NRF_CCM_Type * p_reg,nrf_ccm_cnf_t const * p_data)1077 NRF_STATIC_INLINE void nrf_ccm_cnfptr_set(NRF_CCM_Type *        p_reg,
1078                                           nrf_ccm_cnf_t const * p_data)
1079 {
1080     p_reg->CNFPTR = (uint32_t)p_data;
1081 }
1082 
nrf_ccm_cnfptr_get(NRF_CCM_Type const * p_reg)1083 NRF_STATIC_INLINE nrf_ccm_cnf_t * nrf_ccm_cnfptr_get(NRF_CCM_Type const * p_reg)
1084 {
1085 #if defined(NRF5340_XXAA_NETWORK)
1086     // Apply workaround for anomaly 10.
1087     return (nrf_ccm_cnf_t *)(p_reg->CNFPTR | 0x01000000);
1088 #else
1089     return (nrf_ccm_cnf_t *)(p_reg->CNFPTR);
1090 #endif // NRF5340_XXAA_NETWORK
1091 }
1092 #endif // NRF_CCM_HAS_CNFPTR
1093 
1094 #if NRF_CCM_HAS_KEY
nrf_ccm_key_set(NRF_CCM_Type * p_reg,uint32_t const * p_key)1095 NRF_STATIC_INLINE void nrf_ccm_key_set(NRF_CCM_Type   * p_reg,
1096                                        uint32_t const * p_key)
1097 {
1098     NRFX_ASSERT(p_key);
1099     for (uint8_t i = 0; i < CCM_KEY_VALUE_MaxCount; i++)
1100     {
1101         p_reg->KEY.VALUE[i] = p_key[i];
1102     }
1103 }
1104 
nrf_ccm_key_get(NRF_CCM_Type const * p_reg)1105 NRF_STATIC_INLINE uint32_t const volatile * nrf_ccm_key_get(NRF_CCM_Type const * p_reg)
1106 {
1107     return (uint32_t const volatile *)(p_reg->KEY.VALUE);
1108 }
1109 #endif // NRF_CCM_HAS_KEY
1110 
1111 #if NRF_CCM_HAS_NONCE
nrf_ccm_nonce_set(NRF_CCM_Type * p_reg,uint32_t const * p_nonce)1112 NRF_STATIC_INLINE void nrf_ccm_nonce_set(NRF_CCM_Type *   p_reg,
1113                                          uint32_t const * p_nonce)
1114 {
1115     NRFX_ASSERT(p_nonce);
1116     for (uint8_t i = 0; i < CCM_NONCE_VALUE_MaxCount; i++)
1117     {
1118         p_reg->NONCE.VALUE[i] = p_nonce[i];
1119     }
1120 }
1121 
nrf_ccm_nonce_get(NRF_CCM_Type const * p_reg)1122 NRF_STATIC_INLINE uint32_t const volatile * nrf_ccm_nonce_get(NRF_CCM_Type const * p_reg)
1123 {
1124     return (uint32_t const volatile *)(p_reg->NONCE.VALUE);
1125 }
1126 #endif // NRF_CCM_HAS_NONCE
1127 
1128 #if NRF_CCM_HAS_IN_AMOUNT
nrf_ccm_in_amount_get(NRF_CCM_Type const * p_reg)1129 NRF_STATIC_INLINE uint32_t nrf_ccm_in_amount_get(NRF_CCM_Type const * p_reg)
1130 {
1131     return p_reg->IN.AMOUNT;
1132 }
1133 #endif // NRF_CCM_HAS_IN_AMOUNT
1134 
1135 #if NRF_CCM_HAS_OUT_AMOUNT
nrf_ccm_out_amount_get(NRF_CCM_Type const * p_reg)1136 NRF_STATIC_INLINE uint32_t nrf_ccm_out_amount_get(NRF_CCM_Type const * p_reg)
1137 {
1138     return p_reg->OUT.AMOUNT;
1139 }
1140 #endif // NRF_CCM_HAS_OUT_AMOUNT
1141 
1142 #if NRF_CCM_HAS_INPTR
nrf_ccm_inptr_set(NRF_CCM_Type * p_reg,uint32_t const * p_data)1143 NRF_STATIC_INLINE void nrf_ccm_inptr_set(NRF_CCM_Type *   p_reg,
1144                                          uint32_t const * p_data)
1145 {
1146     p_reg->INPTR = (uint32_t)p_data;
1147 }
1148 
nrf_ccm_inptr_get(NRF_CCM_Type const * p_reg)1149 NRF_STATIC_INLINE uint32_t * nrf_ccm_inptr_get(NRF_CCM_Type const * p_reg)
1150 {
1151 #if defined(NRF5340_XXAA_NETWORK)
1152     // Apply workaround for anomaly 10.
1153     return (uint32_t *)(p_reg->INPTR | 0x01000000);
1154 #else
1155     return (uint32_t *)(p_reg->INPTR);
1156 #endif // defined(NRF5340_XXAA_NETWORK)
1157 }
1158 #endif // NRF_CCM_HAS_INPTR
1159 
1160 #if NRF_CCM_HAS_IN_PTR
nrf_ccm_in_ptr_set(NRF_CCM_Type * p_reg,nrf_vdma_job_t const * p_job)1161 NRF_STATIC_INLINE void nrf_ccm_in_ptr_set(NRF_CCM_Type *         p_reg,
1162                                           nrf_vdma_job_t const * p_job)
1163 {
1164     p_reg->IN.PTR = (uint32_t)p_job;
1165 }
1166 
nrf_ccm_in_ptr_get(NRF_CCM_Type const * p_reg)1167 NRF_STATIC_INLINE nrf_vdma_job_t * nrf_ccm_in_ptr_get(NRF_CCM_Type const * p_reg)
1168 {
1169     return (nrf_vdma_job_t *)(p_reg->IN.PTR);
1170 }
1171 #endif // NRF_CCM_HAS_IN_PTR
1172 
1173 #if NRF_CCM_HAS_OUTPTR
nrf_ccm_outptr_set(NRF_CCM_Type * p_reg,uint32_t const * p_data)1174 NRF_STATIC_INLINE void nrf_ccm_outptr_set(NRF_CCM_Type *   p_reg,
1175                                           uint32_t const * p_data)
1176 {
1177     p_reg->OUTPTR = (uint32_t)p_data;
1178 }
1179 
nrf_ccm_outptr_get(NRF_CCM_Type const * p_reg)1180 NRF_STATIC_INLINE uint32_t * nrf_ccm_outptr_get(NRF_CCM_Type const * p_reg)
1181 {
1182 #if defined(NRF5340_XXAA_NETWORK)
1183     // Apply workaround for anomaly 10.
1184     return (uint32_t *)(p_reg->OUTPTR | 0x01000000);
1185 #else
1186     return (uint32_t *)(p_reg->OUTPTR);
1187 #endif
1188 }
1189 #endif // NRF_CCM_HAS_OUTPTR
1190 
1191 #if NRF_CCM_HAS_OUT_PTR
nrf_ccm_out_ptr_set(NRF_CCM_Type * p_reg,nrf_vdma_job_t const * p_job)1192 NRF_STATIC_INLINE void nrf_ccm_out_ptr_set(NRF_CCM_Type *         p_reg,
1193                                            nrf_vdma_job_t const * p_job)
1194 {
1195     p_reg->OUT.PTR = (uint32_t)p_job;
1196 }
1197 
nrf_ccm_out_ptr_get(NRF_CCM_Type const * p_reg)1198 NRF_STATIC_INLINE nrf_vdma_job_t * nrf_ccm_out_ptr_get(NRF_CCM_Type const * p_reg)
1199 {
1200     return (nrf_vdma_job_t *)(p_reg->OUT.PTR);
1201 }
1202 #endif // NRF_CCM_HAS_OUT_PTR
1203 
1204 #if NRF_CCM_HAS_SCRATCHPTR
nrf_ccm_scratchptr_set(NRF_CCM_Type * p_reg,uint32_t const * p_area)1205 NRF_STATIC_INLINE void nrf_ccm_scratchptr_set(NRF_CCM_Type *   p_reg,
1206                                               uint32_t const * p_area)
1207 {
1208     p_reg->SCRATCHPTR = (uint32_t)p_area;
1209 }
1210 
nrf_ccm_scratchptr_get(NRF_CCM_Type const * p_reg)1211 NRF_STATIC_INLINE uint32_t * nrf_ccm_scratchptr_get(NRF_CCM_Type const * p_reg)
1212 {
1213 #if defined(NRF5340_XXAA_NETWORK)
1214     // Apply workaround for anomaly 10.
1215     return (uint32_t *)(p_reg->SCRATCHPTR | 0x01000000);
1216 #else
1217     return (uint32_t *)(p_reg->SCRATCHPTR);
1218 #endif // defined(NRF5340_XXAA_NETWORK)
1219 }
1220 #endif // NRF_CCM_HAS_SCRATCHPTR
1221 
1222 #if NRF_CCM_HAS_RATEOVERRIDE
nrf_ccm_datarate_override_set(NRF_CCM_Type * p_reg,nrf_ccm_datarate_t datarate)1223 NRF_STATIC_INLINE void nrf_ccm_datarate_override_set(NRF_CCM_Type *     p_reg,
1224                                                      nrf_ccm_datarate_t datarate)
1225 {
1226     p_reg->RATEOVERRIDE = ((uint32_t)datarate << CCM_RATEOVERRIDE_RATEOVERRIDE_Pos);
1227 }
1228 
nrf_ccm_datarate_override_get(NRF_CCM_Type const * p_reg)1229 NRF_STATIC_INLINE nrf_ccm_datarate_t nrf_ccm_datarate_override_get(NRF_CCM_Type const * p_reg)
1230 {
1231     return (nrf_ccm_datarate_t)(p_reg->RATEOVERRIDE);
1232 }
1233 #endif // NRF_CCM_HAS_RATEOVERRIDE
1234 
1235 #if NRF_CCM_HAS_ADATAMASK
nrf_ccm_adatamask_set(NRF_CCM_Type * p_reg,uint8_t adata_msk)1236 NRF_STATIC_INLINE void nrf_ccm_adatamask_set(NRF_CCM_Type * p_reg,
1237                                              uint8_t        adata_msk)
1238 {
1239     p_reg->ADATAMASK = (uint32_t)adata_msk;
1240 }
1241 
nrf_ccm_adatamask_get(NRF_CCM_Type const * p_reg)1242 NRF_STATIC_INLINE uint32_t nrf_ccm_adatamask_get(NRF_CCM_Type const * p_reg)
1243 {
1244     return (uint32_t)(p_reg->ADATAMASK);
1245 }
1246 #endif // NRF_CCM_HAS_ADATAMASK
1247 
1248 #if NRF_CCM_HAS_HEADERMASK
nrf_ccm_headermask_set(NRF_CCM_Type * p_reg,uint8_t header_msk)1249 NRF_STATIC_INLINE void nrf_ccm_headermask_set(NRF_CCM_Type * p_reg,
1250                                               uint8_t        header_msk)
1251 {
1252     p_reg->HEADERMASK = (uint32_t)header_msk;
1253 }
1254 
nrf_ccm_headermask_get(NRF_CCM_Type const * p_reg)1255 NRF_STATIC_INLINE uint32_t nrf_ccm_headermask_get(NRF_CCM_Type const * p_reg)
1256 {
1257     return (uint32_t)(p_reg->HEADERMASK);
1258 }
1259 #endif
1260 
1261 #if defined(DPPI_PRESENT)
nrf_ccm_subscribe_set(NRF_CCM_Type * p_reg,nrf_ccm_task_t task,uint8_t channel)1262 NRF_STATIC_INLINE void nrf_ccm_subscribe_set(NRF_CCM_Type * p_reg,
1263                                              nrf_ccm_task_t task,
1264                                              uint8_t        channel)
1265 {
1266     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
1267             ((uint32_t)channel | NRF_SUBSCRIBE_PUBLISH_ENABLE);
1268 }
1269 
nrf_ccm_subscribe_clear(NRF_CCM_Type * p_reg,nrf_ccm_task_t task)1270 NRF_STATIC_INLINE void nrf_ccm_subscribe_clear(NRF_CCM_Type * p_reg,
1271                                                nrf_ccm_task_t task)
1272 {
1273     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
1274 }
1275 
nrf_ccm_publish_set(NRF_CCM_Type * p_reg,nrf_ccm_event_t event,uint8_t channel)1276 NRF_STATIC_INLINE void nrf_ccm_publish_set(NRF_CCM_Type *  p_reg,
1277                                            nrf_ccm_event_t event,
1278                                            uint8_t         channel)
1279 {
1280     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) =
1281             ((uint32_t)channel | NRF_SUBSCRIBE_PUBLISH_ENABLE);
1282 }
1283 
nrf_ccm_publish_clear(NRF_CCM_Type * p_reg,nrf_ccm_event_t event)1284 NRF_STATIC_INLINE void nrf_ccm_publish_clear(NRF_CCM_Type *  p_reg,
1285                                              nrf_ccm_event_t event)
1286 {
1287     *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) = 0;
1288 }
1289 #endif // defined(DPPI_PRESENT)
1290 
1291 #endif // NRF_DECLARE_ONLY
1292 
1293 /** @} */
1294 
1295 #ifdef __cplusplus
1296 }
1297 #endif
1298 
1299 #endif  // NRF_CCM_H__
1300