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