You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

402 lines
10 KiB

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