stm32l4xx_ll_rng.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_rng.h
  4. * @author MCD Application Team
  5. * @brief Header file of RNG LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 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 STM32L4xx_LL_RNG_H
  20. #define STM32L4xx_LL_RNG_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l4xx.h"
  26. /** @addtogroup STM32L4xx_LL_Driver
  27. * @{
  28. */
  29. #if defined (RNG)
  30. /** @defgroup RNG_LL RNG
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private constants ---------------------------------------------------------*/
  36. /* Private macros ------------------------------------------------------------*/
  37. /* Exported types ------------------------------------------------------------*/
  38. #if defined(RNG_CR_CED)
  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 functions @ref LL_RNG_EnableClkErrorDetect(). */
  51. } LL_RNG_InitTypeDef;
  52. /**
  53. * @}
  54. */
  55. #endif /* USE_FULL_LL_DRIVER */
  56. #endif
  57. /* Exported constants --------------------------------------------------------*/
  58. /** @defgroup RNG_LL_Exported_Constants RNG Exported Constants
  59. * @{
  60. */
  61. #if defined(RNG_CR_CED)
  62. /** @defgroup RNG_LL_CED Clock Error Detection
  63. * @{
  64. */
  65. #define LL_RNG_CED_ENABLE 0x00000000U /*!< Clock error detection enabled */
  66. #define LL_RNG_CED_DISABLE RNG_CR_CED /*!< Clock error detection disabled */
  67. /**
  68. * @}
  69. */
  70. #endif
  71. #if defined(RNG_CR_CONDRST)
  72. /** @defgroup RNG_LL_Clock_Divider_Factor Value used to configure an internal
  73. * programmable divider acting on the incoming RNG clock
  74. * @{
  75. */
  76. #define LL_RNG_CLKDIV_BY_1 (0x00000000UL) /*!< No clock division */
  77. #define LL_RNG_CLKDIV_BY_2 (RNG_CR_CLKDIV_0)
  78. /*!< 2 RNG clock cycles per internal RNG clock */
  79. #define LL_RNG_CLKDIV_BY_4 (RNG_CR_CLKDIV_1)
  80. /*!< 4 RNG clock cycles per internal RNG clock */
  81. #define LL_RNG_CLKDIV_BY_8 (RNG_CR_CLKDIV_1 | RNG_CR_CLKDIV_0)
  82. /*!< 8 RNG clock cycles per internal RNG clock */
  83. #define LL_RNG_CLKDIV_BY_16 (RNG_CR_CLKDIV_2)
  84. /*!< 16 RNG clock cycles per internal RNG clock */
  85. #define LL_RNG_CLKDIV_BY_32 (RNG_CR_CLKDIV_2 | RNG_CR_CLKDIV_0)
  86. /*!< 32 RNG clock cycles per internal RNG clock */
  87. #define LL_RNG_CLKDIV_BY_64 (RNG_CR_CLKDIV_2 | RNG_CR_CLKDIV_1)
  88. /*!< 64 RNG clock cycles per internal RNG clock */
  89. #define LL_RNG_CLKDIV_BY_128 (RNG_CR_CLKDIV_2 | RNG_CR_CLKDIV_1 | RNG_CR_CLKDIV_0)
  90. /*!< 128 RNG clock cycles per internal RNG clock */
  91. #define LL_RNG_CLKDIV_BY_256 (RNG_CR_CLKDIV_3)
  92. /*!< 256 RNG clock cycles per internal RNG clock */
  93. #define LL_RNG_CLKDIV_BY_512 (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_0)
  94. /*!< 512 RNG clock cycles per internal RNG clock */
  95. #define LL_RNG_CLKDIV_BY_1024 (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_1)
  96. /*!< 1024 RNG clock cycles per internal RNG clock */
  97. #define LL_RNG_CLKDIV_BY_2048 (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_1 | RNG_CR_CLKDIV_0)
  98. /*!< 2048 RNG clock cycles per internal RNG clock */
  99. #define LL_RNG_CLKDIV_BY_4096 (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_2)
  100. /*!< 4096 RNG clock cycles per internal RNG clock */
  101. #define LL_RNG_CLKDIV_BY_8192 (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_2 | RNG_CR_CLKDIV_0)
  102. /*!< 8192 RNG clock cycles per internal RNG clock */
  103. #define LL_RNG_CLKDIV_BY_16384 (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_2 | RNG_CR_CLKDIV_1)
  104. /*!< 16384 RNG clock cycles per internal RNG clock */
  105. #define LL_RNG_CLKDIV_BY_32768 (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_2 | RNG_CR_CLKDIV_1 | RNG_CR_CLKDIV_0)
  106. /*!< 32768 RNG clock cycles per internal RNG clock */
  107. /**
  108. * @}
  109. */
  110. /** @defgroup RNG_LL_NIST_Compliance NIST Compliance configuration
  111. * @{
  112. */
  113. #define LL_RNG_NIST_COMPLIANT (0x00000000UL) /*!< NIST compliant configuration*/
  114. #define LL_RNG_NOTNIST_COMPLIANT (RNG_CR_NISTC) /*!< Non NIST compliant configuration */
  115. /**
  116. * @}
  117. */
  118. #endif/*RNG_CR_CONDRST*/
  119. /** @defgroup RNG_LL_EC_GET_FLAG Get Flags Defines
  120. * @brief Flags defines which can be used with LL_RNG_ReadReg function
  121. * @{
  122. */
  123. #define LL_RNG_SR_DRDY RNG_SR_DRDY /*!< Register contains valid random data */
  124. #define LL_RNG_SR_CECS RNG_SR_CECS /*!< Clock error current status */
  125. #define LL_RNG_SR_SECS RNG_SR_SECS /*!< Seed error current status */
  126. #define LL_RNG_SR_CEIS RNG_SR_CEIS /*!< Clock error interrupt status */
  127. #define LL_RNG_SR_SEIS RNG_SR_SEIS /*!< Seed error interrupt status */
  128. /**
  129. * @}
  130. */
  131. /** @defgroup RNG_LL_EC_IT IT Defines
  132. * @brief IT defines which can be used with LL_RNG_ReadReg and LL_RNG_WriteReg macros
  133. * @{
  134. */
  135. #define LL_RNG_CR_IE RNG_CR_IE /*!< RNG Interrupt enable */
  136. /**
  137. * @}
  138. */
  139. /**
  140. * @}
  141. */
  142. /* Exported macro ------------------------------------------------------------*/
  143. /** @defgroup RNG_LL_Exported_Macros RNG Exported Macros
  144. * @{
  145. */
  146. /** @defgroup RNG_LL_EM_WRITE_READ Common Write and read registers Macros
  147. * @{
  148. */
  149. /**
  150. * @brief Write a value in RNG register
  151. * @param __INSTANCE__ RNG Instance
  152. * @param __REG__ Register to be written
  153. * @param __VALUE__ Value to be written in the register
  154. * @retval None
  155. */
  156. #define LL_RNG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  157. /**
  158. * @brief Read a value in RNG register
  159. * @param __INSTANCE__ RNG Instance
  160. * @param __REG__ Register to be read
  161. * @retval Register value
  162. */
  163. #define LL_RNG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  164. /**
  165. * @}
  166. */
  167. /**
  168. * @}
  169. */
  170. /* Exported functions --------------------------------------------------------*/
  171. /** @defgroup RNG_LL_Exported_Functions RNG Exported Functions
  172. * @{
  173. */
  174. /** @defgroup RNG_LL_EF_Configuration RNG Configuration functions
  175. * @{
  176. */
  177. /**
  178. * @brief Enable Random Number Generation
  179. * @rmtoll CR RNGEN LL_RNG_Enable
  180. * @param RNGx RNG Instance
  181. * @retval None
  182. */
  183. __STATIC_INLINE void LL_RNG_Enable(RNG_TypeDef *RNGx)
  184. {
  185. SET_BIT(RNGx->CR, RNG_CR_RNGEN);
  186. }
  187. /**
  188. * @brief Disable Random Number Generation
  189. * @rmtoll CR RNGEN LL_RNG_Disable
  190. * @param RNGx RNG Instance
  191. * @retval None
  192. */
  193. __STATIC_INLINE void LL_RNG_Disable(RNG_TypeDef *RNGx)
  194. {
  195. CLEAR_BIT(RNGx->CR, RNG_CR_RNGEN);
  196. }
  197. /**
  198. * @brief Check if Random Number Generator is enabled
  199. * @rmtoll CR RNGEN LL_RNG_IsEnabled
  200. * @param RNGx RNG Instance
  201. * @retval State of bit (1 or 0).
  202. */
  203. __STATIC_INLINE uint32_t LL_RNG_IsEnabled(RNG_TypeDef *RNGx)
  204. {
  205. return ((READ_BIT(RNGx->CR, RNG_CR_RNGEN) == (RNG_CR_RNGEN)) ? 1UL : 0UL);
  206. }
  207. #if defined(RNG_CR_CED)
  208. /**
  209. * @brief Enable Clock Error Detection
  210. * @rmtoll CR CED LL_RNG_EnableClkErrorDetect
  211. * @param RNGx RNG Instance
  212. * @retval None
  213. */
  214. __STATIC_INLINE void LL_RNG_EnableClkErrorDetect(RNG_TypeDef *RNGx)
  215. {
  216. CLEAR_BIT(RNGx->CR, RNG_CR_CED);
  217. }
  218. /**
  219. * @brief Disable RNG Clock Error Detection
  220. * @rmtoll CR CED LL_RNG_DisableClkErrorDetect
  221. * @param RNGx RNG Instance
  222. * @retval None
  223. */
  224. __STATIC_INLINE void LL_RNG_DisableClkErrorDetect(RNG_TypeDef *RNGx)
  225. {
  226. SET_BIT(RNGx->CR, RNG_CR_CED);
  227. }
  228. /**
  229. * @brief Check if RNG Clock Error Detection is enabled
  230. * @rmtoll CR CED LL_RNG_IsEnabledClkErrorDetect
  231. * @param RNGx RNG Instance
  232. * @retval State of bit (1 or 0).
  233. */
  234. __STATIC_INLINE uint32_t LL_RNG_IsEnabledClkErrorDetect(RNG_TypeDef *RNGx)
  235. {
  236. return ((READ_BIT(RNGx->CR, RNG_CR_CED) != (RNG_CR_CED)) ? 1UL : 0UL);
  237. }
  238. #if defined(RNG_CR_CONDRST)
  239. /**
  240. * @brief Set RNG Conditioning Soft Reset bit
  241. * @rmtoll CR CONDRST LL_RNG_SetConditioningResetBit
  242. * @param RNGx RNG Instance
  243. * @retval None
  244. */
  245. __STATIC_INLINE void LL_RNG_SetConditioningResetBit(RNG_TypeDef *RNGx)
  246. {
  247. SET_BIT(RNGx->CR, RNG_CR_CONDRST);
  248. }
  249. /**
  250. * @brief Reset RNG Conditioning Soft Reset bit
  251. * @rmtoll CR CONDRST LL_RNG_ResetConditioningResetBit
  252. * @param RNGx RNG Instance
  253. * @retval None
  254. */
  255. __STATIC_INLINE void LL_RNG_ResetConditioningResetBit(RNG_TypeDef *RNGx)
  256. {
  257. CLEAR_BIT(RNGx->CR, RNG_CR_CONDRST);
  258. }
  259. /**
  260. * @brief Check if RNG Conditioning Soft Reset bit is set
  261. * @rmtoll CR CONDRST LL_RNG_IsResetConditioningBitSet
  262. * @param RNGx RNG Instance
  263. * @retval State of bit (1 or 0).
  264. */
  265. __STATIC_INLINE uint32_t LL_RNG_IsResetConditioningBitSet(RNG_TypeDef *RNGx)
  266. {
  267. return ((READ_BIT(RNGx->CR, RNG_CR_CONDRST) == (RNG_CR_CONDRST)) ? 1UL : 0UL);
  268. }
  269. /**
  270. * @brief Enable RNG Config Lock
  271. * @rmtoll CR CONFIGLOCK LL_RNG_ConfigLock
  272. * @param RNGx RNG Instance
  273. * @retval None
  274. */
  275. __STATIC_INLINE void LL_RNG_ConfigLock(RNG_TypeDef *RNGx)
  276. {
  277. SET_BIT(RNGx->CR, RNG_CR_CONFIGLOCK);
  278. }
  279. /**
  280. * @brief Check if RNG Config Lock is enabled
  281. * @rmtoll CR CONFIGLOCK LL_RNG_IsConfigLocked
  282. * @param RNGx RNG Instance
  283. * @retval State of bit (1 or 0).
  284. */
  285. __STATIC_INLINE uint32_t LL_RNG_IsConfigLocked(RNG_TypeDef *RNGx)
  286. {
  287. return ((READ_BIT(RNGx->CR, RNG_CR_CONFIGLOCK) == (RNG_CR_CONFIGLOCK)) ? 1UL : 0UL);
  288. }
  289. /**
  290. * @brief Enable NIST Compliance
  291. * @rmtoll CR NISTC LL_RNG_EnableNistCompliance
  292. * @param RNGx RNG Instance
  293. * @retval None
  294. */
  295. __STATIC_INLINE void LL_RNG_EnableNistCompliance(RNG_TypeDef *RNGx)
  296. {
  297. CLEAR_BIT(RNGx->CR, RNG_CR_NISTC);
  298. }
  299. /**
  300. * @brief Disable NIST Compliance
  301. * @rmtoll CR NISTC LL_RNG_DisableNistCompliance
  302. * @param RNGx RNG Instance
  303. * @retval None
  304. */
  305. __STATIC_INLINE void LL_RNG_DisableNistCompliance(RNG_TypeDef *RNGx)
  306. {
  307. SET_BIT(RNGx->CR, RNG_CR_NISTC);
  308. }
  309. /**
  310. * @brief Check if NIST Compliance is enabled
  311. * @rmtoll CR NISTC LL_RNG_IsNistComplianceEnabled
  312. * @param RNGx RNG Instance
  313. * @retval State of bit (1 or 0).
  314. */
  315. __STATIC_INLINE uint32_t LL_RNG_IsNistComplianceEnabled(RNG_TypeDef *RNGx)
  316. {
  317. return ((READ_BIT(RNGx->CR, RNG_CR_NISTC) != (RNG_CR_NISTC)) ? 1UL : 0UL);
  318. }
  319. /**
  320. * @brief Set RNG Config1 Configuration field value
  321. * @rmtoll CR RNG_CONFIG1 LL_RNG_SetConfig1
  322. * @param RNGx RNG Instance
  323. * @param Config1 Value between 0 and 0x3F
  324. * @retval None
  325. */
  326. __STATIC_INLINE void LL_RNG_SetConfig1(RNG_TypeDef *RNGx, uint32_t Config1)
  327. {
  328. MODIFY_REG(RNGx->CR, RNG_CR_RNG_CONFIG1, Config1 << RNG_CR_RNG_CONFIG1_Pos);
  329. }
  330. /**
  331. * @brief Get RNG Config1 Configuration field value
  332. * @rmtoll CR RNG_CONFIG1 LL_RNG_GetConfig1
  333. * @param RNGx RNG Instance
  334. * @retval Returned Value expressed on 6 bits : Value between 0 and 0x3F
  335. */
  336. __STATIC_INLINE uint32_t LL_RNG_GetConfig1(RNG_TypeDef *RNGx)
  337. {
  338. return (uint32_t)(READ_BIT(RNGx->CR, RNG_CR_RNG_CONFIG1) >> RNG_CR_RNG_CONFIG1_Pos);
  339. }
  340. /**
  341. * @brief Set RNG Config2 Configuration field value
  342. * @rmtoll CR RNG_CONFIG2 LL_RNG_SetConfig2
  343. * @param RNGx RNG Instance
  344. * @param Config2 Value between 0 and 0x7
  345. * @retval None
  346. */
  347. __STATIC_INLINE void LL_RNG_SetConfig2(RNG_TypeDef *RNGx, uint32_t Config2)
  348. {
  349. MODIFY_REG(RNGx->CR, RNG_CR_RNG_CONFIG2, Config2 << RNG_CR_RNG_CONFIG2_Pos);
  350. }
  351. /**
  352. * @brief Get RNG Config2 Configuration field value
  353. * @rmtoll CR RNG_CONFIG2 LL_RNG_GetConfig2
  354. * @param RNGx RNG Instance
  355. * @retval Returned Value expressed on 3 bits : Value between 0 and 0x7
  356. */
  357. __STATIC_INLINE uint32_t LL_RNG_GetConfig2(RNG_TypeDef *RNGx)
  358. {
  359. return (uint32_t)(READ_BIT(RNGx->CR, RNG_CR_RNG_CONFIG2) >> RNG_CR_RNG_CONFIG2_Pos);
  360. }
  361. /**
  362. * @brief Set RNG Config3 Configuration field value
  363. * @rmtoll CR RNG_CONFIG3 LL_RNG_SetConfig3
  364. * @param RNGx RNG Instance
  365. * @param Config3 Value between 0 and 0xF
  366. * @retval None
  367. */
  368. __STATIC_INLINE void LL_RNG_SetConfig3(RNG_TypeDef *RNGx, uint32_t Config3)
  369. {
  370. MODIFY_REG(RNGx->CR, RNG_CR_RNG_CONFIG3, Config3 << RNG_CR_RNG_CONFIG3_Pos);
  371. }
  372. /**
  373. * @brief Get RNG Config3 Configuration field value
  374. * @rmtoll CR RNG_CONFIG3 LL_RNG_GetConfig3
  375. * @param RNGx RNG Instance
  376. * @retval Returned Value expressed on 4 bits : Value between 0 and 0xF
  377. */
  378. __STATIC_INLINE uint32_t LL_RNG_GetConfig3(RNG_TypeDef *RNGx)
  379. {
  380. return (uint32_t)(READ_BIT(RNGx->CR, RNG_CR_RNG_CONFIG3) >> RNG_CR_RNG_CONFIG3_Pos);
  381. }
  382. /**
  383. * @brief Set RNG Clock divider factor
  384. * @rmtoll CR CLKDIV LL_RNG_SetClockDivider
  385. * @param RNGx RNG Instance
  386. * @param Divider can be one of the following values:
  387. * @arg @ref LL_RNG_CLKDIV_BY_1
  388. * @arg @ref LL_RNG_CLKDIV_BY_2
  389. * @arg @ref LL_RNG_CLKDIV_BY_4
  390. * @arg @ref LL_RNG_CLKDIV_BY_8
  391. * @arg @ref LL_RNG_CLKDIV_BY_16
  392. * @arg @ref LL_RNG_CLKDIV_BY_32
  393. * @arg @ref LL_RNG_CLKDIV_BY_64
  394. * @arg @ref LL_RNG_CLKDIV_BY_128
  395. * @arg @ref LL_RNG_CLKDIV_BY_256
  396. * @arg @ref LL_RNG_CLKDIV_BY_512
  397. * @arg @ref LL_RNG_CLKDIV_BY_1024
  398. * @arg @ref LL_RNG_CLKDIV_BY_2048
  399. * @arg @ref LL_RNG_CLKDIV_BY_4096
  400. * @arg @ref LL_RNG_CLKDIV_BY_8192
  401. * @arg @ref LL_RNG_CLKDIV_BY_16384
  402. * @arg @ref LL_RNG_CLKDIV_BY_32768
  403. * @retval None
  404. */
  405. __STATIC_INLINE void LL_RNG_SetClockDivider(RNG_TypeDef *RNGx, uint32_t Divider)
  406. {
  407. MODIFY_REG(RNGx->CR, RNG_CR_CLKDIV, Divider << RNG_CR_CLKDIV_Pos);
  408. }
  409. /**
  410. * @brief Get RNG Clock divider factor
  411. * @rmtoll CR CLKDIV LL_RNG_GetClockDivider
  412. * @param RNGx RNG Instance
  413. * @retval Returned value can be one of the following values:
  414. * @arg @ref LL_RNG_CLKDIV_BY_1
  415. * @arg @ref LL_RNG_CLKDIV_BY_2
  416. * @arg @ref LL_RNG_CLKDIV_BY_4
  417. * @arg @ref LL_RNG_CLKDIV_BY_8
  418. * @arg @ref LL_RNG_CLKDIV_BY_16
  419. * @arg @ref LL_RNG_CLKDIV_BY_32
  420. * @arg @ref LL_RNG_CLKDIV_BY_64
  421. * @arg @ref LL_RNG_CLKDIV_BY_128
  422. * @arg @ref LL_RNG_CLKDIV_BY_256
  423. * @arg @ref LL_RNG_CLKDIV_BY_512
  424. * @arg @ref LL_RNG_CLKDIV_BY_1024
  425. * @arg @ref LL_RNG_CLKDIV_BY_2048
  426. * @arg @ref LL_RNG_CLKDIV_BY_4096
  427. * @arg @ref LL_RNG_CLKDIV_BY_8192
  428. * @arg @ref LL_RNG_CLKDIV_BY_16384
  429. * @arg @ref LL_RNG_CLKDIV_BY_32768
  430. */
  431. __STATIC_INLINE uint32_t LL_RNG_GetClockDivider(RNG_TypeDef *RNGx)
  432. {
  433. return (uint32_t)READ_BIT(RNGx->CR, RNG_CR_CLKDIV);
  434. }
  435. #endif /*RNG_CR_CONDRST*/
  436. #endif
  437. /**
  438. * @}
  439. */
  440. /** @defgroup RNG_LL_EF_FLAG_Management FLAG Management
  441. * @{
  442. */
  443. /**
  444. * @brief Indicate if the RNG Data ready Flag is set or not
  445. * @rmtoll SR DRDY LL_RNG_IsActiveFlag_DRDY
  446. * @param RNGx RNG Instance
  447. * @retval State of bit (1 or 0).
  448. */
  449. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_DRDY(RNG_TypeDef *RNGx)
  450. {
  451. return ((READ_BIT(RNGx->SR, RNG_SR_DRDY) == (RNG_SR_DRDY)) ? 1UL : 0UL);
  452. }
  453. /**
  454. * @brief Indicate if the Clock Error Current Status Flag is set or not
  455. * @rmtoll SR CECS LL_RNG_IsActiveFlag_CECS
  456. * @param RNGx RNG Instance
  457. * @retval State of bit (1 or 0).
  458. */
  459. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_CECS(RNG_TypeDef *RNGx)
  460. {
  461. return ((READ_BIT(RNGx->SR, RNG_SR_CECS) == (RNG_SR_CECS)) ? 1UL : 0UL);
  462. }
  463. /**
  464. * @brief Indicate if the Seed Error Current Status Flag is set or not
  465. * @rmtoll SR SECS LL_RNG_IsActiveFlag_SECS
  466. * @param RNGx RNG Instance
  467. * @retval State of bit (1 or 0).
  468. */
  469. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_SECS(RNG_TypeDef *RNGx)
  470. {
  471. return ((READ_BIT(RNGx->SR, RNG_SR_SECS) == (RNG_SR_SECS)) ? 1UL : 0UL);
  472. }
  473. /**
  474. * @brief Indicate if the Clock Error Interrupt Status Flag is set or not
  475. * @rmtoll SR CEIS LL_RNG_IsActiveFlag_CEIS
  476. * @param RNGx RNG Instance
  477. * @retval State of bit (1 or 0).
  478. */
  479. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_CEIS(RNG_TypeDef *RNGx)
  480. {
  481. return ((READ_BIT(RNGx->SR, RNG_SR_CEIS) == (RNG_SR_CEIS)) ? 1UL : 0UL);
  482. }
  483. /**
  484. * @brief Indicate if the Seed Error Interrupt Status Flag is set or not
  485. * @rmtoll SR SEIS LL_RNG_IsActiveFlag_SEIS
  486. * @param RNGx RNG Instance
  487. * @retval State of bit (1 or 0).
  488. */
  489. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_SEIS(RNG_TypeDef *RNGx)
  490. {
  491. return ((READ_BIT(RNGx->SR, RNG_SR_SEIS) == (RNG_SR_SEIS)) ? 1UL : 0UL);
  492. }
  493. /**
  494. * @brief Clear Clock Error interrupt Status (CEIS) Flag
  495. * @rmtoll SR CEIS LL_RNG_ClearFlag_CEIS
  496. * @param RNGx RNG Instance
  497. * @retval None
  498. */
  499. __STATIC_INLINE void LL_RNG_ClearFlag_CEIS(RNG_TypeDef *RNGx)
  500. {
  501. WRITE_REG(RNGx->SR, ~RNG_SR_CEIS);
  502. }
  503. /**
  504. * @brief Clear Seed Error interrupt Status (SEIS) Flag
  505. * @rmtoll SR SEIS LL_RNG_ClearFlag_SEIS
  506. * @param RNGx RNG Instance
  507. * @retval None
  508. */
  509. __STATIC_INLINE void LL_RNG_ClearFlag_SEIS(RNG_TypeDef *RNGx)
  510. {
  511. WRITE_REG(RNGx->SR, ~RNG_SR_SEIS);
  512. }
  513. /**
  514. * @}
  515. */
  516. /** @defgroup RNG_LL_EF_IT_Management IT Management
  517. * @{
  518. */
  519. /**
  520. * @brief Enable Random Number Generator Interrupt
  521. * (applies for either Seed error, Clock Error or Data ready interrupts)
  522. * @rmtoll CR IE LL_RNG_EnableIT
  523. * @param RNGx RNG Instance
  524. * @retval None
  525. */
  526. __STATIC_INLINE void LL_RNG_EnableIT(RNG_TypeDef *RNGx)
  527. {
  528. SET_BIT(RNGx->CR, RNG_CR_IE);
  529. }
  530. /**
  531. * @brief Disable Random Number Generator Interrupt
  532. * (applies for either Seed error, Clock Error or Data ready interrupts)
  533. * @rmtoll CR IE LL_RNG_DisableIT
  534. * @param RNGx RNG Instance
  535. * @retval None
  536. */
  537. __STATIC_INLINE void LL_RNG_DisableIT(RNG_TypeDef *RNGx)
  538. {
  539. CLEAR_BIT(RNGx->CR, RNG_CR_IE);
  540. }
  541. /**
  542. * @brief Check if Random Number Generator Interrupt is enabled
  543. * (applies for either Seed error, Clock Error or Data ready interrupts)
  544. * @rmtoll CR IE LL_RNG_IsEnabledIT
  545. * @param RNGx RNG Instance
  546. * @retval State of bit (1 or 0).
  547. */
  548. __STATIC_INLINE uint32_t LL_RNG_IsEnabledIT(RNG_TypeDef *RNGx)
  549. {
  550. return ((READ_BIT(RNGx->CR, RNG_CR_IE) == (RNG_CR_IE)) ? 1UL : 0UL);
  551. }
  552. /**
  553. * @}
  554. */
  555. /** @defgroup RNG_LL_EF_Data_Management Data Management
  556. * @{
  557. */
  558. /**
  559. * @brief Return32-bit Random Number value
  560. * @rmtoll DR RNDATA LL_RNG_ReadRandData32
  561. * @param RNGx RNG Instance
  562. * @retval Generated 32-bit random value
  563. */
  564. __STATIC_INLINE uint32_t LL_RNG_ReadRandData32(RNG_TypeDef *RNGx)
  565. {
  566. return (uint32_t)(READ_REG(RNGx->DR));
  567. }
  568. /**
  569. * @}
  570. */
  571. #if defined(RNG_VER_3_2) || defined (RNG_VER_3_1)
  572. /** @defgroup RNG_LL_EF_Health_Test_Control Health Test Control
  573. * @{
  574. */
  575. /**
  576. * @brief Set RNG Health Test Control
  577. * @rmtoll HTCR HTCFG LL_RNG_SetHealthconfiguration
  578. * @param RNGx RNG Instance
  579. * @param HTCFG can be values of 32 bits
  580. * @retval None
  581. */
  582. __STATIC_INLINE void LL_RNG_SetHealthconfiguration(RNG_TypeDef *RNGx, uint32_t HTCFG)
  583. {
  584. WRITE_REG(RNGx->HTCR, HTCFG);
  585. }
  586. /**
  587. * @brief Get RNG Health Test Control
  588. * @rmtoll HTCR HTCFG LL_RNG_GetHealthconfiguration
  589. * @param RNGx RNG Instance
  590. * @retval Return 32-bit RNG Health Test configuration
  591. */
  592. __STATIC_INLINE uint32_t LL_RNG_GetHealthconfiguration(RNG_TypeDef *RNGx)
  593. {
  594. return (uint32_t)READ_REG(RNGx->HTCR);
  595. }
  596. /**
  597. * @}
  598. */
  599. #endif /* RNG_VER_3_2 || RNG_VER_3_1 */
  600. #if defined(USE_FULL_LL_DRIVER)
  601. /** @defgroup RNG_LL_EF_Init Initialization and de-initialization functions
  602. * @{
  603. */
  604. #if defined(RNG_CR_CED)
  605. ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct);
  606. void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct);
  607. #endif
  608. ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx);
  609. /**
  610. * @}
  611. */
  612. #endif /* USE_FULL_LL_DRIVER */
  613. /**
  614. * @}
  615. */
  616. /**
  617. * @}
  618. */
  619. #endif /* RNG */
  620. /**
  621. * @}
  622. */
  623. #ifdef __cplusplus
  624. }
  625. #endif
  626. #endif /* STM32L4xx_LL_RNG_H */