stm32l4xx_ll_rng.h 22 KB

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