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.
 
 
 

381 lines
12 KiB

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