1 /**
2 ******************************************************************************
3 * @file stm32g0xx_ll_rng.h
4 * @author MCD Application Team
5 * @brief Header file of RNG LL module.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2018 STMicroelectronics.
10 * All rights reserved.
11 *
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
15 *
16 ******************************************************************************
17 */
18
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32G0xx_LL_RNG_H
21 #define STM32G0xx_LL_RNG_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32g0xx.h"
29
30 /** @addtogroup STM32G0xx_LL_Driver
31 * @{
32 */
33
34 #if defined (RNG)
35
36 /** @defgroup RNG_LL RNG
37 * @{
38 */
39
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /* Private macros ------------------------------------------------------------*/
44
45 /* Exported types ------------------------------------------------------------*/
46 #if defined(USE_FULL_LL_DRIVER)
47 /** @defgroup RNG_LL_ES_Init_Struct RNG Exported Init structures
48 * @{
49 */
50
51
52 /**
53 * @brief LL RNG Init Structure Definition
54 */
55 typedef struct
56 {
57 uint32_t ClockErrorDetection; /*!< Clock error detection.
58 This parameter can be one value of @ref RNG_LL_CED.
59 This parameter can be modified using unitary
60 functions @ref LL_RNG_EnableClkErrorDetect(). */
61 } LL_RNG_InitTypeDef;
62
63 /**
64 * @}
65 */
66 #endif /* USE_FULL_LL_DRIVER */
67 /* Exported constants --------------------------------------------------------*/
68 /** @defgroup RNG_LL_Exported_Constants RNG Exported Constants
69 * @{
70 */
71
72 /** @defgroup RNG_LL_CED Clock Error Detection
73 * @{
74 */
75 #define LL_RNG_CED_ENABLE 0x00000000U /*!< Clock error detection enabled */
76 #define LL_RNG_CED_DISABLE RNG_CR_CED /*!< Clock error detection disabled */
77 /**
78 * @}
79 */
80
81 /** @defgroup RNG_LL_EC_GET_FLAG Get Flags Defines
82 * @brief Flags defines which can be used with LL_RNG_ReadReg function
83 * @{
84 */
85 #define LL_RNG_SR_DRDY RNG_SR_DRDY /*!< Register contains valid random data */
86 #define LL_RNG_SR_CECS RNG_SR_CECS /*!< Clock error current status */
87 #define LL_RNG_SR_SECS RNG_SR_SECS /*!< Seed error current status */
88 #define LL_RNG_SR_CEIS RNG_SR_CEIS /*!< Clock error interrupt status */
89 #define LL_RNG_SR_SEIS RNG_SR_SEIS /*!< Seed error interrupt status */
90 /**
91 * @}
92 */
93
94 /** @defgroup RNG_LL_EC_IT IT Defines
95 * @brief IT defines which can be used with LL_RNG_ReadReg and LL_RNG_WriteReg macros
96 * @{
97 */
98 #define LL_RNG_CR_IE RNG_CR_IE /*!< RNG Interrupt enable */
99 /**
100 * @}
101 */
102
103 /**
104 * @}
105 */
106
107 /* Exported macro ------------------------------------------------------------*/
108 /** @defgroup RNG_LL_Exported_Macros RNG Exported Macros
109 * @{
110 */
111
112 /** @defgroup RNG_LL_EM_WRITE_READ Common Write and read registers Macros
113 * @{
114 */
115
116 /**
117 * @brief Write a value in RNG register
118 * @param __INSTANCE__ RNG Instance
119 * @param __REG__ Register to be written
120 * @param __VALUE__ Value to be written in the register
121 * @retval None
122 */
123 #define LL_RNG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
124
125 /**
126 * @brief Read a value in RNG register
127 * @param __INSTANCE__ RNG Instance
128 * @param __REG__ Register to be read
129 * @retval Register value
130 */
131 #define LL_RNG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
132 /**
133 * @}
134 */
135
136 /**
137 * @}
138 */
139
140
141 /* Exported functions --------------------------------------------------------*/
142 /** @defgroup RNG_LL_Exported_Functions RNG Exported Functions
143 * @{
144 */
145 /** @defgroup RNG_LL_EF_Configuration RNG Configuration functions
146 * @{
147 */
148
149 /**
150 * @brief Enable Random Number Generation
151 * @rmtoll CR RNGEN LL_RNG_Enable
152 * @param RNGx RNG Instance
153 * @retval None
154 */
LL_RNG_Enable(RNG_TypeDef * RNGx)155 __STATIC_INLINE void LL_RNG_Enable(RNG_TypeDef *RNGx)
156 {
157 SET_BIT(RNGx->CR, RNG_CR_RNGEN);
158 }
159
160 /**
161 * @brief Disable Random Number Generation
162 * @rmtoll CR RNGEN LL_RNG_Disable
163 * @param RNGx RNG Instance
164 * @retval None
165 */
LL_RNG_Disable(RNG_TypeDef * RNGx)166 __STATIC_INLINE void LL_RNG_Disable(RNG_TypeDef *RNGx)
167 {
168 CLEAR_BIT(RNGx->CR, RNG_CR_RNGEN);
169 }
170
171 /**
172 * @brief Check if Random Number Generator is enabled
173 * @rmtoll CR RNGEN LL_RNG_IsEnabled
174 * @param RNGx RNG Instance
175 * @retval State of bit (1 or 0).
176 */
LL_RNG_IsEnabled(RNG_TypeDef * RNGx)177 __STATIC_INLINE uint32_t LL_RNG_IsEnabled(RNG_TypeDef *RNGx)
178 {
179 return ((READ_BIT(RNGx->CR, RNG_CR_RNGEN) == (RNG_CR_RNGEN)) ? 1UL : 0UL);
180 }
181
182 /**
183 * @brief Enable Clock Error Detection
184 * @rmtoll CR CED LL_RNG_EnableClkErrorDetect
185 * @param RNGx RNG Instance
186 * @retval None
187 */
LL_RNG_EnableClkErrorDetect(RNG_TypeDef * RNGx)188 __STATIC_INLINE void LL_RNG_EnableClkErrorDetect(RNG_TypeDef *RNGx)
189 {
190 CLEAR_BIT(RNGx->CR, RNG_CR_CED);
191 }
192
193 /**
194 * @brief Disable RNG Clock Error Detection
195 * @rmtoll CR CED LL_RNG_DisableClkErrorDetect
196 * @param RNGx RNG Instance
197 * @retval None
198 */
LL_RNG_DisableClkErrorDetect(RNG_TypeDef * RNGx)199 __STATIC_INLINE void LL_RNG_DisableClkErrorDetect(RNG_TypeDef *RNGx)
200 {
201 SET_BIT(RNGx->CR, RNG_CR_CED);
202 }
203
204 /**
205 * @brief Check if RNG Clock Error Detection is enabled
206 * @rmtoll CR CED LL_RNG_IsEnabledClkErrorDetect
207 * @param RNGx RNG Instance
208 * @retval State of bit (1 or 0).
209 */
LL_RNG_IsEnabledClkErrorDetect(RNG_TypeDef * RNGx)210 __STATIC_INLINE uint32_t LL_RNG_IsEnabledClkErrorDetect(RNG_TypeDef *RNGx)
211 {
212 return ((READ_BIT(RNGx->CR, RNG_CR_CED) != (RNG_CR_CED)) ? 1UL : 0UL);
213 }
214
215 /**
216 * @}
217 */
218
219 /** @defgroup RNG_LL_EF_FLAG_Management FLAG Management
220 * @{
221 */
222
223 /**
224 * @brief Indicate if the RNG Data ready Flag is set or not
225 * @rmtoll SR DRDY LL_RNG_IsActiveFlag_DRDY
226 * @param RNGx RNG Instance
227 * @retval State of bit (1 or 0).
228 */
LL_RNG_IsActiveFlag_DRDY(RNG_TypeDef * RNGx)229 __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_DRDY(RNG_TypeDef *RNGx)
230 {
231 return ((READ_BIT(RNGx->SR, RNG_SR_DRDY) == (RNG_SR_DRDY)) ? 1UL : 0UL);
232 }
233
234 /**
235 * @brief Indicate if the Clock Error Current Status Flag is set or not
236 * @rmtoll SR CECS LL_RNG_IsActiveFlag_CECS
237 * @param RNGx RNG Instance
238 * @retval State of bit (1 or 0).
239 */
LL_RNG_IsActiveFlag_CECS(RNG_TypeDef * RNGx)240 __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_CECS(RNG_TypeDef *RNGx)
241 {
242 return ((READ_BIT(RNGx->SR, RNG_SR_CECS) == (RNG_SR_CECS)) ? 1UL : 0UL);
243 }
244
245 /**
246 * @brief Indicate if the Seed Error Current Status Flag is set or not
247 * @rmtoll SR SECS LL_RNG_IsActiveFlag_SECS
248 * @param RNGx RNG Instance
249 * @retval State of bit (1 or 0).
250 */
LL_RNG_IsActiveFlag_SECS(RNG_TypeDef * RNGx)251 __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_SECS(RNG_TypeDef *RNGx)
252 {
253 return ((READ_BIT(RNGx->SR, RNG_SR_SECS) == (RNG_SR_SECS)) ? 1UL : 0UL);
254 }
255
256 /**
257 * @brief Indicate if the Clock Error Interrupt Status Flag is set or not
258 * @rmtoll SR CEIS LL_RNG_IsActiveFlag_CEIS
259 * @param RNGx RNG Instance
260 * @retval State of bit (1 or 0).
261 */
LL_RNG_IsActiveFlag_CEIS(RNG_TypeDef * RNGx)262 __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_CEIS(RNG_TypeDef *RNGx)
263 {
264 return ((READ_BIT(RNGx->SR, RNG_SR_CEIS) == (RNG_SR_CEIS)) ? 1UL : 0UL);
265 }
266
267 /**
268 * @brief Indicate if the Seed Error Interrupt Status Flag is set or not
269 * @rmtoll SR SEIS LL_RNG_IsActiveFlag_SEIS
270 * @param RNGx RNG Instance
271 * @retval State of bit (1 or 0).
272 */
LL_RNG_IsActiveFlag_SEIS(RNG_TypeDef * RNGx)273 __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_SEIS(RNG_TypeDef *RNGx)
274 {
275 return ((READ_BIT(RNGx->SR, RNG_SR_SEIS) == (RNG_SR_SEIS)) ? 1UL : 0UL);
276 }
277
278 /**
279 * @brief Clear Clock Error interrupt Status (CEIS) Flag
280 * @rmtoll SR CEIS LL_RNG_ClearFlag_CEIS
281 * @param RNGx RNG Instance
282 * @retval None
283 */
LL_RNG_ClearFlag_CEIS(RNG_TypeDef * RNGx)284 __STATIC_INLINE void LL_RNG_ClearFlag_CEIS(RNG_TypeDef *RNGx)
285 {
286 WRITE_REG(RNGx->SR, ~RNG_SR_CEIS);
287 }
288
289 /**
290 * @brief Clear Seed Error interrupt Status (SEIS) Flag
291 * @rmtoll SR SEIS LL_RNG_ClearFlag_SEIS
292 * @param RNGx RNG Instance
293 * @retval None
294 */
LL_RNG_ClearFlag_SEIS(RNG_TypeDef * RNGx)295 __STATIC_INLINE void LL_RNG_ClearFlag_SEIS(RNG_TypeDef *RNGx)
296 {
297 WRITE_REG(RNGx->SR, ~RNG_SR_SEIS);
298 }
299
300 /**
301 * @}
302 */
303
304 /** @defgroup RNG_LL_EF_IT_Management IT Management
305 * @{
306 */
307
308 /**
309 * @brief Enable Random Number Generator Interrupt
310 * (applies for either Seed error, Clock Error or Data ready interrupts)
311 * @rmtoll CR IE LL_RNG_EnableIT
312 * @param RNGx RNG Instance
313 * @retval None
314 */
LL_RNG_EnableIT(RNG_TypeDef * RNGx)315 __STATIC_INLINE void LL_RNG_EnableIT(RNG_TypeDef *RNGx)
316 {
317 SET_BIT(RNGx->CR, RNG_CR_IE);
318 }
319
320 /**
321 * @brief Disable Random Number Generator Interrupt
322 * (applies for either Seed error, Clock Error or Data ready interrupts)
323 * @rmtoll CR IE LL_RNG_DisableIT
324 * @param RNGx RNG Instance
325 * @retval None
326 */
LL_RNG_DisableIT(RNG_TypeDef * RNGx)327 __STATIC_INLINE void LL_RNG_DisableIT(RNG_TypeDef *RNGx)
328 {
329 CLEAR_BIT(RNGx->CR, RNG_CR_IE);
330 }
331
332 /**
333 * @brief Check if Random Number Generator Interrupt is enabled
334 * (applies for either Seed error, Clock Error or Data ready interrupts)
335 * @rmtoll CR IE LL_RNG_IsEnabledIT
336 * @param RNGx RNG Instance
337 * @retval State of bit (1 or 0).
338 */
LL_RNG_IsEnabledIT(RNG_TypeDef * RNGx)339 __STATIC_INLINE uint32_t LL_RNG_IsEnabledIT(RNG_TypeDef *RNGx)
340 {
341 return ((READ_BIT(RNGx->CR, RNG_CR_IE) == (RNG_CR_IE)) ? 1UL : 0UL);
342 }
343
344 /**
345 * @}
346 */
347
348 /** @defgroup RNG_LL_EF_Data_Management Data Management
349 * @{
350 */
351
352 /**
353 * @brief Return32-bit Random Number value
354 * @rmtoll DR RNDATA LL_RNG_ReadRandData32
355 * @param RNGx RNG Instance
356 * @retval Generated 32-bit random value
357 */
LL_RNG_ReadRandData32(RNG_TypeDef * RNGx)358 __STATIC_INLINE uint32_t LL_RNG_ReadRandData32(RNG_TypeDef *RNGx)
359 {
360 return (uint32_t)(READ_REG(RNGx->DR));
361 }
362
363 /**
364 * @}
365 */
366
367 #if defined(USE_FULL_LL_DRIVER)
368 /** @defgroup RNG_LL_EF_Init Initialization and de-initialization functions
369 * @{
370 */
371 ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct);
372 void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct);
373 ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx);
374
375 /**
376 * @}
377 */
378 #endif /* USE_FULL_LL_DRIVER */
379
380 /**
381 * @}
382 */
383
384 /**
385 * @}
386 */
387
388 #endif /* RNG */
389
390 /**
391 * @}
392 */
393
394 #ifdef __cplusplus
395 }
396 #endif
397
398 #endif /* __STM32G0xx_LL_RNG_H */
399
400