STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_hal_rng.h 00004 * @author MCD Application Team 00005 * @brief Header file of RNG HAL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 00019 /* Define to prevent recursive inclusion -------------------------------------*/ 00020 #ifndef STM32H7xx_HAL_RNG_H 00021 #define STM32H7xx_HAL_RNG_H 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /* Includes ------------------------------------------------------------------*/ 00028 #include "stm32h7xx_hal_def.h" 00029 00030 /** @addtogroup STM32H7xx_HAL_Driver 00031 * @{ 00032 */ 00033 00034 #if defined (RNG) 00035 00036 /** @defgroup RNG RNG 00037 * @brief RNG HAL module driver 00038 * @{ 00039 */ 00040 00041 /* Exported types ------------------------------------------------------------*/ 00042 00043 /** @defgroup RNG_Exported_Types RNG Exported Types 00044 * @{ 00045 */ 00046 00047 /** @defgroup RNG_Exported_Types_Group1 RNG Init Structure definition 00048 * @{ 00049 */ 00050 typedef struct 00051 { 00052 uint32_t ClockErrorDetection; /*!< CED Clock error detection */ 00053 } RNG_InitTypeDef; 00054 00055 /** 00056 * @} 00057 */ 00058 00059 /** @defgroup RNG_Exported_Types_Group2 RNG State Structure definition 00060 * @{ 00061 */ 00062 typedef enum 00063 { 00064 HAL_RNG_STATE_RESET = 0x00U, /*!< RNG not yet initialized or disabled */ 00065 HAL_RNG_STATE_READY = 0x01U, /*!< RNG initialized and ready for use */ 00066 HAL_RNG_STATE_BUSY = 0x02U, /*!< RNG internal process is ongoing */ 00067 HAL_RNG_STATE_TIMEOUT = 0x03U, /*!< RNG timeout state */ 00068 HAL_RNG_STATE_ERROR = 0x04U /*!< RNG error state */ 00069 00070 } HAL_RNG_StateTypeDef; 00071 00072 /** 00073 * @} 00074 */ 00075 00076 /** @defgroup RNG_Exported_Types_Group3 RNG Handle Structure definition 00077 * @{ 00078 */ 00079 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 00080 typedef struct __RNG_HandleTypeDef 00081 #else 00082 typedef struct 00083 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 00084 { 00085 RNG_TypeDef *Instance; /*!< Register base address */ 00086 00087 RNG_InitTypeDef Init; /*!< RNG configuration parameters */ 00088 00089 HAL_LockTypeDef Lock; /*!< RNG locking object */ 00090 00091 __IO HAL_RNG_StateTypeDef State; /*!< RNG communication state */ 00092 00093 __IO uint32_t ErrorCode; /*!< RNG Error code */ 00094 00095 uint32_t RandomNumber; /*!< Last Generated RNG Data */ 00096 00097 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 00098 void (* ReadyDataCallback)(struct __RNG_HandleTypeDef *hrng, uint32_t random32bit); /*!< RNG Data Ready Callback */ 00099 void (* ErrorCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Error Callback */ 00100 00101 void (* MspInitCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Msp Init callback */ 00102 void (* MspDeInitCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Msp DeInit callback */ 00103 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 00104 00105 } RNG_HandleTypeDef; 00106 00107 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 00108 /** 00109 * @brief HAL RNG Callback ID enumeration definition 00110 */ 00111 typedef enum 00112 { 00113 HAL_RNG_ERROR_CB_ID = 0x00U, /*!< RNG Error Callback ID */ 00114 00115 HAL_RNG_MSPINIT_CB_ID = 0x01U, /*!< RNG MspInit callback ID */ 00116 HAL_RNG_MSPDEINIT_CB_ID = 0x02U /*!< RNG MspDeInit callback ID */ 00117 00118 } HAL_RNG_CallbackIDTypeDef; 00119 00120 /** 00121 * @brief HAL RNG Callback pointer definition 00122 */ 00123 typedef void (*pRNG_CallbackTypeDef)(RNG_HandleTypeDef *hrng); /*!< pointer to a common RNG callback function */ 00124 typedef void (*pRNG_ReadyDataCallbackTypeDef)(RNG_HandleTypeDef *hrng, uint32_t random32bit); /*!< pointer to an RNG Data Ready specific callback function */ 00125 00126 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 00127 00128 /** 00129 * @} 00130 */ 00131 00132 /** 00133 * @} 00134 */ 00135 00136 /* Exported constants --------------------------------------------------------*/ 00137 /** @defgroup RNG_Exported_Constants RNG Exported Constants 00138 * @{ 00139 */ 00140 00141 /** @defgroup RNG_Exported_Constants_Group1 RNG Interrupt definition 00142 * @{ 00143 */ 00144 #define RNG_IT_DRDY RNG_SR_DRDY /*!< Data Ready interrupt */ 00145 #define RNG_IT_CEI RNG_SR_CEIS /*!< Clock error interrupt */ 00146 #define RNG_IT_SEI RNG_SR_SEIS /*!< Seed error interrupt */ 00147 /** 00148 * @} 00149 */ 00150 00151 /** @defgroup RNG_Exported_Constants_Group2 RNG Flag definition 00152 * @{ 00153 */ 00154 #define RNG_FLAG_DRDY RNG_SR_DRDY /*!< Data ready */ 00155 #define RNG_FLAG_CECS RNG_SR_CECS /*!< Clock error current status */ 00156 #define RNG_FLAG_SECS RNG_SR_SECS /*!< Seed error current status */ 00157 /** 00158 * @} 00159 */ 00160 00161 /** @defgroup RNG_Exported_Constants_Group3 RNG Clock Error Detection 00162 * @{ 00163 */ 00164 #define RNG_CED_ENABLE 0x00000000U /*!< Clock error detection Enabled */ 00165 #define RNG_CED_DISABLE RNG_CR_CED /*!< Clock error detection Disabled */ 00166 /** 00167 * @} 00168 */ 00169 00170 /** @defgroup RNG_Error_Definition RNG Error Definition 00171 * @{ 00172 */ 00173 #define HAL_RNG_ERROR_NONE 0x00000000U /*!< No error */ 00174 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 00175 #define HAL_RNG_ERROR_INVALID_CALLBACK 0x00000001U /*!< Invalid Callback error */ 00176 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 00177 #define HAL_RNG_ERROR_TIMEOUT 0x00000002U /*!< Timeout error */ 00178 #define HAL_RNG_ERROR_BUSY 0x00000004U /*!< Busy error */ 00179 #define HAL_RNG_ERROR_SEED 0x00000008U /*!< Seed error */ 00180 #define HAL_RNG_ERROR_CLOCK 0x00000010U /*!< Clock error */ 00181 /** 00182 * @} 00183 */ 00184 00185 /** 00186 * @} 00187 */ 00188 00189 /* Exported macros -----------------------------------------------------------*/ 00190 /** @defgroup RNG_Exported_Macros RNG Exported Macros 00191 * @{ 00192 */ 00193 00194 /** @brief Reset RNG handle state 00195 * @param __HANDLE__ RNG Handle 00196 * @retval None 00197 */ 00198 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 00199 #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) do{ \ 00200 (__HANDLE__)->State = HAL_RNG_STATE_RESET; \ 00201 (__HANDLE__)->MspInitCallback = NULL; \ 00202 (__HANDLE__)->MspDeInitCallback = NULL; \ 00203 } while(0U) 00204 #else 00205 #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET) 00206 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 00207 00208 /** 00209 * @brief Enables the RNG peripheral. 00210 * @param __HANDLE__ RNG Handle 00211 * @retval None 00212 */ 00213 #define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN) 00214 00215 /** 00216 * @brief Disables the RNG peripheral. 00217 * @param __HANDLE__ RNG Handle 00218 * @retval None 00219 */ 00220 #define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN) 00221 00222 /** 00223 * @brief Check the selected RNG flag status. 00224 * @param __HANDLE__ RNG Handle 00225 * @param __FLAG__ RNG flag 00226 * This parameter can be one of the following values: 00227 * @arg RNG_FLAG_DRDY: Data ready 00228 * @arg RNG_FLAG_CECS: Clock error current status 00229 * @arg RNG_FLAG_SECS: Seed error current status 00230 * @retval The new state of __FLAG__ (SET or RESET). 00231 */ 00232 #define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) 00233 00234 /** 00235 * @brief Clears the selected RNG flag status. 00236 * @param __HANDLE__ RNG handle 00237 * @param __FLAG__ RNG flag to clear 00238 * @note WARNING: This is a dummy macro for HAL code alignment, 00239 * flags RNG_FLAG_DRDY, RNG_FLAG_CECS and RNG_FLAG_SECS are read-only. 00240 * @retval None 00241 */ 00242 #define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) /* dummy macro */ 00243 00244 /** 00245 * @brief Enables the RNG interrupts. 00246 * @param __HANDLE__ RNG Handle 00247 * @retval None 00248 */ 00249 #define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE) 00250 00251 /** 00252 * @brief Disables the RNG interrupts. 00253 * @param __HANDLE__ RNG Handle 00254 * @retval None 00255 */ 00256 #define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE) 00257 00258 /** 00259 * @brief Checks whether the specified RNG interrupt has occurred or not. 00260 * @param __HANDLE__ RNG Handle 00261 * @param __INTERRUPT__ specifies the RNG interrupt status flag to check. 00262 * This parameter can be one of the following values: 00263 * @arg RNG_IT_DRDY: Data ready interrupt 00264 * @arg RNG_IT_CEI: Clock error interrupt 00265 * @arg RNG_IT_SEI: Seed error interrupt 00266 * @retval The new state of __INTERRUPT__ (SET or RESET). 00267 */ 00268 #define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__)) 00269 00270 /** 00271 * @brief Clear the RNG interrupt status flags. 00272 * @param __HANDLE__ RNG Handle 00273 * @param __INTERRUPT__ specifies the RNG interrupt status flag to clear. 00274 * This parameter can be one of the following values: 00275 * @arg RNG_IT_CEI: Clock error interrupt 00276 * @arg RNG_IT_SEI: Seed error interrupt 00277 * @note RNG_IT_DRDY flag is read-only, reading RNG_DR register automatically clears RNG_IT_DRDY. 00278 * @retval None 00279 */ 00280 #define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__)) 00281 00282 /** 00283 * @} 00284 */ 00285 00286 #if defined (RNG_CR_CONDRST) 00287 /* Include RNG HAL Extended module */ 00288 #include "stm32h7xx_hal_rng_ex.h" 00289 #endif /* RNG_CR_CONDRST */ 00290 /* Exported functions --------------------------------------------------------*/ 00291 /** @defgroup RNG_Exported_Functions RNG Exported Functions 00292 * @{ 00293 */ 00294 00295 /** @defgroup RNG_Exported_Functions_Group1 Initialization and configuration functions 00296 * @{ 00297 */ 00298 HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng); 00299 HAL_StatusTypeDef HAL_RNG_DeInit(RNG_HandleTypeDef *hrng); 00300 void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng); 00301 void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng); 00302 00303 /* Callbacks Register/UnRegister functions ***********************************/ 00304 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 00305 HAL_StatusTypeDef HAL_RNG_RegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID, 00306 pRNG_CallbackTypeDef pCallback); 00307 HAL_StatusTypeDef HAL_RNG_UnRegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID); 00308 00309 HAL_StatusTypeDef HAL_RNG_RegisterReadyDataCallback(RNG_HandleTypeDef *hrng, pRNG_ReadyDataCallbackTypeDef pCallback); 00310 HAL_StatusTypeDef HAL_RNG_UnRegisterReadyDataCallback(RNG_HandleTypeDef *hrng); 00311 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 00312 00313 /** 00314 * @} 00315 */ 00316 00317 /** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions 00318 * @{ 00319 */ 00320 HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit); 00321 HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng); 00322 uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef *hrng); 00323 00324 void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng); 00325 void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng); 00326 void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef *hrng, uint32_t random32bit); 00327 00328 /** 00329 * @} 00330 */ 00331 00332 /** @defgroup RNG_Exported_Functions_Group3 Peripheral State functions 00333 * @{ 00334 */ 00335 HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng); 00336 uint32_t HAL_RNG_GetError(RNG_HandleTypeDef *hrng); 00337 /** 00338 * @} 00339 */ 00340 00341 /** 00342 * @} 00343 */ 00344 00345 /* Private macros ------------------------------------------------------------*/ 00346 /** @defgroup RNG_Private_Macros RNG Private Macros 00347 * @{ 00348 */ 00349 #define IS_RNG_IT(IT) (((IT) == RNG_IT_CEI) || \ 00350 ((IT) == RNG_IT_SEI)) 00351 00352 #define IS_RNG_FLAG(FLAG) (((FLAG) == RNG_FLAG_DRDY) || \ 00353 ((FLAG) == RNG_FLAG_CECS) || \ 00354 ((FLAG) == RNG_FLAG_SECS)) 00355 00356 /** 00357 * @brief Verify the RNG Clock Error Detection mode. 00358 * @param __MODE__ RNG Clock Error Detection mode 00359 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 00360 */ 00361 #define IS_RNG_CED(__MODE__) (((__MODE__) == RNG_CED_ENABLE) || \ 00362 ((__MODE__) == RNG_CED_DISABLE)) 00363 /** 00364 * @} 00365 */ 00366 00367 #if defined(RNG_CR_CONDRST) 00368 /* Private functions ---------------------------------------------------------*/ 00369 /** @defgroup RNG_Private_Functions RNG Private functions 00370 * @{ 00371 */ 00372 HAL_StatusTypeDef RNG_RecoverSeedError(RNG_HandleTypeDef *hrng); 00373 /** 00374 * @} 00375 */ 00376 #endif /* RNG_CR_CONDRST */ 00377 /** 00378 * @} 00379 */ 00380 00381 #endif /* RNG */ 00382 00383 /** 00384 * @} 00385 */ 00386 00387 #ifdef __cplusplus 00388 } 00389 #endif 00390 00391 00392 #endif /* STM32H7xx_HAL_RNG_H */ 00393