stm32h7xx_hal_rng.h 11 KB

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