1
0

stm32l4xx_ll_rng.h 9.8 KB

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