stm32l4xx_hal_rng.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_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) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32L4xx_HAL_RNG_H
  37. #define __STM32L4xx_HAL_RNG_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l4xx_hal_def.h"
  43. /** @addtogroup STM32L4xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup RNG
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup RNG_Exported_Types RNG Exported Types
  51. * @{
  52. */
  53. #if defined(RNG_CR_CED)
  54. /**
  55. * @brief RNG Configuration Structure definition
  56. */
  57. typedef struct
  58. {
  59. uint32_t ClockErrorDetection; /*!< Clock error detection */
  60. }RNG_InitTypeDef;
  61. #endif /* defined(RNG_CR_CED) */
  62. /**
  63. * @brief RNG HAL State Structure definition
  64. */
  65. typedef enum
  66. {
  67. HAL_RNG_STATE_RESET = 0x00, /*!< RNG not yet initialized or disabled */
  68. HAL_RNG_STATE_READY = 0x01, /*!< RNG initialized and ready for use */
  69. HAL_RNG_STATE_BUSY = 0x02, /*!< RNG internal process is ongoing */
  70. HAL_RNG_STATE_TIMEOUT = 0x03, /*!< RNG timeout state */
  71. HAL_RNG_STATE_ERROR = 0x04 /*!< RNG error state */
  72. }HAL_RNG_StateTypeDef;
  73. /**
  74. * @brief RNG Handle Structure definition
  75. */
  76. typedef struct
  77. {
  78. RNG_TypeDef *Instance; /*!< Register base address */
  79. #if defined(RNG_CR_CED)
  80. RNG_InitTypeDef Init; /*!< RNG configuration parameters */
  81. #endif /* defined(RNG_CR_CED) */
  82. HAL_LockTypeDef Lock; /*!< RNG locking object */
  83. __IO HAL_RNG_StateTypeDef State; /*!< RNG communication state */
  84. uint32_t RandomNumber; /*!< Last Generated RNG Data */
  85. }RNG_HandleTypeDef;
  86. /**
  87. * @}
  88. */
  89. /* Exported constants --------------------------------------------------------*/
  90. /** @defgroup RNG_Exported_Constants RNG Exported Constants
  91. * @{
  92. */
  93. /** @defgroup RNG_Interrupt_definition RNG Interrupts Definition
  94. * @{
  95. */
  96. #define RNG_IT_DRDY RNG_SR_DRDY /*!< Data Ready interrupt */
  97. #define RNG_IT_CEI RNG_SR_CEIS /*!< Clock error interrupt */
  98. #define RNG_IT_SEI RNG_SR_SEIS /*!< Seed error interrupt */
  99. /**
  100. * @}
  101. */
  102. /** @defgroup RNG_Flag_definition RNG Flags Definition
  103. * @{
  104. */
  105. #define RNG_FLAG_DRDY RNG_SR_DRDY /*!< Data ready */
  106. #define RNG_FLAG_CECS RNG_SR_CECS /*!< Clock error current status */
  107. #define RNG_FLAG_SECS RNG_SR_SECS /*!< Seed error current status */
  108. /**
  109. * @}
  110. */
  111. #if defined(RNG_CR_CED)
  112. /** @defgroup RNG_Clock_Error_Detection RNG Clock Error Detection
  113. * @{
  114. */
  115. #define RNG_CED_ENABLE ((uint32_t)0x00000000) /*!< Clock error detection enabled */
  116. #define RNG_CED_DISABLE RNG_CR_CED /*!< Clock error detection disabled */
  117. /**
  118. * @}
  119. */
  120. #endif /* defined(RNG_CR_CED) */
  121. /**
  122. * @}
  123. */
  124. /* Exported macros -----------------------------------------------------------*/
  125. /** @defgroup RNG_Exported_Macros RNG Exported Macros
  126. * @{
  127. */
  128. /** @brief Reset RNG handle state.
  129. * @param __HANDLE__: RNG Handle
  130. * @retval None
  131. */
  132. #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET)
  133. /**
  134. * @brief Enable the RNG peripheral.
  135. * @param __HANDLE__: RNG Handle
  136. * @retval None
  137. */
  138. #define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN)
  139. /**
  140. * @brief Disable the RNG peripheral.
  141. * @param __HANDLE__: RNG Handle
  142. * @retval None
  143. */
  144. #define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN)
  145. /**
  146. * @brief Check whether the specified RNG flag is set or not.
  147. * @param __HANDLE__: RNG Handle
  148. * @param __FLAG__: RNG flag
  149. * This parameter can be one of the following values:
  150. * @arg RNG_FLAG_DRDY: Data ready
  151. * @arg RNG_FLAG_CECS: Clock error current status
  152. * @arg RNG_FLAG_SECS: Seed error current status
  153. * @retval The new state of __FLAG__ (SET or RESET).
  154. */
  155. #define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
  156. /**
  157. * @brief Clear the selected RNG flag status.
  158. * @param __HANDLE__: RNG handle
  159. * @param __FLAG__: RNG flag to clear
  160. * @note WARNING: This is a dummy macro for HAL code alignment,
  161. * flags RNG_FLAG_DRDY, RNG_FLAG_CECS and RNG_FLAG_SECS are read-only.
  162. * @retval None
  163. */
  164. #define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) /* dummy macro */
  165. /**
  166. * @brief Enable the RNG interrupt.
  167. * @param __HANDLE__: RNG Handle
  168. * @retval None
  169. */
  170. #define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE)
  171. /**
  172. * @brief Disable the RNG interrupt.
  173. * @param __HANDLE__: RNG Handle
  174. * @retval None
  175. */
  176. #define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE)
  177. /**
  178. * @brief Check whether the specified RNG interrupt has occurred or not.
  179. * @param __HANDLE__: RNG Handle
  180. * @param __INTERRUPT__: specifies the RNG interrupt status flag to check.
  181. * This parameter can be one of the following values:
  182. * @arg RNG_IT_DRDY: Data ready interrupt
  183. * @arg RNG_IT_CEI: Clock error interrupt
  184. * @arg RNG_IT_SEI: Seed error interrupt
  185. * @retval The new state of __INTERRUPT__ (SET or RESET).
  186. */
  187. #define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))
  188. /**
  189. * @brief Clear the RNG interrupt status flags.
  190. * @param __HANDLE__: RNG Handle
  191. * @param __INTERRUPT__: specifies the RNG interrupt status flag to clear.
  192. * This parameter can be one of the following values:
  193. * @arg RNG_IT_CEI: Clock error interrupt
  194. * @arg RNG_IT_SEI: Seed error interrupt
  195. * @note RNG_IT_DRDY flag is read-only, reading RNG_DR register automatically clears RNG_IT_DRDY.
  196. * @retval None
  197. */
  198. #define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__))
  199. /**
  200. * @}
  201. */
  202. /* Exported functions --------------------------------------------------------*/
  203. /** @defgroup RNG_Exported_Functions RNG Exported Functions
  204. * @{
  205. */
  206. /* Initialization and de-initialization functions ******************************/
  207. /** @defgroup RNG_Exported_Functions_Group1 Initialization and de-initialization functions
  208. * @{
  209. */
  210. HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng);
  211. HAL_StatusTypeDef HAL_RNG_DeInit (RNG_HandleTypeDef *hrng);
  212. void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng);
  213. void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng);
  214. /**
  215. * @}
  216. */
  217. /* Peripheral Control functions ************************************************/
  218. /** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions
  219. * @{
  220. */
  221. uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber() instead */
  222. uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber_IT() instead */
  223. HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit);
  224. HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng);
  225. uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef *hrng);
  226. void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng);
  227. void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng);
  228. void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef* hrng, uint32_t random32bit);
  229. /**
  230. * @}
  231. */
  232. /* Peripheral State functions **************************************************/
  233. /** @defgroup RNG_Exported_Functions_Group3 Peripheral State functions
  234. * @{
  235. */
  236. HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng);
  237. /**
  238. * @}
  239. */
  240. /**
  241. * @}
  242. */
  243. /* Private types -------------------------------------------------------------*/
  244. /* Private defines -----------------------------------------------------------*/
  245. /* Private variables ---------------------------------------------------------*/
  246. /* Private constants ---------------------------------------------------------*/
  247. /* Private macros ------------------------------------------------------------*/
  248. /** @addtogroup RNG_Private_Macros RNG Private Macros
  249. * @{
  250. */
  251. #if defined(RNG_CR_CED)
  252. /**
  253. * @brief Verify the RNG Clock Error Detection mode.
  254. * @param __MODE__: RNG Clock Error Detection mode
  255. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  256. */
  257. #define IS_RNG_CED(__MODE__) (((__MODE__) == RNG_CED_ENABLE) || \
  258. ((__MODE__) == RNG_CED_DISABLE))
  259. #endif /* defined(RNG_CR_CED) */
  260. /**
  261. * @}
  262. */
  263. /* Private functions prototypes ----------------------------------------------*/
  264. /**
  265. * @}
  266. */
  267. /**
  268. * @}
  269. */
  270. #ifdef __cplusplus
  271. }
  272. #endif
  273. #endif /* __STM32L4xx_HAL_RNG_H */
  274. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/