2 ******************************************************************************
3 * @file stm32f7xx_hal_rng.h
4 * @author MCD Application Team
5 * @brief Header file of RNG HAL module.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
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
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32F7xx_HAL_RNG_H
22 #define STM32F7xx_HAL_RNG_H
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32f7xx_hal_def.h"
31 /** @addtogroup STM32F7xx_HAL_Driver
38 * @brief RNG HAL module driver
42 /* Exported types ------------------------------------------------------------*/
44 /** @defgroup RNG_Exported_Types RNG Exported Types
48 /** @defgroup RNG_Exported_Types_Group1 RNG Init Structure definition
56 /** @defgroup RNG_Exported_Types_Group2 RNG State Structure definition
61 HAL_RNG_STATE_RESET
= 0x00U
, /*!< RNG not yet initialized or disabled */
62 HAL_RNG_STATE_READY
= 0x01U
, /*!< RNG initialized and ready for use */
63 HAL_RNG_STATE_BUSY
= 0x02U
, /*!< RNG internal process is ongoing */
64 HAL_RNG_STATE_TIMEOUT
= 0x03U
, /*!< RNG timeout state */
65 HAL_RNG_STATE_ERROR
= 0x04U
/*!< RNG error state */
67 } HAL_RNG_StateTypeDef
;
73 /** @defgroup RNG_Exported_Types_Group3 RNG Handle Structure definition
76 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
77 typedef struct __RNG_HandleTypeDef
80 #endif /* (USE_HAL_RNG_REGISTER_CALLBACKS) */
82 RNG_TypeDef
*Instance
; /*!< Register base address */
84 HAL_LockTypeDef Lock
; /*!< RNG locking object */
86 __IO HAL_RNG_StateTypeDef State
; /*!< RNG communication state */
88 __IO
uint32_t ErrorCode
; /*!< RNG Error code */
90 uint32_t RandomNumber
; /*!< Last Generated RNG Data */
92 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
93 void (* ReadyDataCallback
)(struct __RNG_HandleTypeDef
*hrng
, uint32_t random32bit
); /*!< RNG Data Ready Callback */
94 void (* ErrorCallback
)(struct __RNG_HandleTypeDef
*hrng
); /*!< RNG Error Callback */
96 void (* MspInitCallback
)(struct __RNG_HandleTypeDef
*hrng
); /*!< RNG Msp Init callback */
97 void (* MspDeInitCallback
)(struct __RNG_HandleTypeDef
*hrng
); /*!< RNG Msp DeInit callback */
98 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
102 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
104 * @brief HAL RNG Callback ID enumeration definition
108 HAL_RNG_ERROR_CB_ID
= 0x00U
, /*!< RNG Error Callback ID */
110 HAL_RNG_MSPINIT_CB_ID
= 0x01U
, /*!< RNG MspInit callback ID */
111 HAL_RNG_MSPDEINIT_CB_ID
= 0x02U
/*!< RNG MspDeInit callback ID */
113 } HAL_RNG_CallbackIDTypeDef
;
116 * @brief HAL RNG Callback pointer definition
118 typedef void (*pRNG_CallbackTypeDef
)(RNG_HandleTypeDef
*hrng
); /*!< pointer to a common RNG callback function */
119 typedef void (*pRNG_ReadyDataCallbackTypeDef
)(RNG_HandleTypeDef
*hrng
, uint32_t random32bit
); /*!< pointer to an RNG Data Ready specific callback function */
121 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
131 /* Exported constants --------------------------------------------------------*/
132 /** @defgroup RNG_Exported_Constants RNG Exported Constants
136 /** @defgroup RNG_Exported_Constants_Group1 RNG Interrupt definition
139 #define RNG_IT_DRDY RNG_SR_DRDY /*!< Data Ready interrupt */
140 #define RNG_IT_CEI RNG_SR_CEIS /*!< Clock error interrupt */
141 #define RNG_IT_SEI RNG_SR_SEIS /*!< Seed error interrupt */
146 /** @defgroup RNG_Exported_Constants_Group2 RNG Flag definition
149 #define RNG_FLAG_DRDY RNG_SR_DRDY /*!< Data ready */
150 #define RNG_FLAG_CECS RNG_SR_CECS /*!< Clock error current status */
151 #define RNG_FLAG_SECS RNG_SR_SECS /*!< Seed error current status */
156 /** @defgroup RNG_Error_Definition RNG Error Definition
159 #define HAL_RNG_ERROR_NONE 0x00000000U /*!< No error */
160 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
161 #define HAL_RNG_ERROR_INVALID_CALLBACK 0x00000001U /*!< Invalid Callback error */
162 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
163 #define HAL_RNG_ERROR_TIMEOUT 0x00000002U /*!< Timeout error */
164 #define HAL_RNG_ERROR_BUSY 0x00000004U /*!< Busy error */
165 #define HAL_RNG_ERROR_SEED 0x00000008U /*!< Seed error */
166 #define HAL_RNG_ERROR_CLOCK 0x00000010U /*!< Clock error */
175 /* Exported macros -----------------------------------------------------------*/
176 /** @defgroup RNG_Exported_Macros RNG Exported Macros
180 /** @brief Reset RNG handle state
181 * @param __HANDLE__ RNG Handle
184 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
185 #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) do{ \
186 (__HANDLE__)->State = HAL_RNG_STATE_RESET; \
187 (__HANDLE__)->MspInitCallback = NULL; \
188 (__HANDLE__)->MspDeInitCallback = NULL; \
191 #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET)
192 #endif /*USE_HAL_RNG_REGISTER_CALLBACKS */
195 * @brief Enables the RNG peripheral.
196 * @param __HANDLE__ RNG Handle
199 #define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN)
202 * @brief Disables the RNG peripheral.
203 * @param __HANDLE__ RNG Handle
206 #define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN)
209 * @brief Check the selected RNG flag status.
210 * @param __HANDLE__ RNG Handle
211 * @param __FLAG__ RNG flag
212 * This parameter can be one of the following values:
213 * @arg RNG_FLAG_DRDY: Data ready
214 * @arg RNG_FLAG_CECS: Clock error current status
215 * @arg RNG_FLAG_SECS: Seed error current status
216 * @retval The new state of __FLAG__ (SET or RESET).
218 #define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
221 * @brief Clears the selected RNG flag status.
222 * @param __HANDLE__ RNG handle
223 * @param __FLAG__ RNG flag to clear
224 * @note WARNING: This is a dummy macro for HAL code alignment,
225 * flags RNG_FLAG_DRDY, RNG_FLAG_CECS and RNG_FLAG_SECS are read-only.
228 #define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) /* dummy macro */
231 * @brief Enables the RNG interrupts.
232 * @param __HANDLE__ RNG Handle
235 #define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE)
238 * @brief Disables the RNG interrupts.
239 * @param __HANDLE__ RNG Handle
242 #define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE)
245 * @brief Checks whether the specified RNG interrupt has occurred or not.
246 * @param __HANDLE__ RNG Handle
247 * @param __INTERRUPT__ specifies the RNG interrupt status flag to check.
248 * This parameter can be one of the following values:
249 * @arg RNG_IT_DRDY: Data ready interrupt
250 * @arg RNG_IT_CEI: Clock error interrupt
251 * @arg RNG_IT_SEI: Seed error interrupt
252 * @retval The new state of __INTERRUPT__ (SET or RESET).
254 #define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))
257 * @brief Clear the RNG interrupt status flags.
258 * @param __HANDLE__ RNG Handle
259 * @param __INTERRUPT__ specifies the RNG interrupt status flag to clear.
260 * This parameter can be one of the following values:
261 * @arg RNG_IT_CEI: Clock error interrupt
262 * @arg RNG_IT_SEI: Seed error interrupt
263 * @note RNG_IT_DRDY flag is read-only, reading RNG_DR register automatically clears RNG_IT_DRDY.
266 #define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__))
272 /* Exported functions --------------------------------------------------------*/
273 /** @defgroup RNG_Exported_Functions RNG Exported Functions
277 /** @defgroup RNG_Exported_Functions_Group1 Initialization and configuration functions
280 HAL_StatusTypeDef
HAL_RNG_Init(RNG_HandleTypeDef
*hrng
);
281 HAL_StatusTypeDef
HAL_RNG_DeInit(RNG_HandleTypeDef
*hrng
);
282 void HAL_RNG_MspInit(RNG_HandleTypeDef
*hrng
);
283 void HAL_RNG_MspDeInit(RNG_HandleTypeDef
*hrng
);
285 /* Callbacks Register/UnRegister functions ***********************************/
286 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
287 HAL_StatusTypeDef
HAL_RNG_RegisterCallback(RNG_HandleTypeDef
*hrng
, HAL_RNG_CallbackIDTypeDef CallbackID
, pRNG_CallbackTypeDef pCallback
);
288 HAL_StatusTypeDef
HAL_RNG_UnRegisterCallback(RNG_HandleTypeDef
*hrng
, HAL_RNG_CallbackIDTypeDef CallbackID
);
290 HAL_StatusTypeDef
HAL_RNG_RegisterReadyDataCallback(RNG_HandleTypeDef
*hrng
, pRNG_ReadyDataCallbackTypeDef pCallback
);
291 HAL_StatusTypeDef
HAL_RNG_UnRegisterReadyDataCallback(RNG_HandleTypeDef
*hrng
);
292 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
298 /** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions
301 uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef
*hrng
); /* Obsolete, use HAL_RNG_GenerateRandomNumber() instead */
302 uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef
*hrng
); /* Obsolete, use HAL_RNG_GenerateRandomNumber_IT() instead */
303 HAL_StatusTypeDef
HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef
*hrng
, uint32_t *random32bit
);
304 HAL_StatusTypeDef
HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef
*hrng
);
305 uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef
*hrng
);
307 void HAL_RNG_IRQHandler(RNG_HandleTypeDef
*hrng
);
308 void HAL_RNG_ErrorCallback(RNG_HandleTypeDef
*hrng
);
309 void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef
*hrng
, uint32_t random32bit
);
315 /** @defgroup RNG_Exported_Functions_Group3 Peripheral State functions
318 HAL_RNG_StateTypeDef
HAL_RNG_GetState(RNG_HandleTypeDef
*hrng
);
319 uint32_t HAL_RNG_GetError(RNG_HandleTypeDef
*hrng
);
328 /* Private macros ------------------------------------------------------------*/
329 /** @defgroup RNG_Private_Macros RNG Private Macros
332 #define IS_RNG_IT(IT) (((IT) == RNG_IT_CEI) || \
333 ((IT) == RNG_IT_SEI))
335 #define IS_RNG_FLAG(FLAG) (((FLAG) == RNG_FLAG_DRDY) || \
336 ((FLAG) == RNG_FLAG_CECS) || \
337 ((FLAG) == RNG_FLAG_SECS))
358 #endif /* STM32F7xx_HAL_RNG_H */
360 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/