1 /***************************************************************************//**
2 * \file cy_cryptolite_trng.h
3 * \version 2.50
4 *
5 * \brief
6 * This file provides common constants and parameters
7 * for the Cryptolite TRNG driver.
8 *
9 ********************************************************************************
10 * Copyright 2022 Cypress Semiconductor Corporation
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *******************************************************************************/
25 #if !defined (CY_CRYPTOLITE_TRNG_H)
26 #define CY_CRYPTOLITE_TRNG_H
27
28 #include "cy_device.h"
29
30 #if defined (CY_IP_MXCRYPTOLITE)
31
32 #if defined(__cplusplus)
33 extern "C" {
34 #endif
35
36 #include "cy_cryptolite_common.h"
37
38 #if (CRYPTOLITE_TRNG_PRESENT == 1)
39 #if defined(CY_CRYPTOLITE_CFG_TRNG_C)
40
41 /** \cond INTERNAL */
42 #define CY_CRYPTOLITE_TRNG_RO_ENABLE (1U)
43 #define CY_CRYPTOLITE_TRNG_RO_DISABLE (0U)
44 /** \endcond */
45
46 /** \cond INTERNAL */
47 typedef enum
48 {
49 /** "Selection of the ring oscillator (RO) source: */
50 CY_CRYPTOLITE_TRNG_SRC_RO11 = 0, /**< "0": fixed RO 11 bit. */
51 CY_CRYPTOLITE_TRNG_SRC_RO15, /**< "1": fixed RO 15 bit. */
52 CY_CRYPTOLITE_TRNG_SRC_GARO15, /**< "2": fixed Galois RO 15 bit. */
53 CY_CRYPTOLITE_TRNG_SRC_GARO31, /**< "3": flexible Galois RO 31 bit. */
54 CY_CRYPTOLITE_TRNG_SRC_FIRO15, /**< "4": fixed Fibonacci RO 15 bit. */
55 CY_CRYPTOLITE_TRNG_SRC_FIRO31 /**< "5": flexible Fibonacci RO 31 bit. */
56 } cy_en_cryptolite_trng_ro_sel_t;
57 /** \endcond */
58
59 /******************************************
60 * Configuration structure
61 ******************************************/
62 /** \cond INTERNAL */
63 typedef enum
64 {
65 /** "Selection of the bitstream: */
66 CY_CRYPTOLITE_TRMON_BS_DAS = 0, /**< "0": DAS bitstream. */
67 CY_CRYPTOLITE_TRMON_BS_RED, /**< "1": RED bitstream. */
68 CY_CRYPTOLITE_TRMON_BS_TR, /**< "2": TR bitstream. */
69 CY_CRYPTOLITE_TRMON_BS_UNDEF /**< "3": Undefined. */
70 } cy_en_cryptolite_trng_bs_sel_t;
71 /** \endcond */
72
73 /** The structure for storing the TRNG configuration.
74 */
75 typedef struct
76 {
77 /** \cond INTERNAL */
78 /**
79 * "Specifies the clock divider that is used to sample oscillator data.
80 * This clock divider is wrt. "clk_sys".
81 * "0": sample clock is "clk_sys".
82 * "1": sample clock is "clk_sys"/2.
83 *
84 * "255": sample clock is "clk_sys"/256. */
85 uint8_t sampleClockDiv;
86 /**
87 * "Specifies the clock divider that is used to produce reduced bits.
88 * "0": 1 reduced bit is produced for each sample.
89 * "1": 1 reduced bit is produced for each 2 samples.
90 *
91 * "255": 1 reduced bit is produced for each 256 samples. */
92 uint8_t reducedClockDiv;
93 /**
94 * Specifies an initialization delay: number of removed/dropped samples
95 * before reduced bits are generated. This field should be programmed
96 * in the range [1, 255]. After starting the oscillators,
97 * at least the first 2 samples should be removed/dropped to clear the state
98 * of internal synchronizers. In addition, it is advised to drop
99 * at least the second 2 samples from the oscillators (to circumvent
100 * the semi-predictable oscillator startup behavior).
101 *
102 * This result in the default field value of "3".
103 * Field encoding is as follows:
104 * "0": 1 sample is dropped.
105 * "1": 2 samples are dropped.
106 *
107 * "255": 256 samples are dropped.
108 *
109 * The TR_INITIALIZED interrupt cause is set to '1', when
110 * the initialization delay is passed. */
111 uint8_t initDelay;
112 /**
113 * "Specifies if the "von Neumann corrector" is disabled or enabled:
114 * '0': disabled.
115 * '1': enabled.
116 * The "von Neumann corrector" post-processes the reduced bits
117 * to remove a '0' or '1' bias. The corrector operates on reduced bit pairs
118 * ("oldest bit, newest bit"):
119 * "00": no bit is produced.
120 * "01": '0' bit is produced (oldest bit).
121 * "10": '1' bit is produced (oldest bit).
122 * "11": no bit is produced.
123 * Note that the corrector produces bits at a random pace and at a frequency
124 * that is 1/4 of the reduced bit frequency (reduced bits are processed
125 * in pairs, and half of the pairs do NOT produce a bit). */
126 bool vnCorrectorEnable;
127 /**
128 * Specifies if TRNG adaptive proportion(AP) Test is enabled
129 * When test fails INTR.TR_AP_DETECT is set to '1'. */
130 bool EnableAPTest;
131 /**
132 * Specifies if TRNG repetition count(RC) Test is enabled
133 * When test fails INTR.TR_RC_DETECT is set to '1'. */
134 bool EnableRCTest;
135 /**
136 * Specifies if TRNG functionality is stopped on an adaptive proportion
137 * test detection (when HW sets INTR.TR_AP_DETECT to '1'):
138 * '0': Functionality is NOT stopped.
139 * '1': Functionality is stopped (TR_CTL1 fields are set to '0' by HW).
140 * valid only if EnableAPTest is set to true */
141 bool stopOnAPDetect;
142 /**
143 * Specifies if TRNG functionality is stopped on a repetition
144 * count test detection (when HW sets INTR.TR_RC_DETECT to '1'):
145 * '0': Functionality is NOT stopped.
146 * '1': Functionality is stopped (TR_CTL1 fields are set to '0' by HW).
147 * valid only if EnableRCTest is set to true */
148 bool stopOnRCDetect;
149 /**
150 * Polynomial for programmable Galois ring oscillator.
151 * The polynomial is represented WITHOUT
152 * the high order bit (this bit is always assumed '1').
153 * The polynomial should be aligned such that the more
154 * significant bits (bit 30 and down) contain the polynomial
155 * and the less significant bits (bit 0 and up) contain padding '0's. */
156 uint32_t garo31Poly;
157 /**
158 * Polynomial for programmable Fibonacci ring oscillator.
159 * The polynomial is represented WITHOUT
160 * the high order bit (this bit is always assumed '1').
161 * The polynomial should be aligned such that the more
162 * significant bits (bit 30 and down) contain the polynomial
163 * and the less significant bits (bit 0 and up) contain padding '0's. */
164 uint32_t firo31Poly;
165 /**
166 * Selection of the bitstream:
167 * "0": DAS bitstream.
168 * "1": RED bitstream.
169 * "2": TR bitstream.
170 * "3": Undefined. */
171 cy_en_cryptolite_trng_bs_sel_t monBitStreamSelect;
172 /**
173 * Cutoff count (legal range is [1, 255]):
174 * "0": Illegal.
175 * "1": 1 repetition.
176 * ..
177 * "255": 255 repetitions. */
178 uint8_t monCutoffCount8;
179 /**
180 * Cutoff count (legal range is [1, 65535]).
181 * "0": Illegal.
182 * "1": 1 occurrence.
183 * ...
184 * "65535": 65535 occurrences. */
185 uint16_t monCutoffCount16;
186 /**
187 * Window size (minus 1) :
188 * "0": 1 bit.
189 * ...
190 * "65535": 65536 bits. */
191 uint16_t monWindowSize;
192 /** \endcond */
193 } cy_stc_cryptolite_trng_config_t;
194
195 /**
196 * \addtogroup group_cryptolite_lld_rng_functions
197 * \{
198 */
199
200 /*******************************************************************************
201 * Function Name: Cy_Cryptolite_Trng
202 ****************************************************************************//**
203 *
204 * Generates a True Random Number.
205 *
206 * \param base
207 * The pointer to the cryptolite instance.
208 *
209 * \param randomNum
210 * The pointer to a generated true random number.
211 *
212 * \return
213 * \ref cy_en_cryptolite_status_t
214 *
215 * \funcusage
216 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Trng
217 *******************************************************************************/
218 cy_en_cryptolite_status_t Cy_Cryptolite_Trng(CRYPTOLITE_Type *base, uint32_t *randomNum);
219
220 /** \} group_cryptolite_lld_rng_functions */
221
222
223
224 /** \cond INTERNAL */
225
226 /* Macros for conditions used by CY_ASSERT calls */
227 #define CY_CRYPTOLITE_IS_SMPL_CLK_DIV_VALID(clkDiv) ((clkDiv) <= 255U)
228 #define CY_CRYPTOLITE_IS_RED_CLK_DIV_VALID(clkDiv) ((clkDiv) <= 255U)
229 #define CY_CRYPTOLITE_IS_INIT_DELAY_VALID(delay) ((delay) <= 255U)
230 #define CY_CRYPTOLITE_IS_VONN_CORR_VALID(val) ((uint32_t)(val) <= 1U)
231 #define CY_CRYPTOLITE_IS_AP_DETECT_VALID(val) ((uint32_t)(val) <= 1U)
232 #define CY_CRYPTOLITE_IS_RC_DETECT_VALID(val) ((uint32_t)(val) <= 1U)
233
234 #define CY_CRYPTOLITE_IS_RO11_EN_VALID(val) ((uint32_t)(val) <= 1U)
235 #define CY_CRYPTOLITE_IS_RO15_EN_VALID(val) ((uint32_t)(val) <= 1U)
236 #define CY_CRYPTOLITE_IS_GARO15_EN_VALID(val) ((uint32_t)(val) <= 1U)
237 #define CY_CRYPTOLITE_IS_GARO31_EN_VALID(val) ((uint32_t)(val) <= 1U)
238 #define CY_CRYPTOLITE_IS_FIRO15_EN_VALID(val) ((uint32_t)(val) <= 1U)
239 #define CY_CRYPTOLITE_IS_FIRO31_EN_VALID(val) ((uint32_t)(val) <= 1U)
240
241 #define CY_CRYPTOLITE_IS_GARO_POLY_VALID(val) ((val) <= 0x7FFFFFFFUL)
242 #define CY_CRYPTOLITE_IS_FIRO_POLY_VALID(val) ((val) <= 0x7FFFFFFFUL)
243
244 #define CY_CRYPTOLITE_IS_BS_SELECT_VALID(val) (((val) == CY_CRYPTOLITE_TRMON_BS_DAS) || \
245 ((val) == CY_CRYPTOLITE_TRMON_BS_RED) || \
246 ((val) == CY_CRYPTOLITE_TRMON_BS_TR))
247
248 #define CY_CRYPTOLITE_IS_CCOUNT8_VALID(val) ((val) <= 255U)
249 #define CY_CRYPTOLITE_IS_CCOUNT16_VALID(val) ((val) <= 65535U)
250 #define CY_CRYPTOLITE_IS_WINSIZE_VALID(val) ((val) <= 65535U)
251
252 #define CY_CRYPTOLITE_TRNG_AP_DETECT_ERROR_BIT (0U)
253 #define CY_CRYPTOLITE_TRNG_RC_DETECT_ERROR_BIT (1U)
254 #define CY_CRYPTOLITE_TRNG_AP_DETECT_ERROR (1U << 0U)
255 #define CY_CRYPTOLITE_TRNG_RC_DETECT_ERROR (1U << 1U)
256
257 #define CY_CRYPTOLITE_TRNG_RO_ALL_MASK (uint32_t)(CRYPTOLITE_TRNG_CTL1_RO11_EN_Msk | \
258 CRYPTOLITE_TRNG_CTL1_RO15_EN_Msk | \
259 CRYPTOLITE_TRNG_CTL1_GARO15_EN_Msk | CRYPTOLITE_TRNG_CTL1_GARO31_EN_Msk | \
260 CRYPTOLITE_TRNG_CTL1_FIRO15_EN_Msk | CRYPTOLITE_TRNG_CTL1_FIRO31_EN_Msk)
261 /** FW sets this field to '1' to enable the ring oscillator with 11 inverters. */
262 #define CY_CRYPTOLITE_DEF_TRNG_RO11_EN (1UL)
263
264 /** FW sets this field to '1' to enable the ring oscillator with 15 inverters. */
265 #define CY_CRYPTOLITE_DEF_TRNG_RO15_EN (1UL)
266
267 /**
268 * FW sets this field to '1' to enable the fixed Galois ring oscillator
269 * with 15 inverters.
270 */
271 #define CY_CRYPTOLITE_DEF_TRNG_GARO15_EN (1UL)
272
273 /**
274 * FW sets this field to '1' to enable the programmable Galois ring oscillator with up
275 * to 31 inverters. The TR_GARO_CTL register specifies the programmable polynomial.
276 */
277 #define CY_CRYPTOLITE_DEF_TRNG_GARO31_EN (1UL)
278
279 /** FW sets this field to '1' to enable the fixed Fibonacci ring oscillator with 15 inverters. */
280 #define CY_CRYPTOLITE_DEF_TRNG_FIRO15_EN (1UL)
281
282 /**
283 * FW sets this field to '1' to enable the programmable Fibonacci ring oscillator
284 * with up to 31 inverters. The TR_FIRO_CTL register specifies the programmable polynomial.
285 */
286 #define CY_CRYPTOLITE_DEF_TRNG_FIRO31_EN (1UL)
287
288 extern const cy_stc_cryptolite_trng_config_t cy_cryptolite_trngDefaultConfig;
289
290 __STATIC_INLINE bool Cy_Cryptolite_Trng_IsInitialized(CRYPTOLITE_Type *base);
291 __STATIC_INLINE uint8_t Cy_Cryptolite_Trng_GetRoStatus(CRYPTOLITE_Type *base, cy_en_cryptolite_trng_ro_sel_t roSelector);
292 __STATIC_INLINE void Cy_Cryptolite_Trng_SetRoStatus(CRYPTOLITE_Type *base,
293 cy_en_cryptolite_trng_ro_sel_t roSelector, uint8_t roStatus);
294 __STATIC_INLINE uint32_t Cy_Cryptolite_Trng_GetData(CRYPTOLITE_Type *base);
295 __STATIC_INLINE void Cy_Cryptolite_Trng_SetGaroPoly(CRYPTOLITE_Type *base, uint32_t poly);
296 __STATIC_INLINE void Cy_Cryptolite_Trng_SetFiroPoly(CRYPTOLITE_Type *base, uint32_t poly);
297 __STATIC_INLINE uint32_t Cy_Cryptolite_Trng_GetGaroPoly(CRYPTOLITE_Type *base);
298 __STATIC_INLINE uint32_t Cy_Cryptolite_Trng_GetFiroPoly(CRYPTOLITE_Type *base);
299
300 __STATIC_INLINE uint8_t Cy_Cryptolite_Trng_MonGetHealthStatus(CRYPTOLITE_Type *base);
301
302 __STATIC_INLINE uint8_t Cy_Cryptolite_Trng_MonGetRcRepCount(CRYPTOLITE_Type *base);
303 __STATIC_INLINE uint16_t Cy_Cryptolite_Trng_MonGetApOccCount(CRYPTOLITE_Type *base);
304 __STATIC_INLINE uint16_t Cy_Cryptolite_Trng_MonGetApWindowIndex(CRYPTOLITE_Type *base);
305
306 __STATIC_INLINE uint8_t Cy_Cryptolite_Trng_MonGetRcCurrentBit(CRYPTOLITE_Type *base);
307 __STATIC_INLINE uint8_t Cy_Cryptolite_Trng_MonGetApCurrentBit(CRYPTOLITE_Type *base);
308
309 __STATIC_INLINE cy_en_cryptolite_status_t Cy_Cryptolite_Trng_MonSetBSSelector(CRYPTOLITE_Type *base, cy_en_cryptolite_trng_bs_sel_t bitStreamSelector);
310 __STATIC_INLINE cy_en_cryptolite_trng_bs_sel_t Cy_Cryptolite_Trng_MonGetBSSelector(CRYPTOLITE_Type *base);
311
312 __STATIC_INLINE void Cy_Cryptolite_Trng_MonEnableApTest(CRYPTOLITE_Type *base);
313 __STATIC_INLINE void Cy_Cryptolite_Trng_MonDisableApTest(CRYPTOLITE_Type *base);
314 __STATIC_INLINE void Cy_Cryptolite_Trng_MonEnableRcTest(CRYPTOLITE_Type *base);
315 __STATIC_INLINE void Cy_Cryptolite_Trng_MonDisableRcTest(CRYPTOLITE_Type *base);
316
317 __STATIC_INLINE void Cy_Cryptolite_Trng_MonSetRcCC8(CRYPTOLITE_Type *base, uint8_t ccCount);
318 __STATIC_INLINE uint8_t Cy_Cryptolite_Trng_MonGetRcCC8(CRYPTOLITE_Type *base);
319
320 __STATIC_INLINE void Cy_Cryptolite_Trng_MonSetApCC16(CRYPTOLITE_Type *base, uint16_t ccCount);
321 __STATIC_INLINE uint16_t Cy_Cryptolite_Trng_MonGetApCC16(CRYPTOLITE_Type *base);
322
323 __STATIC_INLINE void Cy_Cryptolite_Trng_MonSetApWinSize(CRYPTOLITE_Type *base, uint16_t windowSize);
324 __STATIC_INLINE uint16_t Cy_Cryptolite_Trng_MonGetApWinSize(CRYPTOLITE_Type *base);
325
326 __STATIC_INLINE void Cy_Cryptolite_Trng_WaitForComplete(CRYPTOLITE_Type *base);
327 __STATIC_INLINE void Cy_Cryptolite_Trng_WaitForInit(CRYPTOLITE_Type *base);
328
329 /** \endcond */
330
331
332 /**
333 * \addtogroup group_cryptolite_lld_rng_functions
334 * \{
335 */
336
337 /*******************************************************************************
338 * Function Name: Cy_Cryptolite_Trng_Init
339 ****************************************************************************//**
340 *
341 * Initialize the TRNG hardware submodule
342 *
343 * \param base
344 * The pointer to the CRYPTOLITE instance.
345 *
346 * \param config
347 * The pointer to the configuration structure. If NULL default config is used.
348 *
349 * \return
350 * \ref cy_en_cryptolite_status_t
351 *
352 *
353 * \funcusage
354 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Trng
355 *******************************************************************************/
356 cy_en_cryptolite_status_t Cy_Cryptolite_Trng_Init(CRYPTOLITE_Type *base, cy_stc_cryptolite_trng_config_t *config);
357
358
359 /*******************************************************************************
360 * Function Name: Cy_Cryptolite_Trng_Enable
361 ****************************************************************************//**
362 *
363 * Starts a random number generation.
364 *
365 * \param base
366 * The pointer to the CRYPTOLITE instance.
367 *
368 * \return
369 * The error / status code. See \ref cy_en_cryptolite_status_t.
370 *
371 * \funcusage
372 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Trng_enable_disable
373 *******************************************************************************/
374 cy_en_cryptolite_status_t Cy_Cryptolite_Trng_Enable(CRYPTOLITE_Type *base);
375
376
377 /*******************************************************************************
378 * Function Name: Cy_Cryptolite_Trng_Disable
379 ****************************************************************************//**
380 *
381 * Stops the random number generation.
382 *
383 * \param base
384 * The pointer to the CRYPTOLITE instance.
385 *
386 * \return
387 * The error / status code. See \ref cy_en_cryptolite_status_t.
388 *
389 * \funcusage
390 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Trng_enable_disable
391 *******************************************************************************/
392 cy_en_cryptolite_status_t Cy_Cryptolite_Trng_Disable(CRYPTOLITE_Type *base);
393
394
395 /*******************************************************************************
396 * Function Name: Cy_Cryptolite_Trng_ReadData
397 ****************************************************************************//**
398 *
399 * Reads in blocking mode a generated random number.
400 *
401 * \note
402 * Call this API only after Cy_Cryptolite_Trng_Enable() is successful.
403 *
404 * \param base
405 * The pointer to the CRYPTO instance.
406 *
407 * \param randomData
408 * The pointer to a generated true random number.
409 *
410 * \return
411 * The error / status code. See \ref cy_en_cryptolite_status_t.
412 *
413 *
414 * \funcusage
415 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Trng
416 *******************************************************************************/
417 cy_en_cryptolite_status_t Cy_Cryptolite_Trng_ReadData(CRYPTOLITE_Type *base, uint32_t *randomData);
418
419
420 /*******************************************************************************
421 * Function Name: Cy_Cryptolite_Trng_DeInit
422 ****************************************************************************//**
423 *
424 * Clears all TRNG registers by set to hardware default values.
425 *
426 * \param base
427 * The pointer to the CRYPTOLITE instance.
428 *
429 * \return
430 * The error / status code. See \ref cy_en_cryptolite_status_t.
431 *
432 * \funcusage
433 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Trng
434 *******************************************************************************/
435 cy_en_cryptolite_status_t Cy_Cryptolite_Trng_DeInit(CRYPTOLITE_Type *base);
436
437
438 /*******************************************************************************
439 * Function Name: Cy_Cryptolite_Trng_IsEnabled
440 ****************************************************************************//**
441 *
442 * Checks if Trng is enabled.
443 *
444 * \param base
445 * The pointer to the CRYPTOLITE instance.
446 *
447 * \return
448 * The 'true' if Trng enabled 'false' otherwise.
449 *
450 * \funcusage
451 * \snippet cryptolite/snippet/main.c snippet_Cy_Cryptolite_Trng_enable_disable
452 *******************************************************************************/
453 bool Cy_Cryptolite_Trng_IsEnabled(CRYPTOLITE_Type *base);
454
455 /** \} group_cryptolite_lld_rng_functions */
456
457 __STATIC_INLINE void Cy_Cryptolite_Trng_SetInterruptMask(CRYPTOLITE_Type *base, uint32_t interrupts);
458 __STATIC_INLINE uint32_t Cy_Cryptolite_Trng_GetInterruptMask(CRYPTOLITE_Type const *base);
459 __STATIC_INLINE uint32_t Cy_Cryptolite_Trng_GetInterruptStatusMasked(CRYPTOLITE_Type const *base);
460 __STATIC_INLINE uint32_t Cy_Cryptolite_Trng_GetInterruptStatus(CRYPTOLITE_Type *base);
461 /*
462 * API Implementations
463 */
464
465
466 /******************************************************************************
467 * Function Name: Cy_Cryptolite_Trng_SetInterruptMask
468 ***************************************************************************//**
469 *
470 * Masks / unmasks multiple interrupt sources.
471 *
472 * \param base
473 * The pointer to the CRYPTOLITE instance.
474 *
475 * \param interrupts
476 * Mask bits. See definitions above.
477 *
478 ******************************************************************************/
Cy_Cryptolite_Trng_SetInterruptMask(CRYPTOLITE_Type * base,uint32_t interrupts)479 __STATIC_INLINE void Cy_Cryptolite_Trng_SetInterruptMask(CRYPTOLITE_Type *base, uint32_t interrupts)
480 {
481 REG_CRYPTOLITE_INTR_TRNG_MASK(base) = interrupts;
482 }
483
484 /******************************************************************************
485 * Function Name: Cy_Cryptolite_Trng_GetInterruptMask
486 ***************************************************************************//**
487 *
488 * Reports mask / unmask multiple interrupt sources.
489 *
490 * \param base
491 * The pointer to the CRYPTOLITE instance.
492 *
493 * \return
494 * Mask bits. See definitions above.
495 *
496 ******************************************************************************/
Cy_Cryptolite_Trng_GetInterruptMask(CRYPTOLITE_Type const * base)497 __STATIC_INLINE uint32_t Cy_Cryptolite_Trng_GetInterruptMask(CRYPTOLITE_Type const *base)
498 {
499 return (REG_CRYPTOLITE_INTR_TRNG_MASK(base));
500 }
501
502 /******************************************************************************
503 * Function Name: Cy_Cryptolite_Trng_GetInterruptStatusMasked
504 ***************************************************************************//**
505 *
506 * Reports states of multiple enabled interrupt sources.
507 *
508 * \param base
509 * The pointer to the CRYPTOLITE instance.
510 *
511 * \return
512 * Source bits. See definitions above.
513 *
514 *****************************************************************************/
Cy_Cryptolite_Trng_GetInterruptStatusMasked(CRYPTOLITE_Type const * base)515 __STATIC_INLINE uint32_t Cy_Cryptolite_Trng_GetInterruptStatusMasked(CRYPTOLITE_Type const *base)
516 {
517 return (REG_CRYPTOLITE_INTR_TRNG_MASKED(base));
518 }
519
520 /******************************************************************************
521 * Function Name: Cy_Cryptolite_Trng_GetInterruptStatus
522 ***************************************************************************//**
523 *
524 * Reports states of multiple interrupt sources.
525 *
526 * \param base
527 * The pointer to the CRYPTOLITE instance.
528 *
529 * \return
530 * Source bits. See definitions above.
531 *
532 ******************************************************************************/
Cy_Cryptolite_Trng_GetInterruptStatus(CRYPTOLITE_Type * base)533 __STATIC_INLINE uint32_t Cy_Cryptolite_Trng_GetInterruptStatus(CRYPTOLITE_Type *base)
534 {
535 return (REG_CRYPTOLITE_INTR_TRNG(base));
536 }
537
538 /******************************************************************************
539 * Function Name: Cy_Cryptolite_Trng_SetInterrupt
540 ***************************************************************************//**
541 *
542 * Sets one of more interrupt sources
543 *
544 * \param base
545 * The pointer to the CRYPTOLITE instance.
546 *
547 * \param interrupts
548 * Source bit(s)
549 *
550 ******************************************************************************/
Cy_Cryptolite_Trng_SetInterrupt(CRYPTOLITE_Type * base,uint32_t interrupts)551 __STATIC_INLINE void Cy_Cryptolite_Trng_SetInterrupt(CRYPTOLITE_Type *base, uint32_t interrupts)
552 {
553 REG_CRYPTOLITE_INTR_TRNG_SET(base) = interrupts;
554 }
555
556 /******************************************************************************
557 * Function Name: Cy_Cryptolite_Trng_ClearInterrupt
558 ***************************************************************************//**
559 *
560 * Clears multiple interrupt sources.
561 *
562 * \param base
563 * The pointer to the CRYPTOLITE instance.
564 *
565 * \param interrupts
566 * Source bit(s). See definitions above.
567 *
568 ******************************************************************************/
Cy_Cryptolite_Trng_ClearInterrupt(CRYPTOLITE_Type * base,uint32_t interrupts)569 __STATIC_INLINE void Cy_Cryptolite_Trng_ClearInterrupt(CRYPTOLITE_Type *base, uint32_t interrupts)
570 {
571 REG_CRYPTOLITE_INTR_TRNG(base) = interrupts;
572 /* This dummy reading is necessary here. It provides a guarantee that interrupt is cleared at returning from this function. */
573 (void) REG_CRYPTOLITE_INTR_TRNG(base);
574 }
575
576 /******************************************************************************
577 * Function Name: Cy_Cryptolite_Error_SetInterruptMask
578 ***************************************************************************//**
579 *
580 * Masks / unmasks multiple interrupt sources.
581 *
582 * \param base
583 * The pointer to the CRYPTOLITE instance.
584 *
585 * \param interrupts
586 * Mask bits. See definitions above.
587 *
588 ******************************************************************************/
Cy_Cryptolite_Error_SetInterruptMask(CRYPTOLITE_Type * base,uint32_t interrupts)589 __STATIC_INLINE void Cy_Cryptolite_Error_SetInterruptMask(CRYPTOLITE_Type *base, uint32_t interrupts)
590 {
591 REG_CRYPTOLITE_INTR_ERROR_MASK(base) = interrupts;
592 }
593
594 /******************************************************************************
595 * Function Name: Cy_Cryptolite_Error_GetInterruptMask
596 ***************************************************************************//**
597 *
598 * Reports mask / unmask multiple interrupt sources.
599 *
600 * \param base
601 * The pointer to the CRYPTOLITE instance.
602 *
603 * \return
604 * Mask bits. See definitions above.
605 *
606 ******************************************************************************/
Cy_Cryptolite_Error_GetInterruptMask(CRYPTOLITE_Type const * base)607 __STATIC_INLINE uint32_t Cy_Cryptolite_Error_GetInterruptMask(CRYPTOLITE_Type const *base)
608 {
609 return (REG_CRYPTOLITE_INTR_ERROR_MASK(base));
610 }
611
612 /******************************************************************************
613 * Function Name: Cy_Cryptolite_Error_GetInterruptStatusMasked
614 ***************************************************************************//**
615 *
616 * Reports states of multiple enabled interrupt sources.
617 *
618 * \param base
619 * The pointer to the CRYPTOLITE instance.
620 *
621 * \return
622 * Source bits. See definitions above.
623 *
624 *****************************************************************************/
Cy_Cryptolite_Error_GetInterruptStatusMasked(CRYPTOLITE_Type const * base)625 __STATIC_INLINE uint32_t Cy_Cryptolite_Error_GetInterruptStatusMasked(CRYPTOLITE_Type const *base)
626 {
627 return (REG_CRYPTOLITE_INTR_ERROR_MASKED(base));
628 }
629
630 /******************************************************************************
631 * Function Name: Cy_Cryptolite_Error_GetInterruptStatus
632 ***************************************************************************//**
633 *
634 * Reports states of multiple interrupt sources.
635 *
636 * \param base
637 * The pointer to the CRYPTOLITE instance.
638 *
639 * \return
640 * Source bits. See definitions above.
641 *
642 ******************************************************************************/
Cy_Cryptolite_Error_GetInterruptStatus(CRYPTOLITE_Type * base)643 __STATIC_INLINE uint32_t Cy_Cryptolite_Error_GetInterruptStatus(CRYPTOLITE_Type *base)
644 {
645 return (REG_CRYPTOLITE_INTR_ERROR(base));
646 }
647
648 /******************************************************************************
649 * Function Name: Cy_Cryptolite_Error_SetInterrupt
650 ***************************************************************************//**
651 *
652 * Sets one of more interrupt sources
653 *
654 * \param base
655 * The pointer to the CRYPTOLITE instance.
656 *
657 * \param interrupts
658 * Source bit(s)
659 *
660 ******************************************************************************/
Cy_Cryptolite_Error_SetInterrupt(CRYPTOLITE_Type * base,uint32_t interrupts)661 __STATIC_INLINE void Cy_Cryptolite_Error_SetInterrupt(CRYPTOLITE_Type *base, uint32_t interrupts)
662 {
663 REG_CRYPTOLITE_INTR_ERROR_SET(base) = interrupts;
664 }
665
666 /******************************************************************************
667 * Function Name: Cy_Cryptolite_Error_ClearInterrupt
668 ***************************************************************************//**
669 *
670 * Clears multiple interrupt sources.
671 *
672 * \param base
673 * The pointer to the CRYPTOLITE instance.
674 *
675 * \param interrupts
676 * Source bit(s). See definitions above.
677 *
678 ******************************************************************************/
Cy_Cryptolite_Error_ClearInterrupt(CRYPTOLITE_Type * base,uint32_t interrupts)679 __STATIC_INLINE void Cy_Cryptolite_Error_ClearInterrupt(CRYPTOLITE_Type *base, uint32_t interrupts)
680 {
681 REG_CRYPTOLITE_INTR_ERROR(base) = interrupts;
682 /* This dummy reading is necessary here. It provides a guarantee that interrupt is cleared at returning from this function. */
683 (void) REG_CRYPTOLITE_INTR_ERROR(base);
684 }
685
686
687 /*******************************************************************************
688 * Function Name: Cy_Cryptolite_Trng_IsInitialized
689 ****************************************************************************//**
690 *
691 * Checks for TRNG hardware is initialized.
692 *
693 * \param base
694 * The pointer to the CRYPTOLITE instance.
695 *
696 * \return
697 * true when TRNG hardware is initialized, otherwise false.
698 *
699 *******************************************************************************/
Cy_Cryptolite_Trng_IsInitialized(CRYPTOLITE_Type * base)700 __STATIC_INLINE bool Cy_Cryptolite_Trng_IsInitialized(CRYPTOLITE_Type *base)
701 {
702 return ((Cy_Cryptolite_Trng_GetInterruptStatus(base) & CRYPTOLITE_INTR_TRNG_INITIALIZED_Msk) != 0U);
703 }
704
705 /*******************************************************************************
706 * Function Name: Cy_Cryptolite_Trng_WaitForInit
707 ****************************************************************************//**
708 *
709 * Waits for TRNG initialization is complete.
710 *
711 * \param base
712 * The pointer to the CRYPTO instance.
713 *
714 *******************************************************************************/
Cy_Cryptolite_Trng_WaitForInit(CRYPTOLITE_Type * base)715 __STATIC_INLINE void Cy_Cryptolite_Trng_WaitForInit(CRYPTOLITE_Type *base)
716 {
717 uint32_t status;
718 /* Wait until the TRNG init is complete */
719 do
720 {
721 status = (Cy_Cryptolite_Trng_GetInterruptStatus(base) & CRYPTOLITE_INTR_TRNG_INITIALIZED_Msk);
722 }
723 while (status == 0U);
724 }
725
726 /*******************************************************************************
727 * Function Name: Cy_Cryptolite_Trng_WaitForComplete
728 ****************************************************************************//**
729 *
730 * Waits for TRNG random generation is complete.
731 *
732 * \param base
733 * The pointer to the CRYPTOLITE instance.
734 *
735 * \note
736 * After this call the Health Monitor status should be checked to ensure that
737 * random data is healthy.
738 *
739 *******************************************************************************/
Cy_Cryptolite_Trng_WaitForComplete(CRYPTOLITE_Type * base)740 __STATIC_INLINE void Cy_Cryptolite_Trng_WaitForComplete(CRYPTOLITE_Type *base)
741 {
742 uint32_t status;
743 /* Wait until the TRNG random generation is complete */
744 do
745 {
746 status = Cy_Cryptolite_Trng_GetInterruptStatus(base) & (CRYPTOLITE_INTR_TRNG_DATA_AVAILABLE_Msk |
747 CRYPTOLITE_INTR_TRNG_AP_DETECT_Msk |
748 CRYPTOLITE_INTR_TRNG_RC_DETECT_Msk);
749 }
750 while (status == 0U);
751 }
752
753 /*******************************************************************************
754 * Function Name: Cy_Cryptolite_Trng_GetRoStatus
755 ****************************************************************************//**
756 *
757 * Reads the ring oscillator enable status.
758 *
759 * \param base
760 * The pointer to the CRYPTOLITE instance.
761 *
762 * \param roSelector
763 * The ring oscillator selector (see \ref cy_en_cryptolite_trng_ro_sel_t).
764 *
765 * \return
766 * The ring oscillator enabled status (0 or 1).
767 *
768 *******************************************************************************/
Cy_Cryptolite_Trng_GetRoStatus(CRYPTOLITE_Type * base,cy_en_cryptolite_trng_ro_sel_t roSelector)769 __STATIC_INLINE uint8_t Cy_Cryptolite_Trng_GetRoStatus(CRYPTOLITE_Type *base, cy_en_cryptolite_trng_ro_sel_t roSelector)
770 {
771 CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 10.8','Intentional typecast to wider 32bit.');
772 return (REG_CRYPTOLITE_TRNG_CTL1(base) & (uint32_t)(1U << ((uint32_t)roSelector))) != 0U ? 1U : 0U;
773 }
774
775 /*******************************************************************************
776 * Function Name: Cy_Cryptolite_Trng_SetRoStatus
777 ****************************************************************************//**
778 *
779 * Sets the ring oscillator enable status.
780 *
781 * \param base
782 * The pointer to the CRYPTOLITE instance.
783 *
784 * \param roSelector
785 * The ring oscillator selector (see \ref cy_en_cryptolite_trng_ro_sel_t).
786 *
787 * \param roStatus
788 * The new ring oscillator status value (0 or 1).
789 *
790 *******************************************************************************/
Cy_Cryptolite_Trng_SetRoStatus(CRYPTOLITE_Type * base,cy_en_cryptolite_trng_ro_sel_t roSelector,uint8_t roStatus)791 __STATIC_INLINE void Cy_Cryptolite_Trng_SetRoStatus(CRYPTOLITE_Type *base,
792 cy_en_cryptolite_trng_ro_sel_t roSelector, uint8_t roStatus)
793 {
794 CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 10.6','enum cy_en_cryptolite_trng_ro_sel_t to uint32_t conversion intentional.');
795 uint32_t roMask = 1U << (uint32_t)roSelector;
796 uint32_t roData = (REG_CRYPTOLITE_TRNG_CTL1(base) & ~roMask) | (((uint32_t)roStatus != 0U) ? roMask : 0U);
797 REG_CRYPTOLITE_TRNG_CTL1(base) = roData;
798 }
799
800 /*******************************************************************************
801 * Function Name: Cy_Cryptolite_Trng_GetData
802 ****************************************************************************//**
803 *
804 * Reads the generated random number in non-blocking mode.
805 *
806 * \param base
807 * The pointer to the CRYPTOLITE instance.
808 *
809 * \return
810 * The generated random number.
811 *
812 *******************************************************************************/
Cy_Cryptolite_Trng_GetData(CRYPTOLITE_Type * base)813 __STATIC_INLINE uint32_t Cy_Cryptolite_Trng_GetData(CRYPTOLITE_Type *base)
814 {
815 return REG_CRYPTOLITE_TRNG_RESULT(base);
816 }
817
818 /*******************************************************************************
819 * Function Name: Cy_Cryptolite_Trng_SetGaroPoly
820 ****************************************************************************//**
821 *
822 * Sets the polynomial value for the Galois ring oscillator.
823 *
824 * \param base
825 * The pointer to the CRYPTOLITE instance.
826 *
827 * \param poly
828 * The polynomial for the programmable Galois ring oscillator.
829 *
830 *******************************************************************************/
Cy_Cryptolite_Trng_SetGaroPoly(CRYPTOLITE_Type * base,uint32_t poly)831 __STATIC_INLINE void Cy_Cryptolite_Trng_SetGaroPoly(CRYPTOLITE_Type *base, uint32_t poly)
832 {
833 REG_CRYPTOLITE_TRNG_GARO_CTL(base) = poly & CRYPTOLITE_TRNG_GARO_CTL_POLYNOMIAL_Msk;
834 }
835
836 /*******************************************************************************
837 * Function Name: Cy_Cryptolite_Trng_SetFiroPoly
838 ****************************************************************************//**
839 *
840 * Sets the polynomial value for the Fibonacci ring oscillator.
841 *
842 * \param base
843 * The pointer to the CRYPTOLITE instance.
844 *
845 * \param poly
846 * The polynomial for the programmable Fibonacci ring oscillator.
847 *
848 *******************************************************************************/
Cy_Cryptolite_Trng_SetFiroPoly(CRYPTOLITE_Type * base,uint32_t poly)849 __STATIC_INLINE void Cy_Cryptolite_Trng_SetFiroPoly(CRYPTOLITE_Type *base, uint32_t poly)
850 {
851 REG_CRYPTOLITE_TRNG_FIRO_CTL(base) = poly & CRYPTOLITE_TRNG_FIRO_CTL_POLYNOMIAL_Msk;
852 }
853
854 /*******************************************************************************
855 * Function Name: Cy_Cryptolite_Trng_GetGaroPoly
856 ****************************************************************************//**
857 *
858 * Reads the polynomial value of the Galois ring oscillator.
859 *
860 * \param base
861 * The pointer to the CRYPTOLITE instance.
862 *
863 * \return
864 * The polynomial of the programmable Galois ring oscillator.
865 *
866 *******************************************************************************/
Cy_Cryptolite_Trng_GetGaroPoly(CRYPTOLITE_Type * base)867 __STATIC_INLINE uint32_t Cy_Cryptolite_Trng_GetGaroPoly(CRYPTOLITE_Type *base)
868 {
869 return REG_CRYPTOLITE_TRNG_GARO_CTL(base);
870 }
871
872 /*******************************************************************************
873 * Function Name: Cy_Cryptolite_Trng_GetFiroPoly
874 ****************************************************************************//**
875 *
876 * Reads the polynomial value of the Fibonacci ring oscillator.
877 *
878 * \param base
879 * The pointer to the CRYPTOLITE instance.
880 *
881 * \return
882 * The polynomial of the programmable Fibonacci ring oscillator.
883 *
884 *******************************************************************************/
Cy_Cryptolite_Trng_GetFiroPoly(CRYPTOLITE_Type * base)885 __STATIC_INLINE uint32_t Cy_Cryptolite_Trng_GetFiroPoly(CRYPTOLITE_Type *base)
886 {
887 return REG_CRYPTOLITE_TRNG_FIRO_CTL(base);
888 }
889
890 /*******************************************************************************
891 * Function Name: Cy_Cryptolite_Trng_MonGetHealthStatus
892 ****************************************************************************//**
893 *
894 * Returns the health status of the random number health monitor in two bits.
895 *
896 * \param base
897 * The pointer to the CRYPTOLITE instance.
898 *
899 * \return
900 * The health status:
901 * - ZERO - if data is healthy
902 * - bit 0 - Adaptive Proportion (AP) error is detected
903 * - bit 1 - Repetition Count (RC) error is detected
904 *
905 *******************************************************************************/
Cy_Cryptolite_Trng_MonGetHealthStatus(CRYPTOLITE_Type * base)906 __STATIC_INLINE uint8_t Cy_Cryptolite_Trng_MonGetHealthStatus(CRYPTOLITE_Type *base)
907 {
908 return (uint8_t)((REG_CRYPTOLITE_INTR_TRNG(base) \
909 & (CRYPTOLITE_INTR_TRNG_AP_DETECT_Msk | CRYPTOLITE_INTR_TRNG_RC_DETECT_Msk)) \
910 >> CRYPTOLITE_INTR_TRNG_AP_DETECT_Pos);
911 }
912
913 /*******************************************************************************
914 * Function Name: Cy_Cryptolite_Trng_MonClearHealthStatus
915 ****************************************************************************//**
916 *
917 * Clears the health status of the random number health monitor
918 * in the interrupts register
919 *
920 * \param base
921 * The pointer to the CRYPTOLITE instance.
922 *
923 *******************************************************************************/
Cy_Cryptolite_Trng_MonClearHealthStatus(CRYPTOLITE_Type * base)924 __STATIC_INLINE void Cy_Cryptolite_Trng_MonClearHealthStatus(CRYPTOLITE_Type *base)
925 {
926 Cy_Cryptolite_Trng_ClearInterrupt(base, CRYPTOLITE_INTR_TRNG_AP_DETECT_Msk | CRYPTOLITE_INTR_TRNG_RC_DETECT_Msk);
927 }
928
929 /*******************************************************************************
930 * Function Name: Cy_Cryptolite_Trng_MonGetRcRepCount
931 ****************************************************************************//**
932 *
933 * Reads the current number of repetitions from the repetition counter
934 * test monitor.
935 *
936 * \param base
937 * The pointer to the CRYPTOLITE instance.
938 *
939 * \return
940 * The number of repetitions of the current active bit counter.
941 *
942 *******************************************************************************/
Cy_Cryptolite_Trng_MonGetRcRepCount(CRYPTOLITE_Type * base)943 __STATIC_INLINE uint8_t Cy_Cryptolite_Trng_MonGetRcRepCount(CRYPTOLITE_Type *base)
944 {
945 return ((uint8_t)_FLD2VAL(CRYPTOLITE_TRNG_MON_RC_STATUS1_REP_COUNT, REG_CRYPTOLITE_TRNG_MON_RC_STATUS1(base)));
946 }
947
948 /*******************************************************************************
949 * Function Name: Cy_Cryptolite_Trng_MonGetApOccCount
950 ****************************************************************************//**
951 *
952 * Reads the current Cutoff count number from the adaptive proportion
953 * test monitor.
954 *
955 * \param base
956 * The pointer to the CRYPTOLITE instance.
957 *
958 * \return
959 * The Cutoff count number of the adaptive proportion test.
960 *
961 *******************************************************************************/
Cy_Cryptolite_Trng_MonGetApOccCount(CRYPTOLITE_Type * base)962 __STATIC_INLINE uint16_t Cy_Cryptolite_Trng_MonGetApOccCount(CRYPTOLITE_Type *base)
963 {
964 return ((uint16_t)_FLD2VAL(CRYPTOLITE_TRNG_MON_AP_STATUS1_OCC_COUNT, REG_CRYPTOLITE_TRNG_MON_AP_STATUS1(base)));
965 }
966
967 /*******************************************************************************
968 * Function Name: Cy_Cryptolite_Trng_MonGetApWindowIndex
969 ****************************************************************************//**
970 *
971 * Reads the current window index from the adaptive proportion test monitor.
972 *
973 * \param base
974 * The pointer to the CRYPTOLITE instance.
975 *
976 * \return
977 * The window index of the adaptive proportion test.
978 *
979 *******************************************************************************/
Cy_Cryptolite_Trng_MonGetApWindowIndex(CRYPTOLITE_Type * base)980 __STATIC_INLINE uint16_t Cy_Cryptolite_Trng_MonGetApWindowIndex(CRYPTOLITE_Type *base)
981 {
982 return ((uint16_t)_FLD2VAL(CRYPTOLITE_TRNG_MON_AP_STATUS1_WINDOW_INDEX, REG_CRYPTOLITE_TRNG_MON_AP_STATUS1(base)));
983 }
984
985 /*******************************************************************************
986 * Function Name: Cy_Cryptolite_Trng_MonGetRcCurrentBit
987 ****************************************************************************//**
988 *
989 * Reads the active bit value from the adaptive proportion test monitor.
990 *
991 * \param base
992 * The pointer to the CRYPTOLITE instance.
993 *
994 * \return
995 * The active bit value.
996 *
997 *******************************************************************************/
Cy_Cryptolite_Trng_MonGetRcCurrentBit(CRYPTOLITE_Type * base)998 __STATIC_INLINE uint8_t Cy_Cryptolite_Trng_MonGetRcCurrentBit(CRYPTOLITE_Type *base)
999 {
1000 return ((uint8_t)_FLD2VAL(CRYPTOLITE_TRNG_MON_RC_STATUS0_BIT, REG_CRYPTOLITE_TRNG_MON_RC_STATUS0(base)));
1001 }
1002
1003 /*******************************************************************************
1004 * Function Name: Cy_Cryptolite_Trng_MonGetApCurrentBit
1005 ****************************************************************************//**
1006 *
1007 * Reads the active bit value from the repetition counter test monitor.
1008 *
1009 * \param base
1010 * The pointer to the CRYPTOLITE instance.
1011 *
1012 * \return
1013 * The active bit value.
1014 *
1015 *******************************************************************************/
Cy_Cryptolite_Trng_MonGetApCurrentBit(CRYPTOLITE_Type * base)1016 __STATIC_INLINE uint8_t Cy_Cryptolite_Trng_MonGetApCurrentBit(CRYPTOLITE_Type *base)
1017 {
1018 return ((uint8_t)_FLD2VAL(CRYPTOLITE_TRNG_MON_AP_STATUS0_BIT, REG_CRYPTOLITE_TRNG_MON_AP_STATUS0(base)));
1019 }
1020
1021
1022 /*******************************************************************************
1023 * Function Name: Cy_Cryptolite_Trng_MonSetBSSelector
1024 ****************************************************************************//**
1025 *
1026 * Sets the BitStream selector value of the TRNG monitor.
1027 *
1028 * \param base
1029 * The pointer to the CRYPTOLITE instance.
1030 *
1031 * \param bitStreamSelector
1032 * The BitStream selector value (see \ref cy_en_cryptolite_trng_bs_sel_t).
1033 *
1034 *******************************************************************************/
Cy_Cryptolite_Trng_MonSetBSSelector(CRYPTOLITE_Type * base,cy_en_cryptolite_trng_bs_sel_t bitStreamSelector)1035 __STATIC_INLINE cy_en_cryptolite_status_t Cy_Cryptolite_Trng_MonSetBSSelector(CRYPTOLITE_Type *base,
1036 cy_en_cryptolite_trng_bs_sel_t bitStreamSelector)
1037 {
1038 cy_en_cryptolite_status_t status = CY_CRYPTOLITE_SUCCESS;
1039
1040 CY_ASSERT_L3(CY_CRYPTOLITE_IS_BS_SELECT_VALID(bitStreamSelector));
1041
1042 CY_REG32_CLR_SET(REG_CRYPTOLITE_TRNG_MON_CTL(base), CRYPTOLITE_TRNG_MON_CTL_BITSTREAM_SEL, bitStreamSelector);
1043
1044 return status;
1045 }
1046
1047 /*******************************************************************************
1048 * Function Name: Cy_Cryptolite_Trng_MonGetBSSelector
1049 ****************************************************************************//**
1050 *
1051 * Reads the BitStream selector value of the TRNG monitor.
1052 *
1053 * \param base
1054 * The pointer to the CRYPTOLITE instance.
1055 *
1056 * \return
1057 * The BitStream selector value (see \ref cy_en_cryptolite_trng_bs_sel_t).
1058 *
1059 *******************************************************************************/
Cy_Cryptolite_Trng_MonGetBSSelector(CRYPTOLITE_Type * base)1060 __STATIC_INLINE cy_en_cryptolite_trng_bs_sel_t Cy_Cryptolite_Trng_MonGetBSSelector(CRYPTOLITE_Type *base)
1061 {
1062 CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 10.8','Intentional typecast to cy_en_cryptolite_trng_bs_sel_t enum.');
1063 return ((cy_en_cryptolite_trng_bs_sel_t)_FLD2VAL(CRYPTOLITE_TRNG_MON_CTL_BITSTREAM_SEL, REG_CRYPTOLITE_TRNG_MON_CTL(base)));
1064 }
1065
1066 /*******************************************************************************
1067 * Function Name: Cy_Cryptolite_Trng_MonEnableApTest
1068 ****************************************************************************//**
1069 *
1070 * Enables the Adaptive proportion (AP) test.
1071 *
1072 * \param base
1073 * The pointer to the CRYPTOLITE instance.
1074 *
1075 *******************************************************************************/
Cy_Cryptolite_Trng_MonEnableApTest(CRYPTOLITE_Type * base)1076 __STATIC_INLINE void Cy_Cryptolite_Trng_MonEnableApTest(CRYPTOLITE_Type *base)
1077 {
1078 CY_REG32_CLR_SET(REG_CRYPTOLITE_TRNG_MON_CTL(base), CRYPTOLITE_TRNG_MON_CTL_AP, 1U);
1079 }
1080
1081 /*******************************************************************************
1082 * Function Name: Cy_Cryptolite_Trng_MonDisableApTest
1083 ****************************************************************************//**
1084 *
1085 * Disables the Adaptive proportion (AP) test.
1086 *
1087 * \param base
1088 * The pointer to the CRYPTOLITE instance.
1089 *
1090 *******************************************************************************/
Cy_Cryptolite_Trng_MonDisableApTest(CRYPTOLITE_Type * base)1091 __STATIC_INLINE void Cy_Cryptolite_Trng_MonDisableApTest(CRYPTOLITE_Type *base)
1092 {
1093 CY_REG32_CLR_SET(REG_CRYPTOLITE_TRNG_MON_CTL(base), CRYPTOLITE_TRNG_MON_CTL_AP, 0U);
1094 }
1095
1096 /*******************************************************************************
1097 * Function Name: Cy_Cryptolite_Trng_MonEnableRcTest
1098 ****************************************************************************//**
1099 *
1100 * Enables the Repetition count (RC) test.
1101 *
1102 * \param base
1103 * The pointer to the CRYPTOLITE instance.
1104 *
1105 *******************************************************************************/
Cy_Cryptolite_Trng_MonEnableRcTest(CRYPTOLITE_Type * base)1106 __STATIC_INLINE void Cy_Cryptolite_Trng_MonEnableRcTest(CRYPTOLITE_Type *base)
1107 {
1108 CY_REG32_CLR_SET(REG_CRYPTOLITE_TRNG_MON_CTL(base), CRYPTOLITE_TRNG_MON_CTL_RC, 1U);
1109 }
1110
1111 /*******************************************************************************
1112 * Function Name: Cy_Cryptolite_Trng_MonDisableRcTest
1113 ****************************************************************************//**
1114 *
1115 * Disables the Repetition count (RC) test.
1116 *
1117 * \param base
1118 * The pointer to the CRYPTOLITE instance.
1119 *
1120 *******************************************************************************/
Cy_Cryptolite_Trng_MonDisableRcTest(CRYPTOLITE_Type * base)1121 __STATIC_INLINE void Cy_Cryptolite_Trng_MonDisableRcTest(CRYPTOLITE_Type *base)
1122 {
1123 CY_REG32_CLR_SET(REG_CRYPTOLITE_TRNG_MON_CTL(base), CRYPTOLITE_TRNG_MON_CTL_RC, 0U);
1124 }
1125
1126 /*******************************************************************************
1127 * Function Name: Cy_Cryptolite_Trng_MonSetRcCC8
1128 ****************************************************************************//**
1129 *
1130 * Sets the Cutoff counter value of the repetition counter test monitor.
1131 *
1132 * \param base
1133 * The pointer to the CRYPTOLITE instance.
1134 *
1135 * \param ccCount
1136 * The new Cutoff counter value.
1137 *
1138 *******************************************************************************/
Cy_Cryptolite_Trng_MonSetRcCC8(CRYPTOLITE_Type * base,uint8_t ccCount)1139 __STATIC_INLINE void Cy_Cryptolite_Trng_MonSetRcCC8(CRYPTOLITE_Type *base, uint8_t ccCount)
1140 {
1141 REG_CRYPTOLITE_TRNG_MON_RC_CTL(base) = (uint32_t)_VAL2FLD(CRYPTOLITE_TRNG_MON_RC_CTL_CUTOFF_COUNT8, ccCount);
1142 }
1143
1144 /*******************************************************************************
1145 * Function Name: Cy_Cryptolite_Trng_MonGetRcCC8
1146 ****************************************************************************//**
1147 *
1148 * Reads the Cutoff counter value of the repetition counter test monitor.
1149 *
1150 * \param base
1151 * The pointer to the CRYPTOLITE instance.
1152 *
1153 * \return
1154 * The Cutoff counter value.
1155 *
1156 *******************************************************************************/
Cy_Cryptolite_Trng_MonGetRcCC8(CRYPTOLITE_Type * base)1157 __STATIC_INLINE uint8_t Cy_Cryptolite_Trng_MonGetRcCC8(CRYPTOLITE_Type *base)
1158 {
1159 return ((uint8_t)_FLD2VAL(CRYPTOLITE_TRNG_MON_RC_CTL_CUTOFF_COUNT8, REG_CRYPTOLITE_TRNG_MON_RC_CTL(base)));
1160 }
1161
1162 /*******************************************************************************
1163 * Function Name: Cy_Cryptolite_Trng_MonSetApCC16
1164 ****************************************************************************//**
1165 *
1166 * Sets the Cutoff counter value of the adaptive proportion test monitor.
1167 *
1168 * \param base
1169 * The pointer to the CRYPTOLITE instance.
1170 *
1171 * \param ccCount
1172 * The new Cutoff counter value.
1173 *
1174 *******************************************************************************/
Cy_Cryptolite_Trng_MonSetApCC16(CRYPTOLITE_Type * base,uint16_t ccCount)1175 __STATIC_INLINE void Cy_Cryptolite_Trng_MonSetApCC16(CRYPTOLITE_Type *base, uint16_t ccCount)
1176 {
1177 CY_REG32_CLR_SET(REG_CRYPTOLITE_TRNG_MON_AP_CTL(base), CRYPTOLITE_TRNG_MON_AP_CTL_CUTOFF_COUNT16, ccCount);
1178 }
1179
1180 /*******************************************************************************
1181 * Function Name: Cy_Cryptolite_Trng_MonGetApCC16
1182 ****************************************************************************//**
1183 *
1184 * Reads the Cutoff counter value of the adaptive proportion test monitor.
1185 *
1186 * \param base
1187 * The pointer to the CRYPTOLITE instance.
1188 *
1189 * \return
1190 * The Cutoff counter value.
1191 *
1192 *******************************************************************************/
Cy_Cryptolite_Trng_MonGetApCC16(CRYPTOLITE_Type * base)1193 __STATIC_INLINE uint16_t Cy_Cryptolite_Trng_MonGetApCC16(CRYPTOLITE_Type *base)
1194 {
1195 return ((uint16_t)_FLD2VAL(CRYPTOLITE_TRNG_MON_AP_CTL_CUTOFF_COUNT16, REG_CRYPTOLITE_TRNG_MON_AP_CTL(base)));
1196 }
1197
1198 /*******************************************************************************
1199 * Function Name: Cy_Cryptolite_Trng_MonSetApWinSize
1200 ****************************************************************************//**
1201 *
1202 * Sets the window size value of the adaptive proportion test monitor.
1203 *
1204 * \param base
1205 * The pointer to the CRYPTOLITE instance.
1206 *
1207 * \param windowSize
1208 * The new windows size value.
1209 *
1210 *******************************************************************************/
Cy_Cryptolite_Trng_MonSetApWinSize(CRYPTOLITE_Type * base,uint16_t windowSize)1211 __STATIC_INLINE void Cy_Cryptolite_Trng_MonSetApWinSize(CRYPTOLITE_Type *base, uint16_t windowSize)
1212 {
1213 CY_REG32_CLR_SET(REG_CRYPTOLITE_TRNG_MON_AP_CTL(base), CRYPTOLITE_TRNG_MON_AP_CTL_WINDOW_SIZE, windowSize);
1214 }
1215
1216 /*******************************************************************************
1217 * Function Name: Cy_Cryptolite_Trng_MonGetApWinSize
1218 ****************************************************************************//**
1219 *
1220 * Reads the window size value of the adaptive proportion test monitor.
1221 *
1222 * \param base
1223 * The pointer to the CRYPTOLITE instance.
1224 *
1225 * \return
1226 * The windows size value.
1227 *
1228 *******************************************************************************/
Cy_Cryptolite_Trng_MonGetApWinSize(CRYPTOLITE_Type * base)1229 __STATIC_INLINE uint16_t Cy_Cryptolite_Trng_MonGetApWinSize(CRYPTOLITE_Type *base)
1230 {
1231 return ((uint16_t)_FLD2VAL(CRYPTOLITE_TRNG_MON_AP_CTL_WINDOW_SIZE, REG_CRYPTOLITE_TRNG_MON_AP_CTL(base)));
1232 }
1233
1234
1235 #endif /* #if (CY_CRYPTOLITE_CFG_TRNG_C)*/
1236 #endif /* #if CRYPTOLITE_TRNG_PRESENT*/
1237
1238 /** \} group_cryptolite_lld_trng_functions */
1239 #if defined(__cplusplus)
1240 }
1241 #endif
1242
1243 #endif /* CY_IP_MXCRYPTOLITE */
1244
1245 #endif /* #if !defined (CY_CRYPTOLITE_TRNG_H) */
1246
1247 /* [] END OF FILE */
1248