2 ******************************************************************************
3 * @file stm32g4xx_ll_rng.h
4 * @author MCD Application Team
5 * @brief Header file of RNG LL module.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2018 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32G4xx_LL_RNG_H
22 #define STM32G4xx_LL_RNG_H
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32g4xx.h"
31 /** @addtogroup STM32G4xx_LL_Driver
37 /** @defgroup RNG_LL RNG
41 /* Private types -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 /* Private constants ---------------------------------------------------------*/
44 /* Private macros ------------------------------------------------------------*/
46 /* Exported types ------------------------------------------------------------*/
47 #if defined(USE_FULL_LL_DRIVER)
48 /** @defgroup RNG_LL_ES_Init_Struct RNG Exported Init structures
54 * @brief LL RNG Init Structure Definition
58 uint32_t ClockErrorDetection
; /*!< Clock error detection.
59 This parameter can be one value of @ref RNG_LL_CED.
61 This parameter can be modified using unitary functions @ref LL_RNG_EnableClkErrorDetect(). */
67 #endif /* USE_FULL_LL_DRIVER */
68 /* Exported constants --------------------------------------------------------*/
69 /** @defgroup RNG_LL_Exported_Constants RNG Exported Constants
73 /** @defgroup RNG_LL_CED Clock Error Detection
76 #define LL_RNG_CED_ENABLE 0x00000000U /*!< Clock error detection enabled */
77 #define LL_RNG_CED_DISABLE RNG_CR_CED /*!< Clock error detection disabled */
82 /** @defgroup RNG_LL_EC_GET_FLAG Get Flags Defines
83 * @brief Flags defines which can be used with LL_RNG_ReadReg function
86 #define LL_RNG_SR_DRDY RNG_SR_DRDY /*!< Register contains valid random data */
87 #define LL_RNG_SR_CECS RNG_SR_CECS /*!< Clock error current status */
88 #define LL_RNG_SR_SECS RNG_SR_SECS /*!< Seed error current status */
89 #define LL_RNG_SR_CEIS RNG_SR_CEIS /*!< Clock error interrupt status */
90 #define LL_RNG_SR_SEIS RNG_SR_SEIS /*!< Seed error interrupt status */
95 /** @defgroup RNG_LL_EC_IT IT Defines
96 * @brief IT defines which can be used with LL_RNG_ReadReg and LL_RNG_WriteReg macros
99 #define LL_RNG_CR_IE RNG_CR_IE /*!< RNG Interrupt enable */
108 /* Exported macro ------------------------------------------------------------*/
109 /** @defgroup RNG_LL_Exported_Macros RNG Exported Macros
113 /** @defgroup RNG_LL_EM_WRITE_READ Common Write and read registers Macros
118 * @brief Write a value in RNG register
119 * @param __INSTANCE__ RNG Instance
120 * @param __REG__ Register to be written
121 * @param __VALUE__ Value to be written in the register
124 #define LL_RNG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
127 * @brief Read a value in RNG register
128 * @param __INSTANCE__ RNG Instance
129 * @param __REG__ Register to be read
130 * @retval Register value
132 #define LL_RNG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
142 /* Exported functions --------------------------------------------------------*/
143 /** @defgroup RNG_LL_Exported_Functions RNG Exported Functions
146 /** @defgroup RNG_LL_EF_Configuration RNG Configuration functions
151 * @brief Enable Random Number Generation
152 * @rmtoll CR RNGEN LL_RNG_Enable
153 * @param RNGx RNG Instance
156 __STATIC_INLINE
void LL_RNG_Enable(RNG_TypeDef
*RNGx
)
158 SET_BIT(RNGx
->CR
, RNG_CR_RNGEN
);
162 * @brief Disable Random Number Generation
163 * @rmtoll CR RNGEN LL_RNG_Disable
164 * @param RNGx RNG Instance
167 __STATIC_INLINE
void LL_RNG_Disable(RNG_TypeDef
*RNGx
)
169 CLEAR_BIT(RNGx
->CR
, RNG_CR_RNGEN
);
173 * @brief Check if Random Number Generator is enabled
174 * @rmtoll CR RNGEN LL_RNG_IsEnabled
175 * @param RNGx RNG Instance
176 * @retval State of bit (1 or 0).
178 __STATIC_INLINE
uint32_t LL_RNG_IsEnabled(RNG_TypeDef
*RNGx
)
180 return ((READ_BIT(RNGx
->CR
, RNG_CR_RNGEN
) == (RNG_CR_RNGEN
)) ? 1UL : 0UL);
184 * @brief Enable Clock Error Detection
185 * @rmtoll CR CED LL_RNG_EnableClkErrorDetect
186 * @param RNGx RNG Instance
189 __STATIC_INLINE
void LL_RNG_EnableClkErrorDetect(RNG_TypeDef
*RNGx
)
191 CLEAR_BIT(RNGx
->CR
, RNG_CR_CED
);
195 * @brief Disable RNG Clock Error Detection
196 * @rmtoll CR CED LL_RNG_DisableClkErrorDetect
197 * @param RNGx RNG Instance
200 __STATIC_INLINE
void LL_RNG_DisableClkErrorDetect(RNG_TypeDef
*RNGx
)
202 SET_BIT(RNGx
->CR
, RNG_CR_CED
);
206 * @brief Check if RNG Clock Error Detection is enabled
207 * @rmtoll CR CED LL_RNG_IsEnabledClkErrorDetect
208 * @param RNGx RNG Instance
209 * @retval State of bit (1 or 0).
211 __STATIC_INLINE
uint32_t LL_RNG_IsEnabledClkErrorDetect(RNG_TypeDef
*RNGx
)
213 return ((READ_BIT(RNGx
->CR
, RNG_CR_CED
) != (RNG_CR_CED
)) ? 1UL : 0UL);
220 /** @defgroup RNG_LL_EF_FLAG_Management FLAG Management
225 * @brief Indicate if the RNG Data ready Flag is set or not
226 * @rmtoll SR DRDY LL_RNG_IsActiveFlag_DRDY
227 * @param RNGx RNG Instance
228 * @retval State of bit (1 or 0).
230 __STATIC_INLINE
uint32_t LL_RNG_IsActiveFlag_DRDY(RNG_TypeDef
*RNGx
)
232 return ((READ_BIT(RNGx
->SR
, RNG_SR_DRDY
) == (RNG_SR_DRDY
)) ? 1UL : 0UL);
236 * @brief Indicate if the Clock Error Current Status Flag is set or not
237 * @rmtoll SR CECS LL_RNG_IsActiveFlag_CECS
238 * @param RNGx RNG Instance
239 * @retval State of bit (1 or 0).
241 __STATIC_INLINE
uint32_t LL_RNG_IsActiveFlag_CECS(RNG_TypeDef
*RNGx
)
243 return ((READ_BIT(RNGx
->SR
, RNG_SR_CECS
) == (RNG_SR_CECS
)) ? 1UL : 0UL);
247 * @brief Indicate if the Seed Error Current Status Flag is set or not
248 * @rmtoll SR SECS LL_RNG_IsActiveFlag_SECS
249 * @param RNGx RNG Instance
250 * @retval State of bit (1 or 0).
252 __STATIC_INLINE
uint32_t LL_RNG_IsActiveFlag_SECS(RNG_TypeDef
*RNGx
)
254 return ((READ_BIT(RNGx
->SR
, RNG_SR_SECS
) == (RNG_SR_SECS
)) ? 1UL : 0UL);
258 * @brief Indicate if the Clock Error Interrupt Status Flag is set or not
259 * @rmtoll SR CEIS LL_RNG_IsActiveFlag_CEIS
260 * @param RNGx RNG Instance
261 * @retval State of bit (1 or 0).
263 __STATIC_INLINE
uint32_t LL_RNG_IsActiveFlag_CEIS(RNG_TypeDef
*RNGx
)
265 return ((READ_BIT(RNGx
->SR
, RNG_SR_CEIS
) == (RNG_SR_CEIS
)) ? 1UL : 0UL);
269 * @brief Indicate if the Seed Error Interrupt Status Flag is set or not
270 * @rmtoll SR SEIS LL_RNG_IsActiveFlag_SEIS
271 * @param RNGx RNG Instance
272 * @retval State of bit (1 or 0).
274 __STATIC_INLINE
uint32_t LL_RNG_IsActiveFlag_SEIS(RNG_TypeDef
*RNGx
)
276 return ((READ_BIT(RNGx
->SR
, RNG_SR_SEIS
) == (RNG_SR_SEIS
)) ? 1UL : 0UL);
280 * @brief Clear Clock Error interrupt Status (CEIS) Flag
281 * @rmtoll SR CEIS LL_RNG_ClearFlag_CEIS
282 * @param RNGx RNG Instance
285 __STATIC_INLINE
void LL_RNG_ClearFlag_CEIS(RNG_TypeDef
*RNGx
)
287 WRITE_REG(RNGx
->SR
, ~RNG_SR_CEIS
);
291 * @brief Clear Seed Error interrupt Status (SEIS) Flag
292 * @rmtoll SR SEIS LL_RNG_ClearFlag_SEIS
293 * @param RNGx RNG Instance
296 __STATIC_INLINE
void LL_RNG_ClearFlag_SEIS(RNG_TypeDef
*RNGx
)
298 WRITE_REG(RNGx
->SR
, ~RNG_SR_SEIS
);
305 /** @defgroup RNG_LL_EF_IT_Management IT Management
310 * @brief Enable Random Number Generator Interrupt
311 * (applies for either Seed error, Clock Error or Data ready interrupts)
312 * @rmtoll CR IE LL_RNG_EnableIT
313 * @param RNGx RNG Instance
316 __STATIC_INLINE
void LL_RNG_EnableIT(RNG_TypeDef
*RNGx
)
318 SET_BIT(RNGx
->CR
, RNG_CR_IE
);
322 * @brief Disable Random Number Generator Interrupt
323 * (applies for either Seed error, Clock Error or Data ready interrupts)
324 * @rmtoll CR IE LL_RNG_DisableIT
325 * @param RNGx RNG Instance
328 __STATIC_INLINE
void LL_RNG_DisableIT(RNG_TypeDef
*RNGx
)
330 CLEAR_BIT(RNGx
->CR
, RNG_CR_IE
);
334 * @brief Check if Random Number Generator Interrupt is enabled
335 * (applies for either Seed error, Clock Error or Data ready interrupts)
336 * @rmtoll CR IE LL_RNG_IsEnabledIT
337 * @param RNGx RNG Instance
338 * @retval State of bit (1 or 0).
340 __STATIC_INLINE
uint32_t LL_RNG_IsEnabledIT(RNG_TypeDef
*RNGx
)
342 return ((READ_BIT(RNGx
->CR
, RNG_CR_IE
) == (RNG_CR_IE
)) ? 1UL : 0UL);
349 /** @defgroup RNG_LL_EF_Data_Management Data Management
354 * @brief Return32-bit Random Number value
355 * @rmtoll DR RNDATA LL_RNG_ReadRandData32
356 * @param RNGx RNG Instance
357 * @retval Generated 32-bit random value
359 __STATIC_INLINE
uint32_t LL_RNG_ReadRandData32(RNG_TypeDef
*RNGx
)
361 return (uint32_t)(READ_REG(RNGx
->DR
));
368 #if defined(USE_FULL_LL_DRIVER)
369 /** @defgroup RNG_LL_EF_Init Initialization and de-initialization functions
372 ErrorStatus
LL_RNG_Init(RNG_TypeDef
*RNGx
, LL_RNG_InitTypeDef
*RNG_InitStruct
);
373 void LL_RNG_StructInit(LL_RNG_InitTypeDef
*RNG_InitStruct
);
374 ErrorStatus
LL_RNG_DeInit(RNG_TypeDef
*RNGx
);
379 #endif /* USE_FULL_LL_DRIVER */
399 #endif /* __STM32G4xx_LL_RNG_H */
401 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/