stm32l0xx_hal_rng.h 12 KB

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