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.
 
 
 

379 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. /**
  146. * @}
  147. */
  148. /**
  149. * @}
  150. */
  151. /* Exported macros -----------------------------------------------------------*/
  152. /** @defgroup RNG_Exported_Macros RNG Exported Macros
  153. * @{
  154. */
  155. /** @brief Reset RNG handle state
  156. * @param __HANDLE__ RNG Handle
  157. * @retval None
  158. */
  159. #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
  160. #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) do{ \
  161. (__HANDLE__)->State = HAL_RNG_STATE_RESET; \
  162. (__HANDLE__)->MspInitCallback = NULL; \
  163. (__HANDLE__)->MspDeInitCallback = NULL; \
  164. } while(0U)
  165. #else
  166. #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET)
  167. #endif /*USE_HAL_RNG_REGISTER_CALLBACKS */
  168. /**
  169. * @brief Enables the RNG peripheral.
  170. * @param __HANDLE__ RNG Handle
  171. * @retval None
  172. */
  173. #define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN)
  174. /**
  175. * @brief Disables the RNG peripheral.
  176. * @param __HANDLE__ RNG Handle
  177. * @retval None
  178. */
  179. #define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN)
  180. /**
  181. * @brief Check the selected RNG flag status.
  182. * @param __HANDLE__ RNG Handle
  183. * @param __FLAG__ RNG flag
  184. * This parameter can be one of the following values:
  185. * @arg RNG_FLAG_DRDY: Data ready
  186. * @arg RNG_FLAG_CECS: Clock error current status
  187. * @arg RNG_FLAG_SECS: Seed error current status
  188. * @retval The new state of __FLAG__ (SET or RESET).
  189. */
  190. #define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
  191. /**
  192. * @brief Clears the selected RNG flag status.
  193. * @param __HANDLE__ RNG handle
  194. * @param __FLAG__ RNG flag to clear
  195. * @note WARNING: This is a dummy macro for HAL code alignment,
  196. * flags RNG_FLAG_DRDY, RNG_FLAG_CECS and RNG_FLAG_SECS are read-only.
  197. * @retval None
  198. */
  199. #define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) /* dummy macro */
  200. /**
  201. * @brief Enables the RNG interrupts.
  202. * @param __HANDLE__ RNG Handle
  203. * @retval None
  204. */
  205. #define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE)
  206. /**
  207. * @brief Disables the RNG interrupts.
  208. * @param __HANDLE__ RNG Handle
  209. * @retval None
  210. */
  211. #define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE)
  212. /**
  213. * @brief Checks whether the specified RNG interrupt has occurred or not.
  214. * @param __HANDLE__ RNG Handle
  215. * @param __INTERRUPT__ specifies the RNG interrupt status flag to check.
  216. * This parameter can be one of the following values:
  217. * @arg RNG_IT_DRDY: Data ready interrupt
  218. * @arg RNG_IT_CEI: Clock error interrupt
  219. * @arg RNG_IT_SEI: Seed error interrupt
  220. * @retval The new state of __INTERRUPT__ (SET or RESET).
  221. */
  222. #define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))
  223. /**
  224. * @brief Clear the RNG interrupt status flags.
  225. * @param __HANDLE__ RNG Handle
  226. * @param __INTERRUPT__ specifies the RNG interrupt status flag to clear.
  227. * This parameter can be one of the following values:
  228. * @arg RNG_IT_CEI: Clock error interrupt
  229. * @arg RNG_IT_SEI: Seed error interrupt
  230. * @note RNG_IT_DRDY flag is read-only, reading RNG_DR register automatically clears RNG_IT_DRDY.
  231. * @retval None
  232. */
  233. #define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__))
  234. /**
  235. * @}
  236. */
  237. /* Exported functions --------------------------------------------------------*/
  238. /** @defgroup RNG_Exported_Functions RNG Exported Functions
  239. * @{
  240. */
  241. /** @defgroup RNG_Exported_Functions_Group1 Initialization and configuration functions
  242. * @{
  243. */
  244. HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng);
  245. HAL_StatusTypeDef HAL_RNG_DeInit(RNG_HandleTypeDef *hrng);
  246. void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng);
  247. void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng);
  248. /* Callbacks Register/UnRegister functions ***********************************/
  249. #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
  250. HAL_StatusTypeDef HAL_RNG_RegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID, pRNG_CallbackTypeDef pCallback);
  251. HAL_StatusTypeDef HAL_RNG_UnRegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID);
  252. HAL_StatusTypeDef HAL_RNG_RegisterReadyDataCallback(RNG_HandleTypeDef *hrng, pRNG_ReadyDataCallbackTypeDef pCallback);
  253. HAL_StatusTypeDef HAL_RNG_UnRegisterReadyDataCallback(RNG_HandleTypeDef *hrng);
  254. #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
  255. /**
  256. * @}
  257. */
  258. /** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions
  259. * @{
  260. */
  261. HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit);
  262. HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng);
  263. uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef *hrng);
  264. void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng);
  265. void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng);
  266. void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef *hrng, uint32_t random32bit);
  267. /**
  268. * @}
  269. */
  270. /** @defgroup RNG_Exported_Functions_Group3 Peripheral State functions
  271. * @{
  272. */
  273. HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng);
  274. uint32_t HAL_RNG_GetError(RNG_HandleTypeDef *hrng);
  275. /**
  276. * @}
  277. */
  278. /**
  279. * @}
  280. */
  281. /* Private macros ------------------------------------------------------------*/
  282. /** @defgroup RNG_Private_Macros RNG Private Macros
  283. * @{
  284. */
  285. #define IS_RNG_IT(IT) (((IT) == RNG_IT_CEI) || \
  286. ((IT) == RNG_IT_SEI))
  287. #define IS_RNG_FLAG(FLAG) (((FLAG) == RNG_FLAG_DRDY) || \
  288. ((FLAG) == RNG_FLAG_CECS) || \
  289. ((FLAG) == RNG_FLAG_SECS))
  290. /**
  291. * @brief Verify the RNG Clock Error Detection mode.
  292. * @param __MODE__ RNG Clock Error Detection mode
  293. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  294. */
  295. #define IS_RNG_CED(__MODE__) (((__MODE__) == RNG_CED_ENABLE) || \
  296. ((__MODE__) == RNG_CED_DISABLE))
  297. /**
  298. * @}
  299. */
  300. /**
  301. * @}
  302. */
  303. #endif /* RNG */
  304. /**
  305. * @}
  306. */
  307. #ifdef __cplusplus
  308. }
  309. #endif
  310. #endif /* STM32WBxx_HAL_RNG_H */
  311. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/