stm32f4xx_ll_rng.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_ll_rng.h
  4. * @author MCD Application Team
  5. * @brief Header file of RNG LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  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
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32F4xx_LL_RNG_H
  21. #define STM32F4xx_LL_RNG_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f4xx.h"
  27. /** @addtogroup STM32F4xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (RNG)
  31. /** @defgroup RNG_LL RNG
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. /* Exported types ------------------------------------------------------------*/
  39. /* Exported constants --------------------------------------------------------*/
  40. /** @defgroup RNG_LL_Exported_Constants RNG Exported Constants
  41. * @{
  42. */
  43. /** @defgroup RNG_LL_EC_GET_FLAG Get Flags Defines
  44. * @brief Flags defines which can be used with LL_RNG_ReadReg function
  45. * @{
  46. */
  47. #define LL_RNG_SR_DRDY RNG_SR_DRDY /*!< Register contains valid random data */
  48. #define LL_RNG_SR_CECS RNG_SR_CECS /*!< Clock error current status */
  49. #define LL_RNG_SR_SECS RNG_SR_SECS /*!< Seed error current status */
  50. #define LL_RNG_SR_CEIS RNG_SR_CEIS /*!< Clock error interrupt status */
  51. #define LL_RNG_SR_SEIS RNG_SR_SEIS /*!< Seed error interrupt status */
  52. /**
  53. * @}
  54. */
  55. /** @defgroup RNG_LL_EC_IT IT Defines
  56. * @brief IT defines which can be used with LL_RNG_ReadReg and LL_RNG_WriteReg macros
  57. * @{
  58. */
  59. #define LL_RNG_CR_IE RNG_CR_IE /*!< RNG Interrupt enable */
  60. /**
  61. * @}
  62. */
  63. /**
  64. * @}
  65. */
  66. /* Exported macro ------------------------------------------------------------*/
  67. /** @defgroup RNG_LL_Exported_Macros RNG Exported Macros
  68. * @{
  69. */
  70. /** @defgroup RNG_LL_EM_WRITE_READ Common Write and read registers Macros
  71. * @{
  72. */
  73. /**
  74. * @brief Write a value in RNG register
  75. * @param __INSTANCE__ RNG Instance
  76. * @param __REG__ Register to be written
  77. * @param __VALUE__ Value to be written in the register
  78. * @retval None
  79. */
  80. #define LL_RNG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  81. /**
  82. * @brief Read a value in RNG register
  83. * @param __INSTANCE__ RNG Instance
  84. * @param __REG__ Register to be read
  85. * @retval Register value
  86. */
  87. #define LL_RNG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  88. /**
  89. * @}
  90. */
  91. /**
  92. * @}
  93. */
  94. /* Exported functions --------------------------------------------------------*/
  95. /** @defgroup RNG_LL_Exported_Functions RNG Exported Functions
  96. * @{
  97. */
  98. /** @defgroup RNG_LL_EF_Configuration RNG Configuration functions
  99. * @{
  100. */
  101. /**
  102. * @brief Enable Random Number Generation
  103. * @rmtoll CR RNGEN LL_RNG_Enable
  104. * @param RNGx RNG Instance
  105. * @retval None
  106. */
  107. __STATIC_INLINE void LL_RNG_Enable(RNG_TypeDef *RNGx)
  108. {
  109. SET_BIT(RNGx->CR, RNG_CR_RNGEN);
  110. }
  111. /**
  112. * @brief Disable Random Number Generation
  113. * @rmtoll CR RNGEN LL_RNG_Disable
  114. * @param RNGx RNG Instance
  115. * @retval None
  116. */
  117. __STATIC_INLINE void LL_RNG_Disable(RNG_TypeDef *RNGx)
  118. {
  119. CLEAR_BIT(RNGx->CR, RNG_CR_RNGEN);
  120. }
  121. /**
  122. * @brief Check if Random Number Generator is enabled
  123. * @rmtoll CR RNGEN LL_RNG_IsEnabled
  124. * @param RNGx RNG Instance
  125. * @retval State of bit (1 or 0).
  126. */
  127. __STATIC_INLINE uint32_t LL_RNG_IsEnabled(RNG_TypeDef *RNGx)
  128. {
  129. return ((READ_BIT(RNGx->CR, RNG_CR_RNGEN) == (RNG_CR_RNGEN)) ? 1UL : 0UL);
  130. }
  131. /**
  132. * @}
  133. */
  134. /** @defgroup RNG_LL_EF_FLAG_Management FLAG Management
  135. * @{
  136. */
  137. /**
  138. * @brief Indicate if the RNG Data ready Flag is set or not
  139. * @rmtoll SR DRDY LL_RNG_IsActiveFlag_DRDY
  140. * @param RNGx RNG Instance
  141. * @retval State of bit (1 or 0).
  142. */
  143. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_DRDY(RNG_TypeDef *RNGx)
  144. {
  145. return ((READ_BIT(RNGx->SR, RNG_SR_DRDY) == (RNG_SR_DRDY)) ? 1UL : 0UL);
  146. }
  147. /**
  148. * @brief Indicate if the Clock Error Current Status Flag is set or not
  149. * @rmtoll SR CECS LL_RNG_IsActiveFlag_CECS
  150. * @param RNGx RNG Instance
  151. * @retval State of bit (1 or 0).
  152. */
  153. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_CECS(RNG_TypeDef *RNGx)
  154. {
  155. return ((READ_BIT(RNGx->SR, RNG_SR_CECS) == (RNG_SR_CECS)) ? 1UL : 0UL);
  156. }
  157. /**
  158. * @brief Indicate if the Seed Error Current Status Flag is set or not
  159. * @rmtoll SR SECS LL_RNG_IsActiveFlag_SECS
  160. * @param RNGx RNG Instance
  161. * @retval State of bit (1 or 0).
  162. */
  163. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_SECS(RNG_TypeDef *RNGx)
  164. {
  165. return ((READ_BIT(RNGx->SR, RNG_SR_SECS) == (RNG_SR_SECS)) ? 1UL : 0UL);
  166. }
  167. /**
  168. * @brief Indicate if the Clock Error Interrupt Status Flag is set or not
  169. * @rmtoll SR CEIS LL_RNG_IsActiveFlag_CEIS
  170. * @param RNGx RNG Instance
  171. * @retval State of bit (1 or 0).
  172. */
  173. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_CEIS(RNG_TypeDef *RNGx)
  174. {
  175. return ((READ_BIT(RNGx->SR, RNG_SR_CEIS) == (RNG_SR_CEIS)) ? 1UL : 0UL);
  176. }
  177. /**
  178. * @brief Indicate if the Seed Error Interrupt Status Flag is set or not
  179. * @rmtoll SR SEIS LL_RNG_IsActiveFlag_SEIS
  180. * @param RNGx RNG Instance
  181. * @retval State of bit (1 or 0).
  182. */
  183. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_SEIS(RNG_TypeDef *RNGx)
  184. {
  185. return ((READ_BIT(RNGx->SR, RNG_SR_SEIS) == (RNG_SR_SEIS)) ? 1UL : 0UL);
  186. }
  187. /**
  188. * @brief Clear Clock Error interrupt Status (CEIS) Flag
  189. * @rmtoll SR CEIS LL_RNG_ClearFlag_CEIS
  190. * @param RNGx RNG Instance
  191. * @retval None
  192. */
  193. __STATIC_INLINE void LL_RNG_ClearFlag_CEIS(RNG_TypeDef *RNGx)
  194. {
  195. WRITE_REG(RNGx->SR, ~RNG_SR_CEIS);
  196. }
  197. /**
  198. * @brief Clear Seed Error interrupt Status (SEIS) Flag
  199. * @rmtoll SR SEIS LL_RNG_ClearFlag_SEIS
  200. * @param RNGx RNG Instance
  201. * @retval None
  202. */
  203. __STATIC_INLINE void LL_RNG_ClearFlag_SEIS(RNG_TypeDef *RNGx)
  204. {
  205. WRITE_REG(RNGx->SR, ~RNG_SR_SEIS);
  206. }
  207. /**
  208. * @}
  209. */
  210. /** @defgroup RNG_LL_EF_IT_Management IT Management
  211. * @{
  212. */
  213. /**
  214. * @brief Enable Random Number Generator Interrupt
  215. * (applies for either Seed error, Clock Error or Data ready interrupts)
  216. * @rmtoll CR IE LL_RNG_EnableIT
  217. * @param RNGx RNG Instance
  218. * @retval None
  219. */
  220. __STATIC_INLINE void LL_RNG_EnableIT(RNG_TypeDef *RNGx)
  221. {
  222. SET_BIT(RNGx->CR, RNG_CR_IE);
  223. }
  224. /**
  225. * @brief Disable Random Number Generator Interrupt
  226. * (applies for either Seed error, Clock Error or Data ready interrupts)
  227. * @rmtoll CR IE LL_RNG_DisableIT
  228. * @param RNGx RNG Instance
  229. * @retval None
  230. */
  231. __STATIC_INLINE void LL_RNG_DisableIT(RNG_TypeDef *RNGx)
  232. {
  233. CLEAR_BIT(RNGx->CR, RNG_CR_IE);
  234. }
  235. /**
  236. * @brief Check if Random Number Generator Interrupt is enabled
  237. * (applies for either Seed error, Clock Error or Data ready interrupts)
  238. * @rmtoll CR IE LL_RNG_IsEnabledIT
  239. * @param RNGx RNG Instance
  240. * @retval State of bit (1 or 0).
  241. */
  242. __STATIC_INLINE uint32_t LL_RNG_IsEnabledIT(RNG_TypeDef *RNGx)
  243. {
  244. return ((READ_BIT(RNGx->CR, RNG_CR_IE) == (RNG_CR_IE)) ? 1UL : 0UL);
  245. }
  246. /**
  247. * @}
  248. */
  249. /** @defgroup RNG_LL_EF_Data_Management Data Management
  250. * @{
  251. */
  252. /**
  253. * @brief Return32-bit Random Number value
  254. * @rmtoll DR RNDATA LL_RNG_ReadRandData32
  255. * @param RNGx RNG Instance
  256. * @retval Generated 32-bit random value
  257. */
  258. __STATIC_INLINE uint32_t LL_RNG_ReadRandData32(RNG_TypeDef *RNGx)
  259. {
  260. return (uint32_t)(READ_REG(RNGx->DR));
  261. }
  262. /**
  263. * @}
  264. */
  265. #if defined(USE_FULL_LL_DRIVER)
  266. /** @defgroup RNG_LL_EF_Init Initialization and de-initialization functions
  267. * @{
  268. */
  269. ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx);
  270. /**
  271. * @}
  272. */
  273. #endif /* USE_FULL_LL_DRIVER */
  274. /**
  275. * @}
  276. */
  277. /**
  278. * @}
  279. */
  280. #endif /* RNG */
  281. /**
  282. * @}
  283. */
  284. #ifdef __cplusplus
  285. }
  286. #endif
  287. #endif /* __STM32F4xx_LL_RNG_H */
  288. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/