![]() |
|
|||
File indexing completed on 2025-05-11 08:23:36
0001 /** 0002 ****************************************************************************** 0003 * @file stm32h7xx_hal_rng.h 0004 * @author MCD Application Team 0005 * @brief Header file of RNG HAL module. 0006 ****************************************************************************** 0007 * @attention 0008 * 0009 * Copyright (c) 2017 STMicroelectronics. 0010 * All rights reserved. 0011 * 0012 * This software is licensed under terms that can be found in the LICENSE file 0013 * in the root directory of this software component. 0014 * If no LICENSE file comes with this software, it is provided AS-IS. 0015 * 0016 ****************************************************************************** 0017 */ 0018 0019 /* Define to prevent recursive inclusion -------------------------------------*/ 0020 #ifndef STM32H7xx_HAL_RNG_H 0021 #define STM32H7xx_HAL_RNG_H 0022 0023 #ifdef __cplusplus 0024 extern "C" { 0025 #endif 0026 0027 /* Includes ------------------------------------------------------------------*/ 0028 #include "stm32h7xx_hal_def.h" 0029 0030 /** @addtogroup STM32H7xx_HAL_Driver 0031 * @{ 0032 */ 0033 0034 #if defined (RNG) 0035 0036 /** @defgroup RNG RNG 0037 * @ingroup RTEMSBSPsARMSTM32H7 0038 * @brief RNG HAL module driver 0039 * @{ 0040 */ 0041 0042 /* Exported types ------------------------------------------------------------*/ 0043 0044 /** @defgroup RNG_Exported_Types RNG Exported Types 0045 * @ingroup RTEMSBSPsARMSTM32H7 0046 * @{ 0047 */ 0048 0049 /** @defgroup RNG_Exported_Types_Group1 RNG Init Structure definition 0050 * @ingroup RTEMSBSPsARMSTM32H7 0051 * @{ 0052 */ 0053 typedef struct 0054 { 0055 uint32_t ClockErrorDetection; /*!< CED Clock error detection */ 0056 } RNG_InitTypeDef; 0057 0058 /** 0059 * @} 0060 */ 0061 0062 /** @defgroup RNG_Exported_Types_Group2 RNG State Structure definition 0063 * @ingroup RTEMSBSPsARMSTM32H7 0064 * @{ 0065 */ 0066 typedef enum 0067 { 0068 HAL_RNG_STATE_RESET = 0x00U, /*!< RNG not yet initialized or disabled */ 0069 HAL_RNG_STATE_READY = 0x01U, /*!< RNG initialized and ready for use */ 0070 HAL_RNG_STATE_BUSY = 0x02U, /*!< RNG internal process is ongoing */ 0071 HAL_RNG_STATE_TIMEOUT = 0x03U, /*!< RNG timeout state */ 0072 HAL_RNG_STATE_ERROR = 0x04U /*!< RNG error state */ 0073 0074 } HAL_RNG_StateTypeDef; 0075 0076 /** 0077 * @} 0078 */ 0079 0080 /** @defgroup RNG_Exported_Types_Group3 RNG Handle Structure definition 0081 * @ingroup RTEMSBSPsARMSTM32H7 0082 * @{ 0083 */ 0084 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 0085 typedef struct __RNG_HandleTypeDef 0086 #else 0087 typedef struct 0088 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 0089 { 0090 RNG_TypeDef *Instance; /*!< Register base address */ 0091 0092 RNG_InitTypeDef Init; /*!< RNG configuration parameters */ 0093 0094 HAL_LockTypeDef Lock; /*!< RNG locking object */ 0095 0096 __IO HAL_RNG_StateTypeDef State; /*!< RNG communication state */ 0097 0098 __IO uint32_t ErrorCode; /*!< RNG Error code */ 0099 0100 uint32_t RandomNumber; /*!< Last Generated RNG Data */ 0101 0102 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 0103 void (* ReadyDataCallback)(struct __RNG_HandleTypeDef *hrng, uint32_t random32bit); /*!< RNG Data Ready Callback */ 0104 void (* ErrorCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Error Callback */ 0105 0106 void (* MspInitCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Msp Init callback */ 0107 void (* MspDeInitCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Msp DeInit callback */ 0108 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 0109 0110 } RNG_HandleTypeDef; 0111 0112 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 0113 /** 0114 * @brief HAL RNG Callback ID enumeration definition 0115 */ 0116 typedef enum 0117 { 0118 HAL_RNG_ERROR_CB_ID = 0x00U, /*!< RNG Error Callback ID */ 0119 0120 HAL_RNG_MSPINIT_CB_ID = 0x01U, /*!< RNG MspInit callback ID */ 0121 HAL_RNG_MSPDEINIT_CB_ID = 0x02U /*!< RNG MspDeInit callback ID */ 0122 0123 } HAL_RNG_CallbackIDTypeDef; 0124 0125 /** 0126 * @brief HAL RNG Callback pointer definition 0127 */ 0128 typedef void (*pRNG_CallbackTypeDef)(RNG_HandleTypeDef *hrng); /*!< pointer to a common RNG callback function */ 0129 typedef void (*pRNG_ReadyDataCallbackTypeDef)(RNG_HandleTypeDef *hrng, uint32_t random32bit); /*!< pointer to an RNG Data Ready specific callback function */ 0130 0131 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 0132 0133 /** 0134 * @} 0135 */ 0136 0137 /** 0138 * @} 0139 */ 0140 0141 /* Exported constants --------------------------------------------------------*/ 0142 /** @defgroup RNG_Exported_Constants RNG Exported Constants 0143 * @ingroup RTEMSBSPsARMSTM32H7 0144 * @{ 0145 */ 0146 0147 /** @defgroup RNG_Exported_Constants_Group1 RNG Interrupt definition 0148 * @ingroup RTEMSBSPsARMSTM32H7 0149 * @{ 0150 */ 0151 #define RNG_IT_DRDY RNG_SR_DRDY /*!< Data Ready interrupt */ 0152 #define RNG_IT_CEI RNG_SR_CEIS /*!< Clock error interrupt */ 0153 #define RNG_IT_SEI RNG_SR_SEIS /*!< Seed error interrupt */ 0154 /** 0155 * @} 0156 */ 0157 0158 /** @defgroup RNG_Exported_Constants_Group2 RNG Flag definition 0159 * @ingroup RTEMSBSPsARMSTM32H7 0160 * @{ 0161 */ 0162 #define RNG_FLAG_DRDY RNG_SR_DRDY /*!< Data ready */ 0163 #define RNG_FLAG_CECS RNG_SR_CECS /*!< Clock error current status */ 0164 #define RNG_FLAG_SECS RNG_SR_SECS /*!< Seed error current status */ 0165 /** 0166 * @} 0167 */ 0168 0169 /** @defgroup RNG_Exported_Constants_Group3 RNG Clock Error Detection 0170 * @ingroup RTEMSBSPsARMSTM32H7 0171 * @{ 0172 */ 0173 #define RNG_CED_ENABLE 0x00000000U /*!< Clock error detection Enabled */ 0174 #define RNG_CED_DISABLE RNG_CR_CED /*!< Clock error detection Disabled */ 0175 /** 0176 * @} 0177 */ 0178 0179 /** @defgroup RNG_Error_Definition RNG Error Definition 0180 * @ingroup RTEMSBSPsARMSTM32H7 0181 * @{ 0182 */ 0183 #define HAL_RNG_ERROR_NONE 0x00000000U /*!< No error */ 0184 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 0185 #define HAL_RNG_ERROR_INVALID_CALLBACK 0x00000001U /*!< Invalid Callback error */ 0186 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 0187 #define HAL_RNG_ERROR_TIMEOUT 0x00000002U /*!< Timeout error */ 0188 #define HAL_RNG_ERROR_BUSY 0x00000004U /*!< Busy error */ 0189 #define HAL_RNG_ERROR_SEED 0x00000008U /*!< Seed error */ 0190 #define HAL_RNG_ERROR_CLOCK 0x00000010U /*!< Clock error */ 0191 /** 0192 * @} 0193 */ 0194 0195 /** 0196 * @} 0197 */ 0198 0199 /* Exported macros -----------------------------------------------------------*/ 0200 /** @defgroup RNG_Exported_Macros RNG Exported Macros 0201 * @ingroup RTEMSBSPsARMSTM32H7 0202 * @{ 0203 */ 0204 0205 /** @brief Reset RNG handle state 0206 * @param __HANDLE__ RNG Handle 0207 * @retval None 0208 */ 0209 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 0210 #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) do{ \ 0211 (__HANDLE__)->State = HAL_RNG_STATE_RESET; \ 0212 (__HANDLE__)->MspInitCallback = NULL; \ 0213 (__HANDLE__)->MspDeInitCallback = NULL; \ 0214 } while(0U) 0215 #else 0216 #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET) 0217 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 0218 0219 /** 0220 * @brief Enables the RNG peripheral. 0221 * @param __HANDLE__ RNG Handle 0222 * @retval None 0223 */ 0224 #define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN) 0225 0226 /** 0227 * @brief Disables the RNG peripheral. 0228 * @param __HANDLE__ RNG Handle 0229 * @retval None 0230 */ 0231 #define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN) 0232 0233 /** 0234 * @brief Check the selected RNG flag status. 0235 * @param __HANDLE__ RNG Handle 0236 * @param __FLAG__ RNG flag 0237 * This parameter can be one of the following values: 0238 * @arg RNG_FLAG_DRDY: Data ready 0239 * @arg RNG_FLAG_CECS: Clock error current status 0240 * @arg RNG_FLAG_SECS: Seed error current status 0241 * @retval The new state of __FLAG__ (SET or RESET). 0242 */ 0243 #define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) 0244 0245 /** 0246 * @brief Clears the selected RNG flag status. 0247 * @param __HANDLE__ RNG handle 0248 * @param __FLAG__ RNG flag to clear 0249 * @note WARNING: This is a dummy macro for HAL code alignment, 0250 * flags RNG_FLAG_DRDY, RNG_FLAG_CECS and RNG_FLAG_SECS are read-only. 0251 * @retval None 0252 */ 0253 #define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) /* dummy macro */ 0254 0255 /** 0256 * @brief Enables the RNG interrupts. 0257 * @param __HANDLE__ RNG Handle 0258 * @retval None 0259 */ 0260 #define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE) 0261 0262 /** 0263 * @brief Disables the RNG interrupts. 0264 * @param __HANDLE__ RNG Handle 0265 * @retval None 0266 */ 0267 #define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE) 0268 0269 /** 0270 * @brief Checks whether the specified RNG interrupt has occurred or not. 0271 * @param __HANDLE__ RNG Handle 0272 * @param __INTERRUPT__ specifies the RNG interrupt status flag to check. 0273 * This parameter can be one of the following values: 0274 * @arg RNG_IT_DRDY: Data ready interrupt 0275 * @arg RNG_IT_CEI: Clock error interrupt 0276 * @arg RNG_IT_SEI: Seed error interrupt 0277 * @retval The new state of __INTERRUPT__ (SET or RESET). 0278 */ 0279 #define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__)) 0280 0281 /** 0282 * @brief Clear the RNG interrupt status flags. 0283 * @param __HANDLE__ RNG Handle 0284 * @param __INTERRUPT__ specifies the RNG interrupt status flag to clear. 0285 * This parameter can be one of the following values: 0286 * @arg RNG_IT_CEI: Clock error interrupt 0287 * @arg RNG_IT_SEI: Seed error interrupt 0288 * @note RNG_IT_DRDY flag is read-only, reading RNG_DR register automatically clears RNG_IT_DRDY. 0289 * @retval None 0290 */ 0291 #define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__)) 0292 0293 /** 0294 * @} 0295 */ 0296 0297 #if defined (RNG_CR_CONDRST) 0298 /* Include RNG HAL Extended module */ 0299 #include "stm32h7xx_hal_rng_ex.h" 0300 #endif /* RNG_CR_CONDRST */ 0301 /* Exported functions --------------------------------------------------------*/ 0302 /** @defgroup RNG_Exported_Functions RNG Exported Functions 0303 * @ingroup RTEMSBSPsARMSTM32H7 0304 * @{ 0305 */ 0306 0307 /** @defgroup RNG_Exported_Functions_Group1 Initialization and configuration functions 0308 * @ingroup RTEMSBSPsARMSTM32H7 0309 * @{ 0310 */ 0311 HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng); 0312 HAL_StatusTypeDef HAL_RNG_DeInit(RNG_HandleTypeDef *hrng); 0313 void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng); 0314 void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng); 0315 0316 /* Callbacks Register/UnRegister functions ***********************************/ 0317 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 0318 HAL_StatusTypeDef HAL_RNG_RegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID, 0319 pRNG_CallbackTypeDef pCallback); 0320 HAL_StatusTypeDef HAL_RNG_UnRegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID); 0321 0322 HAL_StatusTypeDef HAL_RNG_RegisterReadyDataCallback(RNG_HandleTypeDef *hrng, pRNG_ReadyDataCallbackTypeDef pCallback); 0323 HAL_StatusTypeDef HAL_RNG_UnRegisterReadyDataCallback(RNG_HandleTypeDef *hrng); 0324 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 0325 0326 /** 0327 * @} 0328 */ 0329 0330 /** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions 0331 * @ingroup RTEMSBSPsARMSTM32H7 0332 * @{ 0333 */ 0334 HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit); 0335 HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng); 0336 uint32_t HAL_RNG_ReadLastRandomNumber(const RNG_HandleTypeDef *hrng); 0337 0338 void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng); 0339 void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng); 0340 void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef *hrng, uint32_t random32bit); 0341 0342 /** 0343 * @} 0344 */ 0345 0346 /** @defgroup RNG_Exported_Functions_Group3 Peripheral State functions 0347 * @ingroup RTEMSBSPsARMSTM32H7 0348 * @{ 0349 */ 0350 HAL_RNG_StateTypeDef HAL_RNG_GetState(const RNG_HandleTypeDef *hrng); 0351 uint32_t HAL_RNG_GetError(const RNG_HandleTypeDef *hrng); 0352 /** 0353 * @} 0354 */ 0355 0356 /** 0357 * @} 0358 */ 0359 0360 /* Private macros ------------------------------------------------------------*/ 0361 /** @defgroup RNG_Private_Macros RNG Private Macros 0362 * @ingroup RTEMSBSPsARMSTM32H7 0363 * @{ 0364 */ 0365 #define IS_RNG_IT(IT) (((IT) == RNG_IT_CEI) || \ 0366 ((IT) == RNG_IT_SEI)) 0367 0368 #define IS_RNG_FLAG(FLAG) (((FLAG) == RNG_FLAG_DRDY) || \ 0369 ((FLAG) == RNG_FLAG_CECS) || \ 0370 ((FLAG) == RNG_FLAG_SECS)) 0371 0372 /** 0373 * @brief Verify the RNG Clock Error Detection mode. 0374 * @param __MODE__ RNG Clock Error Detection mode 0375 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 0376 */ 0377 #define IS_RNG_CED(__MODE__) (((__MODE__) == RNG_CED_ENABLE) || \ 0378 ((__MODE__) == RNG_CED_DISABLE)) 0379 /** 0380 * @} 0381 */ 0382 0383 #if defined(RNG_CR_CONDRST) 0384 /* Private functions ---------------------------------------------------------*/ 0385 /** @defgroup RNG_Private_Functions RNG Private functions 0386 * @ingroup RTEMSBSPsARMSTM32H7 0387 * @{ 0388 */ 0389 HAL_StatusTypeDef RNG_RecoverSeedError(RNG_HandleTypeDef *hrng); 0390 /** 0391 * @} 0392 */ 0393 #endif /* RNG_CR_CONDRST */ 0394 /** 0395 * @} 0396 */ 0397 0398 #endif /* RNG */ 0399 0400 /** 0401 * @} 0402 */ 0403 0404 #ifdef __cplusplus 0405 } 0406 #endif 0407 0408 0409 #endif /* STM32H7xx_HAL_RNG_H */ 0410
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |