stm32l4xx_ll_rng.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. * <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 __STM32L4xx_LL_RNG_H
  37. #define __STM32L4xx_LL_RNG_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l4xx.h"
  43. /** @addtogroup STM32L4xx_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. #if defined(USE_FULL_LL_DRIVER)
  56. /** @defgroup RNG_LL_ES_Init_Struct RNG Exported Init structures
  57. * @{
  58. */
  59. #if defined(RNG_CR_CED)
  60. /**
  61. * @brief LL RNG Init Structure Definition
  62. */
  63. typedef struct
  64. {
  65. uint32_t ClockErrorDetection; /*!< Clock error detection.
  66. This parameter can be one value of @ref RNG_LL_CED.
  67. This parameter can be modified using unitary functions @ref LL_RNG_EnableClkErrorDetect(). */
  68. }LL_RNG_InitTypeDef;
  69. #endif /* defined(RNG_CR_CED) */
  70. /**
  71. * @}
  72. */
  73. #endif /* USE_FULL_LL_DRIVER */
  74. /* Exported constants --------------------------------------------------------*/
  75. /** @defgroup RNG_LL_Exported_Constants RNG Exported Constants
  76. * @{
  77. */
  78. #if defined(RNG_CR_CED)
  79. /** @defgroup RNG_LL_CED Clock Error Detection
  80. * @{
  81. */
  82. #define LL_RNG_CED_ENABLE 0x00000000U /*!< Clock error detection enabled */
  83. #define LL_RNG_CED_DISABLE RNG_CR_CED /*!< Clock error detection disabled */
  84. /**
  85. * @}
  86. */
  87. #endif /* defined(RNG_CR_CED) */
  88. /** @defgroup RNG_LL_EC_GET_FLAG Get Flags Defines
  89. * @brief Flags defines which can be used with LL_RNG_ReadReg function
  90. * @{
  91. */
  92. #define LL_RNG_SR_DRDY RNG_SR_DRDY /*!< Register contains valid random data */
  93. #define LL_RNG_SR_CECS RNG_SR_CECS /*!< Clock error current status */
  94. #define LL_RNG_SR_SECS RNG_SR_SECS /*!< Seed error current status */
  95. #define LL_RNG_SR_CEIS RNG_SR_CEIS /*!< Clock error interrupt status */
  96. #define LL_RNG_SR_SEIS RNG_SR_SEIS /*!< Seed error interrupt status */
  97. /**
  98. * @}
  99. */
  100. /** @defgroup RNG_LL_EC_IT IT Defines
  101. * @brief IT defines which can be used with LL_RNG_ReadReg and LL_RNG_WriteReg macros
  102. * @{
  103. */
  104. #define LL_RNG_CR_IE RNG_CR_IE /*!< RNG Interrupt enable */
  105. /**
  106. * @}
  107. */
  108. /**
  109. * @}
  110. */
  111. /* Exported macro ------------------------------------------------------------*/
  112. /** @defgroup RNG_LL_Exported_Macros RNG Exported Macros
  113. * @{
  114. */
  115. /** @defgroup RNG_LL_EM_WRITE_READ Common Write and read registers Macros
  116. * @{
  117. */
  118. /**
  119. * @brief Write a value in RNG register
  120. * @param __INSTANCE__ RNG Instance
  121. * @param __REG__ Register to be written
  122. * @param __VALUE__ Value to be written in the register
  123. * @retval None
  124. */
  125. #define LL_RNG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  126. /**
  127. * @brief Read a value in RNG register
  128. * @param __INSTANCE__ RNG Instance
  129. * @param __REG__ Register to be read
  130. * @retval Register value
  131. */
  132. #define LL_RNG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  133. /**
  134. * @}
  135. */
  136. /**
  137. * @}
  138. */
  139. /* Exported functions --------------------------------------------------------*/
  140. /** @defgroup RNG_LL_Exported_Functions RNG Exported Functions
  141. * @{
  142. */
  143. /** @defgroup RNG_LL_EF_Configuration RNG Configuration functions
  144. * @{
  145. */
  146. /**
  147. * @brief Enable Random Number Generation
  148. * @rmtoll CR RNGEN LL_RNG_Enable
  149. * @param RNGx RNG Instance
  150. * @retval None
  151. */
  152. __STATIC_INLINE void LL_RNG_Enable(RNG_TypeDef *RNGx)
  153. {
  154. SET_BIT(RNGx->CR, RNG_CR_RNGEN);
  155. }
  156. /**
  157. * @brief Disable Random Number Generation
  158. * @rmtoll CR RNGEN LL_RNG_Disable
  159. * @param RNGx RNG Instance
  160. * @retval None
  161. */
  162. __STATIC_INLINE void LL_RNG_Disable(RNG_TypeDef *RNGx)
  163. {
  164. CLEAR_BIT(RNGx->CR, RNG_CR_RNGEN);
  165. }
  166. /**
  167. * @brief Check if Random Number Generator is enabled
  168. * @rmtoll CR RNGEN LL_RNG_IsEnabled
  169. * @param RNGx RNG Instance
  170. * @retval State of bit (1 or 0).
  171. */
  172. __STATIC_INLINE uint32_t LL_RNG_IsEnabled(RNG_TypeDef *RNGx)
  173. {
  174. return (READ_BIT(RNGx->CR, RNG_CR_RNGEN) == (RNG_CR_RNGEN));
  175. }
  176. #if defined(RNG_CR_CED)
  177. /**
  178. * @brief Enable RNG Clock Error Detection
  179. * @rmtoll CR CED LL_RNG_EnableClkErrorDetect
  180. * @param RNGx RNG Instance
  181. * @retval None
  182. */
  183. __STATIC_INLINE void LL_RNG_EnableClkErrorDetect(RNG_TypeDef *RNGx)
  184. {
  185. CLEAR_BIT(RNGx->CR, RNG_CR_CED);
  186. }
  187. /**
  188. * @brief Disable RNG Clock Error Detection
  189. * @rmtoll CR CED LL_RNG_DisableClkErrorDetect
  190. * @param RNGx RNG Instance
  191. * @retval None
  192. */
  193. __STATIC_INLINE void LL_RNG_DisableClkErrorDetect(RNG_TypeDef *RNGx)
  194. {
  195. SET_BIT(RNGx->CR, RNG_CR_CED);
  196. }
  197. /**
  198. * @brief Check if RNG Clock Error Detection is enabled
  199. * @rmtoll CR CED LL_RNG_IsEnabledClkErrorDetect
  200. * @param RNGx RNG Instance
  201. * @retval State of bit (1 or 0).
  202. */
  203. __STATIC_INLINE uint32_t LL_RNG_IsEnabledClkErrorDetect(RNG_TypeDef *RNGx)
  204. {
  205. return (!(READ_BIT(RNGx->CR, RNG_CR_CED) == (RNG_CR_CED)));
  206. }
  207. #endif /* defined(RNG_CR_CED) */
  208. /**
  209. * @}
  210. */
  211. /** @defgroup RNG_LL_EF_FLAG_Management FLAG Management
  212. * @{
  213. */
  214. /**
  215. * @brief Indicate if the RNG Data ready Flag is set or not
  216. * @rmtoll SR DRDY LL_RNG_IsActiveFlag_DRDY
  217. * @param RNGx RNG Instance
  218. * @retval State of bit (1 or 0).
  219. */
  220. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_DRDY(RNG_TypeDef *RNGx)
  221. {
  222. return (READ_BIT(RNGx->SR, RNG_SR_DRDY) == (RNG_SR_DRDY));
  223. }
  224. /**
  225. * @brief Indicate if the Clock Error Current Status Flag is set or not
  226. * @rmtoll SR CECS LL_RNG_IsActiveFlag_CECS
  227. * @param RNGx RNG Instance
  228. * @retval State of bit (1 or 0).
  229. */
  230. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_CECS(RNG_TypeDef *RNGx)
  231. {
  232. return (READ_BIT(RNGx->SR, RNG_SR_CECS) == (RNG_SR_CECS));
  233. }
  234. /**
  235. * @brief Indicate if the Seed Error Current Status Flag is set or not
  236. * @rmtoll SR SECS LL_RNG_IsActiveFlag_SECS
  237. * @param RNGx RNG Instance
  238. * @retval State of bit (1 or 0).
  239. */
  240. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_SECS(RNG_TypeDef *RNGx)
  241. {
  242. return (READ_BIT(RNGx->SR, RNG_SR_SECS) == (RNG_SR_SECS));
  243. }
  244. /**
  245. * @brief Indicate if the Clock Error Interrupt Status Flag is set or not
  246. * @rmtoll SR CEIS LL_RNG_IsActiveFlag_CEIS
  247. * @param RNGx RNG Instance
  248. * @retval State of bit (1 or 0).
  249. */
  250. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_CEIS(RNG_TypeDef *RNGx)
  251. {
  252. return (READ_BIT(RNGx->SR, RNG_SR_CEIS) == (RNG_SR_CEIS));
  253. }
  254. /**
  255. * @brief Indicate if the Seed Error Interrupt Status Flag is set or not
  256. * @rmtoll SR SEIS LL_RNG_IsActiveFlag_SEIS
  257. * @param RNGx RNG Instance
  258. * @retval State of bit (1 or 0).
  259. */
  260. __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_SEIS(RNG_TypeDef *RNGx)
  261. {
  262. return (READ_BIT(RNGx->SR, RNG_SR_SEIS) == (RNG_SR_SEIS));
  263. }
  264. /**
  265. * @brief Clear Clock Error interrupt Status (CEIS) Flag
  266. * @rmtoll SR CEIS LL_RNG_ClearFlag_CEIS
  267. * @param RNGx RNG Instance
  268. * @retval None
  269. */
  270. __STATIC_INLINE void LL_RNG_ClearFlag_CEIS(RNG_TypeDef *RNGx)
  271. {
  272. WRITE_REG(RNGx->SR, ~RNG_SR_CEIS);
  273. }
  274. /**
  275. * @brief Clear Seed Error interrupt Status (SEIS) Flag
  276. * @rmtoll SR SEIS LL_RNG_ClearFlag_SEIS
  277. * @param RNGx RNG Instance
  278. * @retval None
  279. */
  280. __STATIC_INLINE void LL_RNG_ClearFlag_SEIS(RNG_TypeDef *RNGx)
  281. {
  282. WRITE_REG(RNGx->SR, ~RNG_SR_SEIS);
  283. }
  284. /**
  285. * @}
  286. */
  287. /** @defgroup RNG_LL_EF_IT_Management IT Management
  288. * @{
  289. */
  290. /**
  291. * @brief Enable Random Number Generator Interrupt
  292. * (applies for either Seed error, Clock Error or Data ready interrupts)
  293. * @rmtoll CR IE LL_RNG_EnableIT
  294. * @param RNGx RNG Instance
  295. * @retval None
  296. */
  297. __STATIC_INLINE void LL_RNG_EnableIT(RNG_TypeDef *RNGx)
  298. {
  299. SET_BIT(RNGx->CR, RNG_CR_IE);
  300. }
  301. /**
  302. * @brief Disable Random Number Generator Interrupt
  303. * (applies for either Seed error, Clock Error or Data ready interrupts)
  304. * @rmtoll CR IE LL_RNG_DisableIT
  305. * @param RNGx RNG Instance
  306. * @retval None
  307. */
  308. __STATIC_INLINE void LL_RNG_DisableIT(RNG_TypeDef *RNGx)
  309. {
  310. CLEAR_BIT(RNGx->CR, RNG_CR_IE);
  311. }
  312. /**
  313. * @brief Check if Random Number Generator Interrupt is enabled
  314. * (applies for either Seed error, Clock Error or Data ready interrupts)
  315. * @rmtoll CR IE LL_RNG_IsEnabledIT
  316. * @param RNGx RNG Instance
  317. * @retval State of bit (1 or 0).
  318. */
  319. __STATIC_INLINE uint32_t LL_RNG_IsEnabledIT(RNG_TypeDef *RNGx)
  320. {
  321. return (READ_BIT(RNGx->CR, RNG_CR_IE) == (RNG_CR_IE));
  322. }
  323. /**
  324. * @}
  325. */
  326. /** @defgroup RNG_LL_EF_Data_Management Data Management
  327. * @{
  328. */
  329. /**
  330. * @brief Return32-bit Random Number value
  331. * @rmtoll DR RNDATA LL_RNG_ReadRandData32
  332. * @param RNGx RNG Instance
  333. * @retval Generated 32-bit random value
  334. */
  335. __STATIC_INLINE uint32_t LL_RNG_ReadRandData32(RNG_TypeDef *RNGx)
  336. {
  337. return (uint32_t)(READ_REG(RNGx->DR));
  338. }
  339. /**
  340. * @}
  341. */
  342. #if defined(USE_FULL_LL_DRIVER)
  343. /** @defgroup RNG_LL_EF_Init Initialization and de-initialization functions
  344. * @{
  345. */
  346. #if defined(RNG_CR_CED)
  347. ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct);
  348. void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct);
  349. #endif /* defined(RNG_CR_CED) */
  350. ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx);
  351. /**
  352. * @}
  353. */
  354. #endif /* USE_FULL_LL_DRIVER */
  355. /**
  356. * @}
  357. */
  358. /**
  359. * @}
  360. */
  361. #endif /* defined(RNG) */
  362. /**
  363. * @}
  364. */
  365. #ifdef __cplusplus
  366. }
  367. #endif
  368. #endif /* __STM32L4xx_LL_RNG_H */
  369. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/