stm32f4xx_hal_rng.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_rng.h
  4. * @author MCD Application Team
  5. * @brief Header file of RNG HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 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 STM32F4xx_HAL_RNG_H
  21. #define STM32F4xx_HAL_RNG_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f4xx_hal_def.h"
  27. /** @addtogroup STM32F4xx_HAL_Driver
  28. * @{
  29. */
  30. #if defined (RNG)
  31. /** @defgroup RNG RNG
  32. * @brief RNG HAL module driver
  33. * @{
  34. */
  35. /* Exported types ------------------------------------------------------------*/
  36. /** @defgroup RNG_Exported_Types RNG Exported Types
  37. * @{
  38. */
  39. /** @defgroup RNG_Exported_Types_Group1 RNG Init Structure definition
  40. * @{
  41. */
  42. /**
  43. * @}
  44. */
  45. /** @defgroup RNG_Exported_Types_Group2 RNG State Structure definition
  46. * @{
  47. */
  48. typedef enum
  49. {
  50. HAL_RNG_STATE_RESET = 0x00U, /*!< RNG not yet initialized or disabled */
  51. HAL_RNG_STATE_READY = 0x01U, /*!< RNG initialized and ready for use */
  52. HAL_RNG_STATE_BUSY = 0x02U, /*!< RNG internal process is ongoing */
  53. HAL_RNG_STATE_TIMEOUT = 0x03U, /*!< RNG timeout state */
  54. HAL_RNG_STATE_ERROR = 0x04U /*!< RNG error state */
  55. } HAL_RNG_StateTypeDef;
  56. /**
  57. * @}
  58. */
  59. /** @defgroup RNG_Exported_Types_Group3 RNG Handle Structure definition
  60. * @{
  61. */
  62. #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
  63. typedef struct __RNG_HandleTypeDef
  64. #else
  65. typedef struct
  66. #endif /* (USE_HAL_RNG_REGISTER_CALLBACKS) */
  67. {
  68. RNG_TypeDef *Instance; /*!< Register base address */
  69. HAL_LockTypeDef Lock; /*!< RNG locking object */
  70. __IO HAL_RNG_StateTypeDef State; /*!< RNG communication state */
  71. __IO uint32_t ErrorCode; /*!< RNG Error code */
  72. uint32_t RandomNumber; /*!< Last Generated RNG Data */
  73. #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
  74. void (* ReadyDataCallback)(struct __RNG_HandleTypeDef *hrng, uint32_t random32bit); /*!< RNG Data Ready Callback */
  75. void (* ErrorCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Error Callback */
  76. void (* MspInitCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Msp Init callback */
  77. void (* MspDeInitCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Msp DeInit callback */
  78. #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
  79. } RNG_HandleTypeDef;
  80. #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
  81. /**
  82. * @brief HAL RNG Callback ID enumeration definition
  83. */
  84. typedef enum
  85. {
  86. HAL_RNG_ERROR_CB_ID = 0x00U, /*!< RNG Error Callback ID */
  87. HAL_RNG_MSPINIT_CB_ID = 0x01U, /*!< RNG MspInit callback ID */
  88. HAL_RNG_MSPDEINIT_CB_ID = 0x02U /*!< RNG MspDeInit callback ID */
  89. } HAL_RNG_CallbackIDTypeDef;
  90. /**
  91. * @brief HAL RNG Callback pointer definition
  92. */
  93. typedef void (*pRNG_CallbackTypeDef)(RNG_HandleTypeDef *hrng); /*!< pointer to a common RNG callback function */
  94. typedef void (*pRNG_ReadyDataCallbackTypeDef)(RNG_HandleTypeDef *hrng, uint32_t random32bit); /*!< pointer to an RNG Data Ready specific callback function */
  95. #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
  96. /**
  97. * @}
  98. */
  99. /**
  100. * @}
  101. */
  102. /* Exported constants --------------------------------------------------------*/
  103. /** @defgroup RNG_Exported_Constants RNG Exported Constants
  104. * @{
  105. */
  106. /** @defgroup RNG_Exported_Constants_Group1 RNG Interrupt definition
  107. * @{
  108. */
  109. #define RNG_IT_DRDY RNG_SR_DRDY /*!< Data Ready interrupt */
  110. #define RNG_IT_CEI RNG_SR_CEIS /*!< Clock error interrupt */
  111. #define RNG_IT_SEI RNG_SR_SEIS /*!< Seed error interrupt */
  112. /**
  113. * @}
  114. */
  115. /** @defgroup RNG_Exported_Constants_Group2 RNG Flag definition
  116. * @{
  117. */
  118. #define RNG_FLAG_DRDY RNG_SR_DRDY /*!< Data ready */
  119. #define RNG_FLAG_CECS RNG_SR_CECS /*!< Clock error current status */
  120. #define RNG_FLAG_SECS RNG_SR_SECS /*!< Seed error current status */
  121. /**
  122. * @}
  123. */
  124. /** @defgroup RNG_Error_Definition RNG Error Definition
  125. * @{
  126. */
  127. #define HAL_RNG_ERROR_NONE 0x00000000U /*!< No error */
  128. #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
  129. #define HAL_RNG_ERROR_INVALID_CALLBACK 0x00000001U /*!< Invalid Callback error */
  130. #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
  131. #define HAL_RNG_ERROR_TIMEOUT 0x00000002U /*!< Timeout error */
  132. #define HAL_RNG_ERROR_BUSY 0x00000004U /*!< Busy error */
  133. #define HAL_RNG_ERROR_SEED 0x00000008U /*!< Seed error */
  134. #define HAL_RNG_ERROR_CLOCK 0x00000010U /*!< Clock error */
  135. /**
  136. * @}
  137. */
  138. /**
  139. * @}
  140. */
  141. /* Exported macros -----------------------------------------------------------*/
  142. /** @defgroup RNG_Exported_Macros RNG Exported Macros
  143. * @{
  144. */
  145. /** @brief Reset RNG handle state
  146. * @param __HANDLE__ RNG Handle
  147. * @retval None
  148. */
  149. #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
  150. #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) do{ \
  151. (__HANDLE__)->State = HAL_RNG_STATE_RESET; \
  152. (__HANDLE__)->MspInitCallback = NULL; \
  153. (__HANDLE__)->MspDeInitCallback = NULL; \
  154. } while(0U)
  155. #else
  156. #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET)
  157. #endif /*USE_HAL_RNG_REGISTER_CALLBACKS */
  158. /**
  159. * @brief Enables the RNG peripheral.
  160. * @param __HANDLE__ RNG Handle
  161. * @retval None
  162. */
  163. #define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN)
  164. /**
  165. * @brief Disables the RNG peripheral.
  166. * @param __HANDLE__ RNG Handle
  167. * @retval None
  168. */
  169. #define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN)
  170. /**
  171. * @brief Check the selected RNG flag status.
  172. * @param __HANDLE__ RNG Handle
  173. * @param __FLAG__ RNG flag
  174. * This parameter can be one of the following values:
  175. * @arg RNG_FLAG_DRDY: Data ready
  176. * @arg RNG_FLAG_CECS: Clock error current status
  177. * @arg RNG_FLAG_SECS: Seed error current status
  178. * @retval The new state of __FLAG__ (SET or RESET).
  179. */
  180. #define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
  181. /**
  182. * @brief Clears the selected RNG flag status.
  183. * @param __HANDLE__ RNG handle
  184. * @param __FLAG__ RNG flag to clear
  185. * @note WARNING: This is a dummy macro for HAL code alignment,
  186. * flags RNG_FLAG_DRDY, RNG_FLAG_CECS and RNG_FLAG_SECS are read-only.
  187. * @retval None
  188. */
  189. #define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) /* dummy macro */
  190. /**
  191. * @brief Enables the RNG interrupts.
  192. * @param __HANDLE__ RNG Handle
  193. * @retval None
  194. */
  195. #define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE)
  196. /**
  197. * @brief Disables the RNG interrupts.
  198. * @param __HANDLE__ RNG Handle
  199. * @retval None
  200. */
  201. #define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE)
  202. /**
  203. * @brief Checks whether the specified RNG interrupt has occurred or not.
  204. * @param __HANDLE__ RNG Handle
  205. * @param __INTERRUPT__ specifies the RNG interrupt status flag to check.
  206. * This parameter can be one of the following values:
  207. * @arg RNG_IT_DRDY: Data ready interrupt
  208. * @arg RNG_IT_CEI: Clock error interrupt
  209. * @arg RNG_IT_SEI: Seed error interrupt
  210. * @retval The new state of __INTERRUPT__ (SET or RESET).
  211. */
  212. #define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))
  213. /**
  214. * @brief Clear the RNG interrupt status flags.
  215. * @param __HANDLE__ RNG Handle
  216. * @param __INTERRUPT__ specifies the RNG interrupt status flag to clear.
  217. * This parameter can be one of the following values:
  218. * @arg RNG_IT_CEI: Clock error interrupt
  219. * @arg RNG_IT_SEI: Seed error interrupt
  220. * @note RNG_IT_DRDY flag is read-only, reading RNG_DR register automatically clears RNG_IT_DRDY.
  221. * @retval None
  222. */
  223. #define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__))
  224. /**
  225. * @}
  226. */
  227. /* Exported functions --------------------------------------------------------*/
  228. /** @defgroup RNG_Exported_Functions RNG Exported Functions
  229. * @{
  230. */
  231. /** @defgroup RNG_Exported_Functions_Group1 Initialization and configuration functions
  232. * @{
  233. */
  234. HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng);
  235. HAL_StatusTypeDef HAL_RNG_DeInit(RNG_HandleTypeDef *hrng);
  236. void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng);
  237. void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng);
  238. /* Callbacks Register/UnRegister functions ***********************************/
  239. #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
  240. HAL_StatusTypeDef HAL_RNG_RegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID, pRNG_CallbackTypeDef pCallback);
  241. HAL_StatusTypeDef HAL_RNG_UnRegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID);
  242. HAL_StatusTypeDef HAL_RNG_RegisterReadyDataCallback(RNG_HandleTypeDef *hrng, pRNG_ReadyDataCallbackTypeDef pCallback);
  243. HAL_StatusTypeDef HAL_RNG_UnRegisterReadyDataCallback(RNG_HandleTypeDef *hrng);
  244. #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
  245. /**
  246. * @}
  247. */
  248. /** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions
  249. * @{
  250. */
  251. uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber() instead */
  252. uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber_IT() instead */
  253. HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit);
  254. HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng);
  255. uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef *hrng);
  256. void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng);
  257. void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng);
  258. void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef *hrng, uint32_t random32bit);
  259. /**
  260. * @}
  261. */
  262. /** @defgroup RNG_Exported_Functions_Group3 Peripheral State functions
  263. * @{
  264. */
  265. HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng);
  266. uint32_t HAL_RNG_GetError(RNG_HandleTypeDef *hrng);
  267. /**
  268. * @}
  269. */
  270. /**
  271. * @}
  272. */
  273. /* Private macros ------------------------------------------------------------*/
  274. /** @defgroup RNG_Private_Macros RNG Private Macros
  275. * @{
  276. */
  277. #define IS_RNG_IT(IT) (((IT) == RNG_IT_CEI) || \
  278. ((IT) == RNG_IT_SEI))
  279. #define IS_RNG_FLAG(FLAG) (((FLAG) == RNG_FLAG_DRDY) || \
  280. ((FLAG) == RNG_FLAG_CECS) || \
  281. ((FLAG) == RNG_FLAG_SECS))
  282. /**
  283. * @}
  284. */
  285. /**
  286. * @}
  287. */
  288. #endif /* RNG */
  289. /**
  290. * @}
  291. */
  292. #ifdef __cplusplus
  293. }
  294. #endif
  295. #endif /* STM32F4xx_HAL_RNG_H */
  296. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/