stm32f4xx_ll_rng.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F4xx_LL_RNG_H
  37. #define __STM32F4xx_LL_RNG_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f4xx.h"
  43. /** @addtogroup STM32F4xx_LL_Driver
  44. * @{
  45. */
  46. #if defined(RNG)
  47. /** @defgroup RNG_LL RNG
  48. * @{
  49. */
  50. /* Private types -------------------------------------------------------------*/
  51. /* Private variables ---------------------------------------------------------*/
  52. /* Private constants ---------------------------------------------------------*/
  53. /* Private macros ------------------------------------------------------------*/
  54. /* Exported types ------------------------------------------------------------*/
  55. /* Exported constants --------------------------------------------------------*/
  56. /** @defgroup RNG_LL_Exported_Constants RNG Exported Constants
  57. * @{
  58. */
  59. /** @defgroup RNG_LL_EC_GET_FLAG Get Flags Defines
  60. * @brief Flags defines which can be used with LL_RNG_ReadReg function
  61. * @{
  62. */
  63. #define LL_RNG_SR_DRDY RNG_SR_DRDY /*!< Register contains valid random data */
  64. #define LL_RNG_SR_CECS RNG_SR_CECS /*!< Clock error current status */
  65. #define LL_RNG_SR_SECS RNG_SR_SECS /*!< Seed error current status */
  66. #define LL_RNG_SR_CEIS RNG_SR_CEIS /*!< Clock error interrupt status */
  67. #define LL_RNG_SR_SEIS RNG_SR_SEIS /*!< Seed error interrupt status */
  68. /**
  69. * @}
  70. */
  71. /** @defgroup RNG_LL_EC_IT IT Defines
  72. * @brief IT defines which can be used with LL_RNG_ReadReg and LL_RNG_WriteReg macros
  73. * @{
  74. */
  75. #define LL_RNG_CR_IE RNG_CR_IE /*!< RNG Interrupt enable */
  76. /**
  77. * @}
  78. */
  79. /**
  80. * @}
  81. */
  82. /* Exported macro ------------------------------------------------------------*/
  83. /** @defgroup RNG_LL_Exported_Macros RNG Exported Macros
  84. * @{
  85. */
  86. /** @defgroup RNG_LL_EM_WRITE_READ Common Write and read registers Macros
  87. * @{
  88. */
  89. /**
  90. * @brief Write a value in RNG register
  91. * @param __INSTANCE__ RNG Instance
  92. * @param __REG__ Register to be written
  93. * @param __VALUE__ Value to be written in the register
  94. * @retval None
  95. */
  96. #define LL_RNG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  97. /**
  98. * @brief Read a value in RNG register
  99. * @param __INSTANCE__ RNG Instance
  100. * @param __REG__ Register to be read
  101. * @retval Register value
  102. */
  103. #define LL_RNG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  104. /**
  105. * @}
  106. */
  107. /**
  108. * @}
  109. */
  110. /* Exported functions --------------------------------------------------------*/
  111. /** @defgroup RNG_LL_Exported_Functions RNG Exported Functions
  112. * @{
  113. */
  114. /** @defgroup RNG_LL_EF_Configuration RNG Configuration functions
  115. * @{
  116. */
  117. /**
  118. * @brief Enable Random Number Generation
  119. * @rmtoll CR RNGEN LL_RNG_Enable
  120. * @param RNGx RNG Instance
  121. * @retval None
  122. */
  123. __STATIC_INLINE void LL_RNG_Enable(RNG_TypeDef *RNGx)
  124. {
  125. SET_BIT(RNGx->CR, RNG_CR_RNGEN);
  126. }
  127. /**
  128. * @brief Disable Random Number Generation
  129. * @rmtoll CR RNGEN LL_RNG_Disable
  130. * @param RNGx RNG Instance
  131. * @retval None
  132. */
  133. __STATIC_INLINE void LL_RNG_Disable(RNG_TypeDef *RNGx)
  134. {
  135. CLEAR_BIT(RNGx->CR, RNG_CR_RNGEN);
  136. }
  137. /**
  138. * @brief Check if Random Number Generator is enabled
  139. * @rmtoll CR RNGEN LL_RNG_IsEnabled
  140. * @param RNGx RNG Instance
  141. * @retval State of bit (1 or 0).
  142. */
  143. __STATIC_INLINE uint32_t LL_RNG_IsEnabled(RNG_TypeDef *RNGx)
  144. {
  145. return (READ_BIT(RNGx->CR, RNG_CR_RNGEN) == (RNG_CR_RNGEN));
  146. }
  147. /**
  148. * @}
  149. */
  150. /** @defgroup RNG_LL_EF_FLAG_Management FLAG Management
  151. * @{
  152. */
  153. /**
  154. * @brief Indicate if the RNG Data ready Flag is set or not
  155. * @rmtoll SR DRDY LL_RNG_IsActiveFlag_DRDY
  156. * @param RNGx RNG Instance
  157. * @retval State of bit (1 or 0).
  158. */
  159. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_DRDY(RNG_TypeDef *RNGx)
  160. {
  161. return (READ_BIT(RNGx->SR, RNG_SR_DRDY) == (RNG_SR_DRDY));
  162. }
  163. /**
  164. * @brief Indicate if the Clock Error Current Status Flag is set or not
  165. * @rmtoll SR CECS LL_RNG_IsActiveFlag_CECS
  166. * @param RNGx RNG Instance
  167. * @retval State of bit (1 or 0).
  168. */
  169. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_CECS(RNG_TypeDef *RNGx)
  170. {
  171. return (READ_BIT(RNGx->SR, RNG_SR_CECS) == (RNG_SR_CECS));
  172. }
  173. /**
  174. * @brief Indicate if the Seed Error Current Status Flag is set or not
  175. * @rmtoll SR SECS LL_RNG_IsActiveFlag_SECS
  176. * @param RNGx RNG Instance
  177. * @retval State of bit (1 or 0).
  178. */
  179. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_SECS(RNG_TypeDef *RNGx)
  180. {
  181. return (READ_BIT(RNGx->SR, RNG_SR_SECS) == (RNG_SR_SECS));
  182. }
  183. /**
  184. * @brief Indicate if the Clock Error Interrupt Status Flag is set or not
  185. * @rmtoll SR CEIS LL_RNG_IsActiveFlag_CEIS
  186. * @param RNGx RNG Instance
  187. * @retval State of bit (1 or 0).
  188. */
  189. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_CEIS(RNG_TypeDef *RNGx)
  190. {
  191. return (READ_BIT(RNGx->SR, RNG_SR_CEIS) == (RNG_SR_CEIS));
  192. }
  193. /**
  194. * @brief Indicate if the Seed Error Interrupt Status Flag is set or not
  195. * @rmtoll SR SEIS LL_RNG_IsActiveFlag_SEIS
  196. * @param RNGx RNG Instance
  197. * @retval State of bit (1 or 0).
  198. */
  199. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_SEIS(RNG_TypeDef *RNGx)
  200. {
  201. return (READ_BIT(RNGx->SR, RNG_SR_SEIS) == (RNG_SR_SEIS));
  202. }
  203. /**
  204. * @brief Clear Clock Error interrupt Status (CEIS) Flag
  205. * @rmtoll SR CEIS LL_RNG_ClearFlag_CEIS
  206. * @param RNGx RNG Instance
  207. * @retval None
  208. */
  209. __STATIC_INLINE void LL_RNG_ClearFlag_CEIS(RNG_TypeDef *RNGx)
  210. {
  211. WRITE_REG(RNGx->SR, ~RNG_SR_CEIS);
  212. }
  213. /**
  214. * @brief Clear Seed Error interrupt Status (SEIS) Flag
  215. * @rmtoll SR SEIS LL_RNG_ClearFlag_SEIS
  216. * @param RNGx RNG Instance
  217. * @retval None
  218. */
  219. __STATIC_INLINE void LL_RNG_ClearFlag_SEIS(RNG_TypeDef *RNGx)
  220. {
  221. WRITE_REG(RNGx->SR, ~RNG_SR_SEIS);
  222. }
  223. /**
  224. * @}
  225. */
  226. /** @defgroup RNG_LL_EF_IT_Management IT Management
  227. * @{
  228. */
  229. /**
  230. * @brief Enable Random Number Generator Interrupt
  231. * (applies for either Seed error, Clock Error or Data ready interrupts)
  232. * @rmtoll CR IE LL_RNG_EnableIT
  233. * @param RNGx RNG Instance
  234. * @retval None
  235. */
  236. __STATIC_INLINE void LL_RNG_EnableIT(RNG_TypeDef *RNGx)
  237. {
  238. SET_BIT(RNGx->CR, RNG_CR_IE);
  239. }
  240. /**
  241. * @brief Disable Random Number Generator Interrupt
  242. * (applies for either Seed error, Clock Error or Data ready interrupts)
  243. * @rmtoll CR IE LL_RNG_DisableIT
  244. * @param RNGx RNG Instance
  245. * @retval None
  246. */
  247. __STATIC_INLINE void LL_RNG_DisableIT(RNG_TypeDef *RNGx)
  248. {
  249. CLEAR_BIT(RNGx->CR, RNG_CR_IE);
  250. }
  251. /**
  252. * @brief Check if Random Number Generator Interrupt is enabled
  253. * (applies for either Seed error, Clock Error or Data ready interrupts)
  254. * @rmtoll CR IE LL_RNG_IsEnabledIT
  255. * @param RNGx RNG Instance
  256. * @retval State of bit (1 or 0).
  257. */
  258. __STATIC_INLINE uint32_t LL_RNG_IsEnabledIT(RNG_TypeDef *RNGx)
  259. {
  260. return (READ_BIT(RNGx->CR, RNG_CR_IE) == (RNG_CR_IE));
  261. }
  262. /**
  263. * @}
  264. */
  265. /** @defgroup RNG_LL_EF_Data_Management Data Management
  266. * @{
  267. */
  268. /**
  269. * @brief Return32-bit Random Number value
  270. * @rmtoll DR RNDATA LL_RNG_ReadRandData32
  271. * @param RNGx RNG Instance
  272. * @retval Generated 32-bit random value
  273. */
  274. __STATIC_INLINE uint32_t LL_RNG_ReadRandData32(RNG_TypeDef *RNGx)
  275. {
  276. return (uint32_t)(READ_REG(RNGx->DR));
  277. }
  278. /**
  279. * @}
  280. */
  281. #if defined(USE_FULL_LL_DRIVER)
  282. /** @defgroup RNG_LL_EF_Init Initialization and de-initialization functions
  283. * @{
  284. */
  285. ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx);
  286. /**
  287. * @}
  288. */
  289. #endif /* USE_FULL_LL_DRIVER */
  290. /**
  291. * @}
  292. */
  293. /**
  294. * @}
  295. */
  296. #endif /* defined(RNG) */
  297. /**
  298. * @}
  299. */
  300. #ifdef __cplusplus
  301. }
  302. #endif
  303. #endif /* __STM32F4xx_LL_RNG_H */
  304. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/