Updated and Validated
[betaflight.git] / lib / main / STM32F7 / Drivers / STM32F7xx_HAL_Driver / Inc / stm32f7xx_hal_rng.h
blob3245aa70c6e9f31e4d802fd7713774abffd4e0b2
1 /**
2 ******************************************************************************
3 * @file stm32f7xx_hal_rng.h
4 * @author MCD Application Team
5 * @brief Header file of RNG HAL module.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; 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
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32f7xx_hal_def.h"
31 /** @addtogroup STM32F7xx_HAL_Driver
32 * @{
35 #if defined (RNG)
37 /** @defgroup RNG RNG
38 * @brief RNG HAL module driver
39 * @{
42 /* Exported types ------------------------------------------------------------*/
44 /** @defgroup RNG_Exported_Types RNG Exported Types
45 * @{
48 /** @defgroup RNG_Exported_Types_Group1 RNG Init Structure definition
49 * @{
52 /**
53 * @}
56 /** @defgroup RNG_Exported_Types_Group2 RNG State Structure definition
57 * @{
59 typedef enum
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;
69 /**
70 * @}
73 /** @defgroup RNG_Exported_Types_Group3 RNG Handle Structure definition
74 * @{
76 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
77 typedef struct __RNG_HandleTypeDef
78 #else
79 typedef struct
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 */
100 } RNG_HandleTypeDef;
102 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
104 * @brief HAL RNG Callback ID enumeration definition
106 typedef enum
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 */
124 * @}
128 * @}
131 /* Exported constants --------------------------------------------------------*/
132 /** @defgroup RNG_Exported_Constants RNG Exported Constants
133 * @{
136 /** @defgroup RNG_Exported_Constants_Group1 RNG Interrupt definition
137 * @{
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 */
143 * @}
146 /** @defgroup RNG_Exported_Constants_Group2 RNG Flag definition
147 * @{
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 */
153 * @}
156 /** @defgroup RNG_Error_Definition RNG Error Definition
157 * @{
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 */
168 * @}
172 * @}
175 /* Exported macros -----------------------------------------------------------*/
176 /** @defgroup RNG_Exported_Macros RNG Exported Macros
177 * @{
180 /** @brief Reset RNG handle state
181 * @param __HANDLE__ RNG Handle
182 * @retval None
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; \
189 } while(0U)
190 #else
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
197 * @retval None
199 #define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN)
202 * @brief Disables the RNG peripheral.
203 * @param __HANDLE__ RNG Handle
204 * @retval None
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.
226 * @retval None
228 #define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) /* dummy macro */
231 * @brief Enables the RNG interrupts.
232 * @param __HANDLE__ RNG Handle
233 * @retval None
235 #define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE)
238 * @brief Disables the RNG interrupts.
239 * @param __HANDLE__ RNG Handle
240 * @retval None
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.
264 * @retval None
266 #define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__))
269 * @}
272 /* Exported functions --------------------------------------------------------*/
273 /** @defgroup RNG_Exported_Functions RNG Exported Functions
274 * @{
277 /** @defgroup RNG_Exported_Functions_Group1 Initialization and configuration functions
278 * @{
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 */
295 * @}
298 /** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions
299 * @{
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);
312 * @}
315 /** @defgroup RNG_Exported_Functions_Group3 Peripheral State functions
316 * @{
318 HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng);
319 uint32_t HAL_RNG_GetError(RNG_HandleTypeDef *hrng);
321 * @}
325 * @}
328 /* Private macros ------------------------------------------------------------*/
329 /** @defgroup RNG_Private_Macros RNG Private Macros
330 * @{
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))
340 * @}
344 * @}
347 #endif /* RNG */
350 * @}
353 #ifdef __cplusplus
355 #endif
358 #endif /* STM32F7xx_HAL_RNG_H */
360 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/