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.
 
 
 

359 lines
10 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_rng.h
  4. * @author MCD Application Team
  5. * @version V1.2.2
  6. * @date 14-April-2017
  7. * @brief Header file of RNG HAL 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 __STM32F7xx_HAL_RNG_H
  39. #define __STM32F7xx_HAL_RNG_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. /** @addtogroup STM32F7xx_HAL_Driver
  46. * @{
  47. */
  48. /** @defgroup RNG RNG
  49. * @brief RNG HAL module driver
  50. * @{
  51. */
  52. /* Exported types ------------------------------------------------------------*/
  53. /** @defgroup RNG_Exported_Types RNG Exported Types
  54. * @{
  55. */
  56. /** @defgroup RNG_Exported_Types_Group1 RNG State Structure definition
  57. * @{
  58. */
  59. typedef enum
  60. {
  61. HAL_RNG_STATE_RESET = 0x00U, /*!< RNG not yet initialized or disabled */
  62. HAL_RNG_STATE_READY = 0x01U, /*!< RNG initialized and ready for use */
  63. HAL_RNG_STATE_BUSY = 0x02U, /*!< RNG internal process is ongoing */
  64. HAL_RNG_STATE_TIMEOUT = 0x03U, /*!< RNG timeout state */
  65. HAL_RNG_STATE_ERROR = 0x04U /*!< RNG error state */
  66. }HAL_RNG_StateTypeDef;
  67. /**
  68. * @}
  69. */
  70. /** @defgroup RNG_Exported_Types_Group2 RNG Handle Structure definition
  71. * @{
  72. */
  73. typedef struct
  74. {
  75. RNG_TypeDef *Instance; /*!< Register base address */
  76. uint32_t RandomNumber; /*!< Last Generated random number */
  77. HAL_LockTypeDef Lock; /*!< RNG locking object */
  78. __IO HAL_RNG_StateTypeDef State; /*!< RNG communication state */
  79. }RNG_HandleTypeDef;
  80. /**
  81. * @}
  82. */
  83. /**
  84. * @}
  85. */
  86. /* Exported constants --------------------------------------------------------*/
  87. /** @defgroup RNG_Exported_Constants RNG Exported Constants
  88. * @{
  89. */
  90. /** @defgroup RNG_Exported_Constants_Group1 RNG Interrupt definition
  91. * @{
  92. */
  93. #define RNG_IT_DRDY RNG_SR_DRDY /*!< Data Ready interrupt */
  94. #define RNG_IT_CEI RNG_SR_CEIS /*!< Clock error interrupt */
  95. #define RNG_IT_SEI RNG_SR_SEIS /*!< Seed error interrupt */
  96. /**
  97. * @}
  98. */
  99. /** @defgroup RNG_Exported_Constants_Group2 RNG Flag definition
  100. * @{
  101. */
  102. #define RNG_FLAG_DRDY RNG_SR_DRDY /*!< Data ready */
  103. #define RNG_FLAG_CECS RNG_SR_CECS /*!< Clock error current status */
  104. #define RNG_FLAG_SECS RNG_SR_SECS /*!< Seed error current status */
  105. /**
  106. * @}
  107. */
  108. /**
  109. * @}
  110. */
  111. /* Exported macros -----------------------------------------------------------*/
  112. /** @defgroup RNG_Exported_Macros RNG Exported Macros
  113. * @{
  114. */
  115. /** @brief Reset RNG handle state
  116. * @param __HANDLE__: RNG Handle
  117. * @retval None
  118. */
  119. #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET)
  120. /**
  121. * @brief Enables the RNG peripheral.
  122. * @param __HANDLE__: RNG Handle
  123. * @retval None
  124. */
  125. #define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN)
  126. /**
  127. * @brief Disables the RNG peripheral.
  128. * @param __HANDLE__: RNG Handle
  129. * @retval None
  130. */
  131. #define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN)
  132. /**
  133. * @brief Check the selected RNG flag status.
  134. * @param __HANDLE__: RNG Handle
  135. * @param __FLAG__: RNG flag
  136. * This parameter can be one of the following values:
  137. * @arg RNG_FLAG_DRDY: Data ready
  138. * @arg RNG_FLAG_CECS: Clock error current status
  139. * @arg RNG_FLAG_SECS: Seed error current status
  140. * @retval The new state of __FLAG__ (SET or RESET).
  141. */
  142. #define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
  143. /**
  144. * @brief Clears the selected RNG flag status.
  145. * @param __HANDLE__: RNG handle
  146. * @param __FLAG__: RNG flag to clear
  147. * @note WARNING: This is a dummy macro for HAL code alignment,
  148. * flags RNG_FLAG_DRDY, RNG_FLAG_CECS and RNG_FLAG_SECS are read-only.
  149. * @retval None
  150. */
  151. #define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) /* dummy macro */
  152. /**
  153. * @brief Enables the RNG interrupts.
  154. * @param __HANDLE__: RNG Handle
  155. * @retval None
  156. */
  157. #define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE)
  158. /**
  159. * @brief Disables the RNG interrupts.
  160. * @param __HANDLE__: RNG Handle
  161. * @retval None
  162. */
  163. #define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE)
  164. /**
  165. * @brief Checks whether the specified RNG interrupt has occurred or not.
  166. * @param __HANDLE__: RNG Handle
  167. * @param __INTERRUPT__: specifies the RNG interrupt status flag to check.
  168. * This parameter can be one of the following values:
  169. * @arg RNG_IT_DRDY: Data ready interrupt
  170. * @arg RNG_IT_CEI: Clock error interrupt
  171. * @arg RNG_IT_SEI: Seed error interrupt
  172. * @retval The new state of __INTERRUPT__ (SET or RESET).
  173. */
  174. #define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))
  175. /**
  176. * @brief Clear the RNG interrupt status flags.
  177. * @param __HANDLE__: RNG Handle
  178. * @param __INTERRUPT__: specifies the RNG interrupt status flag to clear.
  179. * This parameter can be one of the following values:
  180. * @arg RNG_IT_CEI: Clock error interrupt
  181. * @arg RNG_IT_SEI: Seed error interrupt
  182. * @note RNG_IT_DRDY flag is read-only, reading RNG_DR register automatically clears RNG_IT_DRDY.
  183. * @retval None
  184. */
  185. #define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__))
  186. /**
  187. * @}
  188. */
  189. /* Exported functions --------------------------------------------------------*/
  190. /** @defgroup RNG_Exported_Functions RNG Exported Functions
  191. * @{
  192. */
  193. /** @defgroup RNG_Exported_Functions_Group1 Initialization and de-initialization functions
  194. * @{
  195. */
  196. HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng);
  197. HAL_StatusTypeDef HAL_RNG_DeInit (RNG_HandleTypeDef *hrng);
  198. void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng);
  199. void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng);
  200. /**
  201. * @}
  202. */
  203. /** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions
  204. * @{
  205. */
  206. uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber() instead */
  207. uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber_IT() instead */
  208. HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit);
  209. HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng);
  210. uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef *hrng);
  211. void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng);
  212. void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng);
  213. void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef* hrng, uint32_t random32bit);
  214. /**
  215. * @}
  216. */
  217. /** @defgroup RNG_Exported_Functions_Group3 Peripheral State functions
  218. * @{
  219. */
  220. HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng);
  221. /**
  222. * @}
  223. */
  224. /**
  225. * @}
  226. */
  227. /* Private types -------------------------------------------------------------*/
  228. /** @defgroup RNG_Private_Types RNG Private Types
  229. * @{
  230. */
  231. /**
  232. * @}
  233. */
  234. /* Private defines -----------------------------------------------------------*/
  235. /** @defgroup RNG_Private_Defines RNG Private Defines
  236. * @{
  237. */
  238. /**
  239. * @}
  240. */
  241. /* Private variables ---------------------------------------------------------*/
  242. /** @defgroup RNG_Private_Variables RNG Private Variables
  243. * @{
  244. */
  245. /**
  246. * @}
  247. */
  248. /* Private constants ---------------------------------------------------------*/
  249. /** @defgroup RNG_Private_Constants RNG Private Constants
  250. * @{
  251. */
  252. /**
  253. * @}
  254. */
  255. /* Private macros ------------------------------------------------------------*/
  256. /** @defgroup RNG_Private_Macros RNG Private Macros
  257. * @{
  258. */
  259. #define IS_RNG_IT(IT) (((IT) == RNG_IT_CEI) || \
  260. ((IT) == RNG_IT_SEI))
  261. #define IS_RNG_FLAG(FLAG) (((FLAG) == RNG_FLAG_DRDY) || \
  262. ((FLAG) == RNG_FLAG_CECS) || \
  263. ((FLAG) == RNG_FLAG_SECS))
  264. /**
  265. * @}
  266. */
  267. /* Private functions prototypes ----------------------------------------------*/
  268. /** @defgroup RNG_Private_Functions_Prototypes RNG Private Functions Prototypes
  269. * @{
  270. */
  271. /**
  272. * @}
  273. */
  274. /* Private functions ---------------------------------------------------------*/
  275. /** @defgroup RNG_Private_Functions RNG Private Functions
  276. * @{
  277. */
  278. /**
  279. * @}
  280. */
  281. /**
  282. * @}
  283. */
  284. /**
  285. * @}
  286. */
  287. #ifdef __cplusplus
  288. }
  289. #endif
  290. #endif /* __STM32F7xx_HAL_RNG_H */
  291. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/