gr55xx_hal_rng.h
Go to the documentation of this file.
1
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_RNG_H__
53 #define __GR55xx_HAL_RNG_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_ll_rng.h"
61 #include "gr55xx_hal_def.h"
62
63 /* Exported types ------------------------------------------------------------*/
75 typedef enum
76 {
77 HAL_RNG_STATE_RESET = 0x00,
78 HAL_RNG_STATE_READY = 0x01,
79 HAL_RNG_STATE_BUSY = 0x02,
80 HAL_RNG_STATE_TIMEOUT = 0x03,
81 HAL_RNG_STATE_ERROR = 0x04
82 } hal_rng_state_t;
83
99 typedef struct _rng_init
100 {
101 uint32_t seed_mode;
104 uint32_t lfsr_mode;
107 uint32_t out_mode;
110 uint32_t post_mode;
113 } rng_init_t;
114
124 typedef struct _rng_handle
125 {
126 rng_regs_t *p_instance;
128 rng_init_t init;
130 hal_lock_t lock;
132 __IO hal_rng_state_t state;
134 uint32_t random_number;
136 uint32_t retention[1];
137 } rng_handle_t;
138
155 typedef struct _hal_rng_callback
156 {
157 void (*rng_msp_init)(rng_handle_t *p_rng);
158 void (*rng_msp_deinit)(rng_handle_t *p_rng);
159 void (*rng_ready_data_callback)(rng_handle_t *p_rng, uint32_t random32bit);
160 } hal_rng_callback_t;
161
171 /* Exported constants --------------------------------------------------------*/
179 #define RNG_SEED_FR0_S0 LL_RNG_SEED_FR0_S0
180 #define RNG_SEED_USER LL_RNG_SEED_USER
187 #define RNG_LFSR_MODE_59BIT LL_RNG_LFSR_MODE_59BIT
188 #define RNG_LFSR_MODE_128BIT LL_RNG_LFSR_MODE_128BIT
194 #define RNG_POST_PRO_NOT LL_RNG_POST_PRO_NOT
195 #define RNG_POST_PRO_SKIPPING LL_RNG_POST_PRO_SKIPPING
196 #define RNG_POST_PRO_COUNTING LL_RNG_POST_PRO_COUNTING
197 #define RNG_POST_PRO_NEUMANN LL_RNG_POST_PRO_NEUMANN
203 #define RNG_OUTPUT_FR0_S0 LL_RNG_OUTPUT_FR0_S0
204 #define RNG_OUTPUT_CYCLIC_PARITY LL_RNG_OUTPUT_CYCLIC_PARITY
205 #define RNG_OUTPUT_CYCLIC LL_RNG_OUTPUT_CYCLIC
206 #define RNG_OUTPUT_LFSR_RNG LL_RNG_OUTPUT_LFSR_RNG
207 #define RNG_OUTPUT_LFSR LL_RNG_OUTPUT_LFSR
214 /* Exported functions --------------------------------------------------------*/
215
248 hal_status_t hal_rng_init(rng_handle_t *p_rng);
249
260 hal_status_t hal_rng_deinit(rng_handle_t *p_rng);
261
272 void hal_rng_msp_init(rng_handle_t *p_rng);
273
284 void hal_rng_msp_deinit(rng_handle_t *p_rng);
285
322 hal_status_t hal_rng_generate_random_number(rng_handle_t *p_rng, uint16_t *p_seed, uint32_t *p_random32bit);
323
339 hal_status_t hal_rng_generate_random_number_it(rng_handle_t *p_rng, uint16_t *p_seed);
340
349 uint32_t hal_rng_read_last_random_number(rng_handle_t *p_rng);
350
363 void hal_rng_irq_handler(rng_handle_t *p_rng);
364
376 void hal_rng_ready_data_callback(rng_handle_t *p_rng, uint32_t random32bit);
377
404 hal_rng_state_t hal_rng_get_state(rng_handle_t *p_rng);
405
417 hal_status_t hal_rng_suspend_reg(rng_handle_t *p_rng);
418
431 hal_status_t hal_rng_resume_reg(rng_handle_t *p_rng);
432
433
439 #ifdef __cplusplus
440 }
441 #endif
442
443 #endif /* __GR55xx_HAL_RNG_H__ */
444
rng_init_t
struct _rng_init rng_init_t
RNG init structure definition.
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
hal_rng_generate_random_number
hal_status_t hal_rng_generate_random_number(rng_handle_t *p_rng, uint16_t *p_seed, uint32_t *p_random32bit)
Generate a 32-bit random number.
_rng_handle::retention
uint32_t retention[1]
Definition: gr55xx_hal_rng.h:136
hal_rng_init
hal_status_t hal_rng_init(rng_handle_t *p_rng)
Initialize the RNG according to the specified parameters in the rng_init_t of associated handle.
_rng_init::out_mode
uint32_t out_mode
Definition: gr55xx_hal_rng.h:107
_rng_handle::lock
hal_lock_t lock
Definition: gr55xx_hal_rng.h:130
hal_rng_msp_deinit
void hal_rng_msp_deinit(rng_handle_t *p_rng)
De-initialize the RNG MSP.
hal_rng_generate_random_number_it
hal_status_t hal_rng_generate_random_number_it(rng_handle_t *p_rng, uint16_t *p_seed)
Generate a 32-bit random number in interrupt mode.
_rng_handle::random_number
uint32_t random_number
Definition: gr55xx_hal_rng.h:134
HAL_RNG_STATE_TIMEOUT
@ HAL_RNG_STATE_TIMEOUT
Definition: gr55xx_hal_rng.h:80
_hal_rng_callback
HAL_RNG Callback function definition.
Definition: gr55xx_hal_rng.h:156
hal_rng_msp_init
void hal_rng_msp_init(rng_handle_t *p_rng)
Initialize the RNG MSP.
_rng_handle::state
__IO hal_rng_state_t state
Definition: gr55xx_hal_rng.h:132
hal_rng_state_t
hal_rng_state_t
HAL RNG State Enumerations definition.
Definition: gr55xx_hal_rng.h:76
hal_rng_deinit
hal_status_t hal_rng_deinit(rng_handle_t *p_rng)
De-initialize the RNG peripheral.
rng_handle_t
struct _rng_handle rng_handle_t
RNG handle Structure definition.
hal_rng_callback_t
struct _hal_rng_callback hal_rng_callback_t
HAL_RNG Callback function definition.
hal_rng_resume_reg
hal_status_t hal_rng_resume_reg(rng_handle_t *p_rng)
Restore some registers related to RNG configuration after sleep. This function must be used in conjun...
HAL_RNG_STATE_RESET
@ HAL_RNG_STATE_RESET
Definition: gr55xx_hal_rng.h:77
hal_rng_get_state
hal_rng_state_t hal_rng_get_state(rng_handle_t *p_rng)
Return the RNG handle state.
_rng_init::lfsr_mode
uint32_t lfsr_mode
Definition: gr55xx_hal_rng.h:104
HAL_RNG_STATE_ERROR
@ HAL_RNG_STATE_ERROR
Definition: gr55xx_hal_rng.h:81
gr55xx_ll_rng.h
Header file containing functions prototypes of RNG LL library.
_hal_rng_callback::rng_msp_init
void(* rng_msp_init)(rng_handle_t *p_rng)
Definition: gr55xx_hal_rng.h:157
_rng_init::post_mode
uint32_t post_mode
Definition: gr55xx_hal_rng.h:110
_rng_handle
RNG handle Structure definition.
Definition: gr55xx_hal_rng.h:125
hal_rng_read_last_random_number
uint32_t hal_rng_read_last_random_number(rng_handle_t *p_rng)
Read the latest generated random number.
HAL_RNG_STATE_READY
@ HAL_RNG_STATE_READY
Definition: gr55xx_hal_rng.h:78
HAL_RNG_STATE_BUSY
@ HAL_RNG_STATE_BUSY
Definition: gr55xx_hal_rng.h:79
hal_rng_suspend_reg
hal_status_t hal_rng_suspend_reg(rng_handle_t *p_rng)
Suspend some registers related to RNG configuration before sleep.
_rng_handle::p_instance
rng_regs_t * p_instance
Definition: gr55xx_hal_rng.h:126
hal_rng_irq_handler
void hal_rng_irq_handler(rng_handle_t *p_rng)
Handle RNG interrupt request.
_rng_init
RNG init structure definition.
Definition: gr55xx_hal_rng.h:100
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
_rng_handle::init
rng_init_t init
Definition: gr55xx_hal_rng.h:128
_hal_rng_callback::rng_ready_data_callback
void(* rng_ready_data_callback)(rng_handle_t *p_rng, uint32_t random32bit)
Definition: gr55xx_hal_rng.h:159
_rng_init::seed_mode
uint32_t seed_mode
Definition: gr55xx_hal_rng.h:101
_hal_rng_callback::rng_msp_deinit
void(* rng_msp_deinit)(rng_handle_t *p_rng)
Definition: gr55xx_hal_rng.h:158
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
hal_rng_ready_data_callback
void hal_rng_ready_data_callback(rng_handle_t *p_rng, uint32_t random32bit)
Data Ready callback in non-blocking mode.