gr55xx_ll_rng.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_ll_rng.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of RNG LL library.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup LL_DRIVER LL Driver
43 * @{
44 */
45
46 /** @defgroup LL_RNG RNG
47 * @brief RNG LL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55XX_LL_RNG_H__
53 #define __GR55XX_LL_RNG_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx.h"
61
62 #if defined (RNG)
63
64 /** @defgroup RNG_LL_STRUCTURES Structures
65 * @{
66 */
67
68 /* Exported types ------------------------------------------------------------*/
69 /** @defgroup RNG_LL_ES_INIT RNG Exported Init structures
70 * @{
71 */
72
73 /**
74 * @brief LL RNG Init Structure definition
75 */
76 typedef struct _ll_rng_init
77 {
78 uint32_t seed; /**< Specifies the seed source for the LFSR.
79 This parameter can be a value of @ref RNG_LL_EC_SEED_SOURCE */
80
81 uint32_t lfsr_mode; /**< Specifies the configuration mode for the LFSR.
82 This parameter can be a value of @ref RNG_LL_EC_LFSR_MODE */
83
84 uint32_t out_mode; /**< Specifies the Output mode for the RNG.
85 This parameter can be a value of @ref RNG_LL_EC_OUTPUT_MODE */
86
87 uint32_t post_mode; /**< Specifies post-process configuration for the RNG.
88 This parameter can be a value of @ref RNG_LL_EC_POST_PRO */
89
90 uint32_t interrupt; /**< Specifies interrupt configuration for the RNG.
91 This parameter can be a value of @ref RNG_LL_EC_IT */
92
93 } ll_rng_init_t;
94
95 /** @} */
96
97 /** @} */
98
99 /** @defgroup RNG_LL_MACRO Defines
100 * @{
101 */
102 /* Exported constants --------------------------------------------------------*/
103 /** @defgroup RNG_LL_Exported_Constants RNG Exported Constants
104 * @{
105 */
106
107 /** @defgroup RNG_LL_EC_SEED_SOURCE LFSR seed source
108 * @{
109 */
110 #define LL_RNG_SEED_FR0_S0 (4UL << RNG_CONFIG_LFSR_SEED_SEL_Pos) /**< LFSR seed is from the switching oscillator s0. */
111 #define LL_RNG_SEED_USER (6UL << RNG_CONFIG_LFSR_SEED_SEL_Pos) /**< LFSR seed is configured by users. */
112 /** @} */
113
114
115 /** @defgroup RNG_LL_EC_LFSR_MODE LFSR configuration mode
116 * @{
117 */
118 #define LL_RNG_LFSR_MODE_59BIT (0x00000000UL) /**< 59 bit LFSR. */
119 #define LL_RNG_LFSR_MODE_128BIT (1UL << RNG_CONFIG_LFSR_MODE_Pos) /**< 128 bit LFSR. */
120 /** @} */
121
122 /** @defgroup RNG_LL_EC_POST_PRO Post-process mode
123 * @{
124 */
125 #define LL_RNG_POST_PRO_NOT (0x00000000UL) /**< No post process. */
126 #define LL_RNG_POST_PRO_SKIPPING (1UL << RNG_CONFIG_POST_MODE_Pos) /**< bit skipping. */
127 #define LL_RNG_POST_PRO_COUNTING (2UL << RNG_CONFIG_POST_MODE_Pos) /**< bit counting. */
128 #define LL_RNG_POST_PRO_NEUMANN (3UL << RNG_CONFIG_POST_MODE_Pos) /**< Von-Neumann. */
129 /** @} */
130
131 /** @defgroup RNG_LL_EC_IT RNG hardware interrupt enable.
132 * @{
133 */
134 #define LL_RNG_IT_DISABLE (0x00000000UL) /**< Disable RNG interrupt. */
135 #define LL_RNG_IT_ENABLE (1UL << RNG_CONFIG_IRQ_EN_Pos) /**< Enable RNG interrupt. */
136 /** @} */
137
138 /** @defgroup RNG_LL_EC_OUTPUT_MODE RNG Output mode
139 * @{
140 */
141 #define LL_RNG_OUTPUT_FR0_S0 (4UL << RNG_CONFIG_OUT_MODE_Pos) /**< Digital RNG direct output, ring oscillator s0. */
142 #define LL_RNG_OUTPUT_CYCLIC_PARITY (6UL << RNG_CONFIG_OUT_MODE_Pos) /**< LFSR and RNG cyclic sampling and parity generation. */
143 #define LL_RNG_OUTPUT_CYCLIC (7UL << RNG_CONFIG_OUT_MODE_Pos) /**< LFSR and RNG cyclic sampling. */
144 #define LL_RNG_OUTPUT_LFSR_RNG (8UL << RNG_CONFIG_OUT_MODE_Pos) /**< LFSR ⊕ RNG. */
145 #define LL_RNG_OUTPUT_LFSR (9UL << RNG_CONFIG_OUT_MODE_Pos) /**< LFSR direct output. */
146 /** @} */
147
148 /** @} */
149
150 /* Exported macro ------------------------------------------------------------*/
151 /** @defgroup RNG_LL_Exported_Macros RNG Exported Macros
152 * @{
153 */
154
155 /** @defgroup RNG_LL_EM_WRITE_READ Common Write and read registers Macros
156 * @{
157 */
158
159 /**
160 * @brief Write a value in RNG register
161 * @param __instance__ RNG instance
162 * @param __REG__ Register to be written
163 * @param __VALUE__ Value to be written in the register
164 * @retval None.
165 */
166 #define LL_RNG_WriteReg(__instance__, __REG__, __VALUE__) WRITE_REG(__instance__->__REG__, (__VALUE__))
167
168 /**
169 * @brief Read a value in RNG register
170 * @param __instance__ RNG instance
171 * @param __REG__ Register to be read
172 * @retval Register value
173 */
174 #define LL_RNG_ReadReg(__instance__, __REG__) READ_REG(__instance__->__REG__)
175 /** @} */
176
177 /** @} */
178 /** @} */
179
180
181 /* Exported functions --------------------------------------------------------*/
182 /** @defgroup RNG_LL_Exported_Functions Functions
183 * @{
184 */
185
186 /** @defgroup RNG_LL_EF_Configuration RNG Configuration functions
187 * @{
188 */
189
190 /**
191 * @brief Enable Random Number Generation.
192 *
193 * \rst
194 * +----------------------+-----------------------------------+
195 * | Register | BitsName |
196 * +======================+===================================+
197 * | CTRL | RNG_RUN |
198 * +----------------------+-----------------------------------+
199 * \endrst
200 *
201 * @param RNGx RNG instance.
202 * @retval None
203 */
204 __STATIC_INLINE void ll_rng_enable(rng_regs_t *RNGx)
205 {
206 SET_BITS(RNGx->CTRL, RNG_CTRL_RUN_EN);
207 }
208
209 /**
210 * @brief Disable Random Number Generation.
211 *
212 * \rst
213 * +----------------------+-----------------------------------+
214 * | Register | BitsName |
215 * +======================+===================================+
216 * | CTRL | RNG_RUN |
217 * +----------------------+-----------------------------------+
218 * \endrst
219 *
220 * @param RNGx RNG instance.
221 * @retval None
222 */
223 __STATIC_INLINE void ll_rng_disable(rng_regs_t *RNGx)
224 {
225 CLEAR_BITS(RNGx->CTRL, RNG_CTRL_RUN_EN);
226 }
227
228 /**
229 * @brief Check if Random Number Generator is enabled.
230 *
231 * \rst
232 * +----------------------+-----------------------------------+
233 * | Register | BitsName |
234 * +======================+===================================+
235 * | CTRL | RNG_RUN |
236 * +----------------------+-----------------------------------+
237 * \endrst
238 *
239 * @param RNGx RNG instance.
240 * @retval State of bit (1 or 0).
241 */
242 __STATIC_INLINE uint32_t ll_rng_is_enabled(rng_regs_t *RNGx)
243 {
244 return (READ_BITS(RNGx->CTRL, RNG_CTRL_RUN_EN) == (RNG_CTRL_RUN_EN));
245 }
246
247 /**
248 * @brief Enable Ring oscillator TRNG enabled signal.
249 *
250 * \rst
251 * +----------------------+-----------------------------------+
252 * | Register | BitsName |
253 * +======================+===================================+
254 * | CONFIG | RNG_FRO_EN |
255 * +----------------------+-----------------------------------+
256 * \endrst
257 *
258 * @param RNGx RNG instance.
259 * @retval None
260 */
261 __STATIC_INLINE void ll_rng_enable_fro(rng_regs_t *RNGx)
262 {
263 SET_BITS(RNGx->CONFIG, RNG_CONFIG_FRO_EN);
264 }
265
266 /**
267 * @brief Disable Ring oscillator TRNG enabled signal.
268 *
269 * \rst
270 * +----------------------+-----------------------------------+
271 * | Register | BitsName |
272 * +======================+===================================+
273 * | CTRL | RNG_RUN |
274 * +----------------------+-----------------------------------+
275 * \endrst
276 *
277 * @param RNGx RNG instance.
278 * @retval None
279 */
280 __STATIC_INLINE void ll_rng_disable_fro(rng_regs_t *RNGx)
281 {
282 CLEAR_BITS(RNGx->CONFIG, RNG_CONFIG_FRO_EN);
283 }
284
285 /**
286 * @brief Check if Ring oscillator TRNG enabled signal is enabled.
287 *
288 * \rst
289 * +----------------------+-----------------------------------+
290 * | Register | BitsName |
291 * +======================+===================================+
292 * | CTRL | RNG_RUN |
293 * +----------------------+-----------------------------------+
294 * \endrst
295 *
296 * @param RNGx RNG instance.
297 * @retval State of bit (1 or 0).
298 */
299 __STATIC_INLINE uint32_t ll_rng_fro_is_enabled(rng_regs_t *RNGx)
300 {
301 return (READ_BITS(RNGx->CONFIG, RNG_CONFIG_FRO_EN) == (RNG_CONFIG_FRO_EN));
302 }
303
304 /**
305 * @brief Set source of LFSR seed.
306 *
307 * \rst
308 * +----------------------+-----------------------------------+
309 * | Register | BitsName |
310 * +======================+===================================+
311 * | CONFIG | RNG_LFSR_SEED_SEL |
312 * +----------------------+-----------------------------------+
313 * \endrst
314 *
315 * @param RNGx RNG instance.
316 * @param seed This parameter can be one of the following values:
317 * @arg @ref LL_RNG_SEED_FR0_S0
318 * @arg @ref LL_RNG_SEED_USER
319 * @retval None
320 */
321 __STATIC_INLINE void ll_rng_set_lfsr_seed(rng_regs_t *RNGx, uint32_t seed)
322 {
323 MODIFY_REG(RNGx->CONFIG, RNG_CONFIG_LFSR_SEED_SEL, seed);
324 }
325
326 /**
327 * @brief Get source of LFSR seed.
328 *
329 * \rst
330 * +----------------------+-----------------------------------+
331 * | Register | BitsName |
332 * +======================+===================================+
333 * | CONFIG | RNG_LFSR_SEED_SEL |
334 * +----------------------+-----------------------------------+
335 * \endrst
336 *
337 * @param RNGx RNG instance.
338 * @retval Returned value can be one of the following values:
339 * @arg @ref LL_RNG_SEED_FR0_S0
340 * @arg @ref LL_RNG_SEED_USER
341 */
342 __STATIC_INLINE uint32_t ll_rng_get_lfsr_seed(rng_regs_t *RNGx)
343 {
344 return READ_BITS(RNGx->CONFIG, RNG_CONFIG_LFSR_SEED_SEL);
345 }
346
347 /**
348 * @brief Set LFSR configuration mode.
349 *
350 * \rst
351 * +----------------------+-----------------------------------+
352 * | Register | BitsName |
353 * +======================+===================================+
354 * | CONFIG | RNG_LFSR_MODE |
355 * +----------------------+-----------------------------------+
356 * \endrst
357 *
358 * @param RNGx RNG instance.
359 * @param mode This parameter can be one of the following values:
360 * @arg @ref LL_RNG_LFSR_MODE_59BIT
361 * @arg @ref LL_RNG_LFSR_MODE_128BIT
362 * @retval None
363 */
364 __STATIC_INLINE void ll_rng_set_lfsr_mode(rng_regs_t *RNGx, uint32_t mode)
365 {
366 MODIFY_REG(RNGx->CONFIG, RNG_CONFIG_LFSR_MODE, mode);
367 }
368
369 /**
370 * @brief Get LFSR configuration mode.
371 *
372 * \rst
373 * +----------------------+-----------------------------------+
374 * | Register | BitsName |
375 * +======================+===================================+
376 * | CONFIG | RNG_LFSR_MODE |
377 * +----------------------+-----------------------------------+
378 * \endrst
379 *
380 * @param RNGx RNG instance.
381 * @retval Returned value can be one of the following values:
382 * @arg @ref LL_RNG_LFSR_MODE_59BIT
383 * @arg @ref LL_RNG_LFSR_MODE_128BIT
384 */
385 __STATIC_INLINE uint32_t ll_rng_get_lfsr_mode(rng_regs_t *RNGx)
386 {
387 return READ_BITS(RNGx->CONFIG, RNG_CONFIG_LFSR_MODE);
388 }
389
390 /**
391 * @brief Set RNG post-process configuration.
392 *
393 * \rst
394 * +----------------------+-----------------------------------+
395 * | Register | BitsName |
396 * +======================+===================================+
397 * | CONFIG | RNG_POST_MODE |
398 * +----------------------+-----------------------------------+
399 * \endrst
400 *
401 * @param RNGx RNG instance.
402 * @param post This parameter can be one of the following values:
403 * @arg @ref LL_RNG_POST_PRO_NOT
404 * @arg @ref LL_RNG_POST_PRO_SKIPPING
405 * @arg @ref LL_RNG_POST_PRO_COUNTING
406 * @arg @ref LL_RNG_POST_PRO_NEUMANN
407 * @retval None
408 */
409 __STATIC_INLINE void ll_rng_set_post_mode(rng_regs_t *RNGx, uint32_t post)
410 {
411 MODIFY_REG(RNGx->CONFIG, RNG_CONFIG_POST_MODE, post);
412 }
413
414 /**
415 * @brief Get RNG post-process configuration.
416 *
417 * \rst
418 * +----------------------+-----------------------------------+
419 * | Register | BitsName |
420 * +======================+===================================+
421 * | CONFIG | RNG_POST_MODE |
422 * +----------------------+-----------------------------------+
423 * \endrst
424 *
425 * @param RNGx RNG instance.
426 * @retval Returned value can be one of the following values:
427 * @arg @ref LL_RNG_POST_PRO_NOT
428 * @arg @ref LL_RNG_POST_PRO_SKIPPING
429 * @arg @ref LL_RNG_POST_PRO_COUNTING
430 * @arg @ref LL_RNG_POST_PRO_NEUMANN
431 */
432 __STATIC_INLINE uint32_t ll_rng_get_post_mode(rng_regs_t *RNGx)
433 {
434 return READ_BITS(RNGx->CONFIG, RNG_CONFIG_POST_MODE);
435 }
436
437 /**
438 * @brief set RNG output mode.
439 *
440 * \rst
441 * +----------------------+-----------------------------------+
442 * | Register | BitsName |
443 * +======================+===================================+
444 * | CONFIG | RNG_OUT_MODE |
445 * +----------------------+-----------------------------------+
446 * \endrst
447 *
448 * @param RNGx RNG instance.
449 * @param mode This parameter can be one of the following values:
450 * @arg @ref LL_RNG_OUTPUT_FR0_S0
451 * @arg @ref LL_RNG_OUTPUT_CYCLIC_PARITY
452 * @arg @ref LL_RNG_OUTPUT_CYCLIC
453 * @arg @ref LL_RNG_OUTPUT_LFSR_RNG
454 * @arg @ref LL_RNG_OUTPUT_LFSR
455 * @retval None
456 */
457 __STATIC_INLINE void ll_rng_set_output_mode(rng_regs_t *RNGx, uint32_t mode)
458 {
459 MODIFY_REG(RNGx->CONFIG, RNG_CONFIG_OUT_MODE, mode);
460 }
461
462 /**
463 * @brief get RNG output mode.
464 *
465 * \rst
466 * +----------------------+-----------------------------------+
467 * | Register | BitsName |
468 * +======================+===================================+
469 * | CONFIG | RNG_OUT_MODE |
470 * +----------------------+-----------------------------------+
471 * \endrst
472 *
473 * @param RNGx RNG instance.
474 * @retval Returned value can be one of the following values:
475 * @arg @ref LL_RNG_OUTPUT_FR0_S0
476 * @arg @ref LL_RNG_OUTPUT_CYCLIC_PARITY
477 * @arg @ref LL_RNG_OUTPUT_CYCLIC
478 * @arg @ref LL_RNG_OUTPUT_LFSR_RNG
479 * @arg @ref LL_RNG_OUTPUT_LFSR
480 */
481 __STATIC_INLINE uint32_t ll_rng_get_output_mode(rng_regs_t *RNGx)
482 {
483 return READ_BITS(RNGx->CONFIG, RNG_CONFIG_OUT_MODE);
484 }
485
486 /**
487 * @brief set the waiting time that RNG input reaches stable.
488 *
489 * \rst
490 * +----------------------+-----------------------------------+
491 * | Register | BitsName |
492 * +======================+===================================+
493 * | TSCON | RNG_TRDY_TIME |
494 * +----------------------+-----------------------------------+
495 * \endrst
496 *
497 * @param RNGx RNG instance.
498 * @param time range between 0x1 and 0xFF.
499 * @retval None
500 */
501 __STATIC_INLINE void ll_rng_set_trdy_time(rng_regs_t *RNGx, uint32_t time)
502 {
503 MODIFY_REG(RNGx->TSCON, RNG_TSCON_TRDY_TIME, time);
504 }
505
506 /**
507 * @brief get the waiting time that RNG input reaches stable.
508 *
509 * \rst
510 * +----------------------+-----------------------------------+
511 * | Register | BitsName |
512 * +======================+===================================+
513 * | TSCON | RNG_TRDY_TIME |
514 * +----------------------+-----------------------------------+
515 * \endrst
516 *
517 * @param RNGx RNG instance.
518 * @retval Between Min_Time = 0 and Max_Time = 0xFF
519 */
520 __STATIC_INLINE uint32_t ll_rng_get_trdy_time(rng_regs_t *RNGx)
521 {
522 return READ_BITS(RNGx->TSCON, RNG_TSCON_TRDY_TIME);
523 }
524
525
526 /**
527 * @brief set RNG seed configured by user.
528 *
529 * \rst
530 * +----------------------+-----------------------------------+
531 * | Register | BitsName |
532 * +======================+===================================+
533 * | USER | RNG_USER_SEED |
534 * +----------------------+-----------------------------------+
535 * \endrst
536 *
537 * @param RNGx RNG instance.
538 * @param seed range between 0x1 and 0xFFFF.
539 * @retval None
540 */
541 __STATIC_INLINE void ll_rng_set_user_seed(rng_regs_t *RNGx, uint32_t seed)
542 {
543 WRITE_REG(RNGx->USER_SEED, seed);
544 }
545
546 /** @} */
547
548 /** @defgroup RNG_LL_EF_FLAG_Management FLAG Management
549 * @{
550 */
551
552 /**
553 * @brief Indicate if the Flag of RNG long run test is set or not.
554 *
555 * Register |BitsName
556 * ---------|--------
557 * LR_STATUS| RNG_LR_FLAG
558 *
559 * @param RNGx RNG instance.
560 * @retval State of bit (1 or 0).
561 */
562 __STATIC_INLINE uint32_t ll_rng_is_active_flag_lr(rng_regs_t *RNGx)
563 {
564 return (READ_BITS(RNGx->LR_STATUS, RNG_LR_STATUS_FLAG) == (RNG_LR_STATUS_FLAG));
565 }
566
567 /**
568 * @brief Indicate if the RNG Status Flag is set or not.
569 *
570 * \rst
571 * +----------------------+-----------------------------------+
572 * | Register | BitsName |
573 * +======================+===================================+
574 * | STATUS | RNG_READY |
575 * +----------------------+-----------------------------------+
576 * \endrst
577 *
578 * @param RNGx RNG instance.
579 * @retval State of bit (1 or 0).
580 */
581 __STATIC_INLINE uint32_t ll_rng_is_active_flag_sts(rng_regs_t *RNGx)
582 {
583 return (READ_BITS(RNGx->STATUS, RNG_STATUS_READY) == (RNG_STATUS_READY));
584 }
585
586 /**
587 * @brief Clear RNG Status flag.
588 *
589 * \rst
590 * +----------------------+-----------------------------------+
591 * | Register | BitsName |
592 * +======================+===================================+
593 * | STATUS | RNG_READY |
594 * +----------------------+-----------------------------------+
595 * \endrst
596 *
597 * @param RNGx RNG instance.
598 * @retval None
599 */
600 __STATIC_INLINE void ll_rng_clear_flag_sts(rng_regs_t *RNGx)
601 {
602 WRITE_REG(RNGx->STATUS, RNG_STATUS_READY);
603 }
604
605 /** @} */
606
607 /** @defgroup RNG_LL_EF_IT_Management IT Management
608 * @{
609 */
610
611 /**
612 * @brief Enable Random Number Generator Interrupt
613 *
614 * \rst
615 * +----------------------+-----------------------------------+
616 * | Register | BitsName |
617 * +======================+===================================+
618 * | CONFIG | RNG_IRQ_EN |
619 * +----------------------+-----------------------------------+
620 * \endrst
621 *
622 * @param RNGx RNG instance.
623 * @retval None
624 */
625 __STATIC_INLINE void ll_rng_enable_it(rng_regs_t *RNGx)
626 {
627 SET_BITS(RNGx->CONFIG, RNG_CONFIG_IRQ_EN);
628 }
629
630 /**
631 * @brief Disable Random Number Generator Interrupt
632 *
633 * \rst
634 * +----------------------+-----------------------------------+
635 * | Register | BitsName |
636 * +======================+===================================+
637 * | CONFIG | RNG_IRQ_EN |
638 * +----------------------+-----------------------------------+
639 * \endrst
640 *
641 * @param RNGx RNG instance.
642 * @retval None
643 */
644 __STATIC_INLINE void ll_rng_disable_it(rng_regs_t *RNGx)
645 {
646 CLEAR_BITS(RNGx->CONFIG, RNG_CONFIG_IRQ_EN);
647 }
648
649 /**
650 * @brief Check if Random Number Generator Interrupt is enabled
651 *
652 * \rst
653 * +----------------------+-----------------------------------+
654 * | Register | BitsName |
655 * +======================+===================================+
656 * | CONFIG | RNG_IRQ_EN |
657 * +----------------------+-----------------------------------+
658 * \endrst
659 *
660 * @param RNGx RNG instance.
661 * @retval State of bit (1 or 0).
662 */
663 __STATIC_INLINE uint32_t ll_rng_is_enabled_it(rng_regs_t *RNGx)
664 {
665 return (READ_BITS(RNGx->CONFIG, RNG_CONFIG_IRQ_EN) == (RNG_CONFIG_IRQ_EN));
666 }
667
668 /** @} */
669
670 /** @defgroup RNG_LL_EF_Data_Management Data Management
671 * @{
672 */
673
674 /**
675 * @brief Return32-bit Random Number value
676 *
677 * \rst
678 * +----------------------+-----------------------------------+
679 * | Register | BitsName |
680 * +======================+===================================+
681 * | DATA | RNG_DATA |
682 * +----------------------+-----------------------------------+
683 * \endrst
684 *
685 * @param RNGx RNG instance.
686 * @retval Generated 32-bit random value
687 */
688 __STATIC_INLINE uint32_t ll_rng_read_random_data32(rng_regs_t *RNGx)
689 {
690 return (uint32_t)(READ_REG(RNGx->DATA));
691 }
692
693 /**
694 * @brief Return8-bit RNG Long Run Test counts.
695 *
696 * Register |BitsName
697 * ---------|--------
698 * LR_STATUS| RNG_LR_CNT
699 *
700 * @param RNGx RNG instance.
701 * @retval Output Data[7:0]
702 */
703 __STATIC_INLINE uint32_t ll_rng_read_lr_count(rng_regs_t *RNGx)
704 {
705 return READ_BITS(RNGx->LR_STATUS, RNG_LR_STATUS_CNT) >> RNG_LR_STATUS_CNT_Pos;
706 }
707
708 /** @} */
709
710 /** @defgroup RNG_LL_EF_Init Initialization and de-initialization functions
711 * @{
712 */
713
714 /**
715 * @brief De-initialize the RNG registers to their default reset values.
716 * @param RNGx RNG instance.
717 * @retval An error_status_t enumeration value:
718 * - SUCCESS: RNG registers are de-initialized
719 * - ERROR: RNG registers are not de-initialized
720 */
721 error_status_t ll_rng_deinit(rng_regs_t *RNGx);
722
723 /**
724 * @brief Initialize RNG registers according to the specified
725 * parameters in p_rng_init.
726 * @param RNGx RNG Instance
727 * @param p_rng_init Pointer to a ll_rng_init_t structure that contains the configuration
728 * information for the specified RNG peripheral.
729 * @retval An error_status_t enumeration value:
730 * - SUCCESS: RNG registers are initialized according to p_rng_init content
731 * - ERROR: Problem occurred during RNG Registers initialization
732 */
733 error_status_t ll_rng_init(rng_regs_t *RNGx, ll_rng_init_t *p_rng_init);
734
735 /**
736 * @brief Set each field of a @ref ll_rng_init_t type structure to default value.
737 * @param p_rng_init Pointer to a @ref ll_rng_init_t structure
738 * whose fields will be set to default values.
739 * @retval None
740 */
741 void ll_rng_struct_init(ll_rng_init_t *p_rng_init);
742
743 /** @} */
744
745 /** @} */
746
747 #endif /* RNG */
748
749 #ifdef __cplusplus
750 }
751 #endif
752
753 #endif /* __GR55XX_LL_RNG_H__ */
754
755 /** @} */
756
757 /** @} */
758
759 /** @} */
ll_rng_deinit
error_status_t ll_rng_deinit(rng_regs_t *RNGx)
De-initialize the RNG registers to their default reset values.
ll_rng_is_active_flag_lr
__STATIC_INLINE uint32_t ll_rng_is_active_flag_lr(rng_regs_t *RNGx)
Indicate if the Flag of RNG long run test is set or not.
Definition: gr55xx_ll_rng.h:562
ll_rng_get_post_mode
__STATIC_INLINE uint32_t ll_rng_get_post_mode(rng_regs_t *RNGx)
Get RNG post-process configuration.
Definition: gr55xx_ll_rng.h:432
ll_rng_set_lfsr_seed
__STATIC_INLINE void ll_rng_set_lfsr_seed(rng_regs_t *RNGx, uint32_t seed)
Set source of LFSR seed.
Definition: gr55xx_ll_rng.h:321
ll_rng_enable_fro
__STATIC_INLINE void ll_rng_enable_fro(rng_regs_t *RNGx)
Enable Ring oscillator TRNG enabled signal.
Definition: gr55xx_ll_rng.h:261
ll_rng_clear_flag_sts
__STATIC_INLINE void ll_rng_clear_flag_sts(rng_regs_t *RNGx)
Clear RNG Status flag.
Definition: gr55xx_ll_rng.h:600
ll_rng_set_post_mode
__STATIC_INLINE void ll_rng_set_post_mode(rng_regs_t *RNGx, uint32_t post)
Set RNG post-process configuration.
Definition: gr55xx_ll_rng.h:409
ll_rng_enable
__STATIC_INLINE void ll_rng_enable(rng_regs_t *RNGx)
Enable Random Number Generation.
Definition: gr55xx_ll_rng.h:204
ll_rng_get_lfsr_seed
__STATIC_INLINE uint32_t ll_rng_get_lfsr_seed(rng_regs_t *RNGx)
Get source of LFSR seed.
Definition: gr55xx_ll_rng.h:342
ll_rng_struct_init
void ll_rng_struct_init(ll_rng_init_t *p_rng_init)
Set each field of a ll_rng_init_t type structure to default value.
ll_rng_set_trdy_time
__STATIC_INLINE void ll_rng_set_trdy_time(rng_regs_t *RNGx, uint32_t time)
set the waiting time that RNG input reaches stable.
Definition: gr55xx_ll_rng.h:501
ll_rng_read_lr_count
__STATIC_INLINE uint32_t ll_rng_read_lr_count(rng_regs_t *RNGx)
Return8-bit RNG Long Run Test counts.
Definition: gr55xx_ll_rng.h:703
ll_rng_is_enabled_it
__STATIC_INLINE uint32_t ll_rng_is_enabled_it(rng_regs_t *RNGx)
Check if Random Number Generator Interrupt is enabled.
Definition: gr55xx_ll_rng.h:663
ll_rng_set_output_mode
__STATIC_INLINE void ll_rng_set_output_mode(rng_regs_t *RNGx, uint32_t mode)
set RNG output mode.
Definition: gr55xx_ll_rng.h:457
ll_rng_enable_it
__STATIC_INLINE void ll_rng_enable_it(rng_regs_t *RNGx)
Enable Random Number Generator Interrupt.
Definition: gr55xx_ll_rng.h:625
ll_rng_disable_it
__STATIC_INLINE void ll_rng_disable_it(rng_regs_t *RNGx)
Disable Random Number Generator Interrupt.
Definition: gr55xx_ll_rng.h:644
ll_rng_set_user_seed
__STATIC_INLINE void ll_rng_set_user_seed(rng_regs_t *RNGx, uint32_t seed)
set RNG seed configured by user.
Definition: gr55xx_ll_rng.h:541
ll_rng_read_random_data32
__STATIC_INLINE uint32_t ll_rng_read_random_data32(rng_regs_t *RNGx)
Return32-bit Random Number value.
Definition: gr55xx_ll_rng.h:688
ll_rng_disable_fro
__STATIC_INLINE void ll_rng_disable_fro(rng_regs_t *RNGx)
Disable Ring oscillator TRNG enabled signal.
Definition: gr55xx_ll_rng.h:280
ll_rng_get_output_mode
__STATIC_INLINE uint32_t ll_rng_get_output_mode(rng_regs_t *RNGx)
get RNG output mode.
Definition: gr55xx_ll_rng.h:481
ll_rng_get_lfsr_mode
__STATIC_INLINE uint32_t ll_rng_get_lfsr_mode(rng_regs_t *RNGx)
Get LFSR configuration mode.
Definition: gr55xx_ll_rng.h:385
_ll_rng_init::out_mode
uint32_t out_mode
Definition: gr55xx_ll_rng.h:84
_ll_rng_init
LL RNG Init Structure definition.
Definition: gr55xx_ll_rng.h:77
ll_rng_init_t
struct _ll_rng_init ll_rng_init_t
LL RNG Init Structure definition.
_ll_rng_init::interrupt
uint32_t interrupt
Definition: gr55xx_ll_rng.h:90
ll_rng_is_enabled
__STATIC_INLINE uint32_t ll_rng_is_enabled(rng_regs_t *RNGx)
Check if Random Number Generator is enabled.
Definition: gr55xx_ll_rng.h:242
ll_rng_get_trdy_time
__STATIC_INLINE uint32_t ll_rng_get_trdy_time(rng_regs_t *RNGx)
get the waiting time that RNG input reaches stable.
Definition: gr55xx_ll_rng.h:520
_ll_rng_init::seed
uint32_t seed
Definition: gr55xx_ll_rng.h:78
ll_rng_init
error_status_t ll_rng_init(rng_regs_t *RNGx, ll_rng_init_t *p_rng_init)
Initialize RNG registers according to the specified parameters in p_rng_init.
_ll_rng_init::post_mode
uint32_t post_mode
Definition: gr55xx_ll_rng.h:87
ll_rng_is_active_flag_sts
__STATIC_INLINE uint32_t ll_rng_is_active_flag_sts(rng_regs_t *RNGx)
Indicate if the RNG Status Flag is set or not.
Definition: gr55xx_ll_rng.h:581
ll_rng_disable
__STATIC_INLINE void ll_rng_disable(rng_regs_t *RNGx)
Disable Random Number Generation.
Definition: gr55xx_ll_rng.h:223
ll_rng_set_lfsr_mode
__STATIC_INLINE void ll_rng_set_lfsr_mode(rng_regs_t *RNGx, uint32_t mode)
Set LFSR configuration mode.
Definition: gr55xx_ll_rng.h:364
ll_rng_fro_is_enabled
__STATIC_INLINE uint32_t ll_rng_fro_is_enabled(rng_regs_t *RNGx)
Check if Ring oscillator TRNG enabled signal is enabled.
Definition: gr55xx_ll_rng.h:299
_ll_rng_init::lfsr_mode
uint32_t lfsr_mode
Definition: gr55xx_ll_rng.h:81