stm32f4xx_hal_rng.h 12 KB

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