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.
 
 
 

354 lines
11 KiB

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