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.
 
 
 

286 lines
9.6 KiB

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