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