stm32g0xx_ll_rng.h 11 KB

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