stm32h7xx_ll_rng.h 23 KB

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