gr55xx_ll_rng.h
Go to the documentation of this file.
1
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
68 /* Exported types ------------------------------------------------------------*/
76 typedef struct _ll_rng_init
77 {
78 uint32_t seed;
81 uint32_t lfsr_mode;
84 uint32_t out_mode;
87 uint32_t post_mode;
90 uint32_t interrupt;
93 } ll_rng_init_t;
94
102 /* Exported constants --------------------------------------------------------*/
110 #define LL_RNG_SEED_FR0_S0 (4UL << RNG_CONFIG_LFSR_SEED_SEL_Pos)
111 #define LL_RNG_SEED_USER (6UL << RNG_CONFIG_LFSR_SEED_SEL_Pos)
118 #define LL_RNG_LFSR_MODE_59BIT (0x00000000UL)
119 #define LL_RNG_LFSR_MODE_128BIT (1UL << RNG_CONFIG_LFSR_MODE_Pos)
125 #define LL_RNG_POST_PRO_NOT (0x00000000UL)
126 #define LL_RNG_POST_PRO_SKIPPING (1UL << RNG_CONFIG_POST_MODE_Pos)
127 #define LL_RNG_POST_PRO_COUNTING (2UL << RNG_CONFIG_POST_MODE_Pos)
128 #define LL_RNG_POST_PRO_NEUMANN (3UL << RNG_CONFIG_POST_MODE_Pos)
134 #define LL_RNG_IT_DISABLE (0x00000000UL)
135 #define LL_RNG_IT_ENABLE (1UL << RNG_CONFIG_IRQ_EN_Pos)
141 #define LL_RNG_OUTPUT_FR0_S0 (4UL << RNG_CONFIG_OUT_MODE_Pos)
142 #define LL_RNG_OUTPUT_CYCLIC_PARITY (6UL << RNG_CONFIG_OUT_MODE_Pos)
143 #define LL_RNG_OUTPUT_CYCLIC (7UL << RNG_CONFIG_OUT_MODE_Pos)
144 #define LL_RNG_OUTPUT_LFSR_RNG (8UL << RNG_CONFIG_OUT_MODE_Pos)
145 #define LL_RNG_OUTPUT_LFSR (9UL << RNG_CONFIG_OUT_MODE_Pos)
150 /* Exported macro ------------------------------------------------------------*/
151
166 #define LL_RNG_WriteReg(__instance__, __REG__, __VALUE__) WRITE_REG(__instance__->__REG__, (__VALUE__))
167
174 #define LL_RNG_ReadReg(__instance__, __REG__) READ_REG(__instance__->__REG__)
175
181 /* Exported functions --------------------------------------------------------*/
200 __STATIC_INLINE void ll_rng_enable(rng_regs_t *RNGx)
201 {
202 SET_BITS(RNGx->CTRL, RNG_CTRL_RUN_EN);
203 }
204
215 __STATIC_INLINE void ll_rng_disable(rng_regs_t *RNGx)
216 {
217 CLEAR_BITS(RNGx->CTRL, RNG_CTRL_RUN_EN);
218 }
219
230 __STATIC_INLINE uint32_t ll_rng_is_enabled(rng_regs_t *RNGx)
231 {
232 return (READ_BITS(RNGx->CTRL, RNG_CTRL_RUN_EN) == (RNG_CTRL_RUN_EN));
233 }
234
245 __STATIC_INLINE void ll_rng_enable_fro(rng_regs_t *RNGx)
246 {
247 SET_BITS(RNGx->CONFIG, RNG_CONFIG_FRO_EN);
248 }
249
260 __STATIC_INLINE void ll_rng_disable_fro(rng_regs_t *RNGx)
261 {
262 CLEAR_BITS(RNGx->CONFIG, RNG_CONFIG_FRO_EN);
263 }
264
275 __STATIC_INLINE uint32_t ll_rng_fro_is_enabled(rng_regs_t *RNGx)
276 {
277 return (READ_BITS(RNGx->CONFIG, RNG_CONFIG_FRO_EN) == (RNG_CONFIG_FRO_EN));
278 }
279
293 __STATIC_INLINE void ll_rng_set_lfsr_seed(rng_regs_t *RNGx, uint32_t seed)
294 {
295 MODIFY_REG(RNGx->CONFIG, RNG_CONFIG_LFSR_SEED_SEL, seed);
296 }
297
310 __STATIC_INLINE uint32_t ll_rng_get_lfsr_seed(rng_regs_t *RNGx)
311 {
312 return READ_BITS(RNGx->CONFIG, RNG_CONFIG_LFSR_SEED_SEL);
313 }
314
328 __STATIC_INLINE void ll_rng_set_lfsr_mode(rng_regs_t *RNGx, uint32_t mode)
329 {
330 MODIFY_REG(RNGx->CONFIG, RNG_CONFIG_LFSR_MODE, mode);
331 }
332
345 __STATIC_INLINE uint32_t ll_rng_get_lfsr_mode(rng_regs_t *RNGx)
346 {
347 return READ_BITS(RNGx->CONFIG, RNG_CONFIG_LFSR_MODE);
348 }
349
365 __STATIC_INLINE void ll_rng_set_post_mode(rng_regs_t *RNGx, uint32_t post)
366 {
367 MODIFY_REG(RNGx->CONFIG, RNG_CONFIG_POST_MODE, post);
368 }
369
384 __STATIC_INLINE uint32_t ll_rng_get_post_mode(rng_regs_t *RNGx)
385 {
386 return READ_BITS(RNGx->CONFIG, RNG_CONFIG_POST_MODE);
387 }
388
405 __STATIC_INLINE void ll_rng_set_output_mode(rng_regs_t *RNGx, uint32_t mode)
406 {
407 MODIFY_REG(RNGx->CONFIG, RNG_CONFIG_OUT_MODE, mode);
408 }
409
425 __STATIC_INLINE uint32_t ll_rng_get_output_mode(rng_regs_t *RNGx)
426 {
427 return READ_BITS(RNGx->CONFIG, RNG_CONFIG_OUT_MODE);
428 }
429
441 __STATIC_INLINE void ll_rng_set_trdy_time(rng_regs_t *RNGx, uint32_t time)
442 {
443 MODIFY_REG(RNGx->TSCON, RNG_TSCON_TRDY_TIME, time);
444 }
445
456 __STATIC_INLINE uint32_t ll_rng_get_trdy_time(rng_regs_t *RNGx)
457 {
458 return READ_BITS(RNGx->TSCON, RNG_TSCON_TRDY_TIME);
459 }
460
461
473 __STATIC_INLINE void ll_rng_set_user_seed(rng_regs_t *RNGx, uint32_t seed)
474 {
475 WRITE_REG(RNGx->USER_SEED, seed);
476 }
477
494 __STATIC_INLINE uint32_t ll_rng_is_active_flag_lr(rng_regs_t *RNGx)
495 {
496 return (READ_BITS(RNGx->LR_STATUS, RNG_LR_STATUS_FLAG) == (RNG_LR_STATUS_FLAG));
497 }
498
509 __STATIC_INLINE uint32_t ll_rng_is_active_flag_sts(rng_regs_t *RNGx)
510 {
511 return (READ_BITS(RNGx->STATUS, RNG_STATUS_READY) == (RNG_STATUS_READY));
512 }
513
524 __STATIC_INLINE void ll_rng_clear_flag_sts(rng_regs_t *RNGx)
525 {
526 WRITE_REG(RNGx->STATUS, RNG_STATUS_READY);
527 }
528
545 __STATIC_INLINE void ll_rng_enable_it(rng_regs_t *RNGx)
546 {
547 SET_BITS(RNGx->CONFIG, RNG_CONFIG_IRQ_EN);
548 }
549
560 __STATIC_INLINE void ll_rng_disable_it(rng_regs_t *RNGx)
561 {
562 CLEAR_BITS(RNGx->CONFIG, RNG_CONFIG_IRQ_EN);
563 }
564
575 __STATIC_INLINE uint32_t ll_rng_is_enabled_it(rng_regs_t *RNGx)
576 {
577 return (READ_BITS(RNGx->CONFIG, RNG_CONFIG_IRQ_EN) == (RNG_CONFIG_IRQ_EN));
578 }
579
596 __STATIC_INLINE uint32_t ll_rng_read_random_data32(rng_regs_t *RNGx)
597 {
598 return (uint32_t)(READ_REG(RNGx->DATA));
599 }
600
611 __STATIC_INLINE uint32_t ll_rng_read_lr_count(rng_regs_t *RNGx)
612 {
613 return READ_BITS(RNGx->LR_STATUS, RNG_LR_STATUS_CNT) >> RNG_LR_STATUS_CNT_Pos;
614 }
615
629 error_status_t ll_rng_deinit(rng_regs_t *RNGx);
630
641 error_status_t ll_rng_init(rng_regs_t *RNGx, ll_rng_init_t *p_rng_init);
642
649 void ll_rng_struct_init(ll_rng_init_t *p_rng_init);
650
655 #endif /* RNG */
656
657 #ifdef __cplusplus
658 }
659 #endif
660
661 #endif /* __GR55XX_LL_RNG_H__ */
662
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:494
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:384
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:293
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:245
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:524
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:365
ll_rng_enable
__STATIC_INLINE void ll_rng_enable(rng_regs_t *RNGx)
Enable Random Number Generation.
Definition: gr55xx_ll_rng.h:200
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:310
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:441
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:611
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:575
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:405
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:545
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:560
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:473
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:596
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:260
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:425
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:345
_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:230
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:456
_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:509
ll_rng_disable
__STATIC_INLINE void ll_rng_disable(rng_regs_t *RNGx)
Disable Random Number Generation.
Definition: gr55xx_ll_rng.h:215
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:328
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:275
_ll_rng_init::lfsr_mode
uint32_t lfsr_mode
Definition: gr55xx_ll_rng.h:81