STM32L486xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_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) 2017 STMicroelectronics</center></h2> 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00030 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 ****************************************************************************** 00034 */ 00035 00036 /* Define to prevent recursive inclusion -------------------------------------*/ 00037 #ifndef __STM32L4xx_HAL_RNG_H 00038 #define __STM32L4xx_HAL_RNG_H 00039 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00044 /* Includes ------------------------------------------------------------------*/ 00045 #include "stm32l4xx_hal_def.h" 00046 00047 /** @addtogroup STM32L4xx_HAL_Driver 00048 * @{ 00049 */ 00050 00051 /** @addtogroup RNG 00052 * @{ 00053 */ 00054 00055 /* Exported types ------------------------------------------------------------*/ 00056 /** @defgroup RNG_Exported_Types RNG Exported Types 00057 * @{ 00058 */ 00059 00060 #if defined(RNG_CR_CED) 00061 /** 00062 * @brief RNG Configuration Structure definition 00063 */ 00064 typedef struct 00065 { 00066 uint32_t ClockErrorDetection; /*!< Clock error detection */ 00067 }RNG_InitTypeDef; 00068 #endif /* defined(RNG_CR_CED) */ 00069 00070 /** 00071 * @brief RNG HAL State Structure definition 00072 */ 00073 typedef enum 00074 { 00075 HAL_RNG_STATE_RESET = 0x00, /*!< RNG not yet initialized or disabled */ 00076 HAL_RNG_STATE_READY = 0x01, /*!< RNG initialized and ready for use */ 00077 HAL_RNG_STATE_BUSY = 0x02, /*!< RNG internal process is ongoing */ 00078 HAL_RNG_STATE_TIMEOUT = 0x03, /*!< RNG timeout state */ 00079 HAL_RNG_STATE_ERROR = 0x04 /*!< RNG error state */ 00080 00081 }HAL_RNG_StateTypeDef; 00082 00083 /** 00084 * @brief RNG Handle Structure definition 00085 */ 00086 typedef struct __RNG_HandleTypeDef 00087 { 00088 RNG_TypeDef *Instance; /*!< Register base address */ 00089 00090 #if defined(RNG_CR_CED) 00091 RNG_InitTypeDef Init; /*!< RNG configuration parameters */ 00092 #endif /* defined(RNG_CR_CED) */ 00093 00094 HAL_LockTypeDef Lock; /*!< RNG locking object */ 00095 00096 __IO HAL_RNG_StateTypeDef State; /*!< RNG communication state */ 00097 00098 __IO uint32_t ErrorCode; /*!< RNG Error code */ 00099 00100 uint32_t RandomNumber; /*!< Last Generated RNG Data */ 00101 00102 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 00103 void (* ReadyDataCallback)(struct __RNG_HandleTypeDef *hrng, uint32_t random32bit); /*!< RNG Data Ready Callback */ 00104 void (* ErrorCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Error Callback */ 00105 00106 void (* MspInitCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Msp Init callback */ 00107 void (* MspDeInitCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Msp DeInit callback */ 00108 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 00109 00110 }RNG_HandleTypeDef; 00111 00112 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 00113 /** 00114 * @brief HAL RNG Callback ID enumeration definition 00115 */ 00116 typedef enum 00117 { 00118 HAL_RNG_ERROR_CB_ID = 0x00U, /*!< RNG Error Callback ID */ 00119 00120 HAL_RNG_MSPINIT_CB_ID = 0x01U, /*!< RNG MspInit callback ID */ 00121 HAL_RNG_MSPDEINIT_CB_ID = 0x02U /*!< RNG MspDeInit callback ID */ 00122 00123 } HAL_RNG_CallbackIDTypeDef; 00124 00125 /** 00126 * @brief HAL RNG Callback pointer definition 00127 */ 00128 typedef void (*pRNG_CallbackTypeDef)(RNG_HandleTypeDef *hrng); /*!< pointer to a common RNG callback function */ 00129 typedef void (*pRNG_ReadyDataCallbackTypeDef)(RNG_HandleTypeDef * hrng, uint32_t random32bit); /*!< pointer to an RNG Data Ready specific callback function */ 00130 00131 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 00132 00133 /** 00134 * @} 00135 */ 00136 00137 /* Exported constants --------------------------------------------------------*/ 00138 /** @defgroup RNG_Exported_Constants RNG Exported Constants 00139 * @{ 00140 */ 00141 00142 /** @defgroup RNG_Interrupt_definition RNG Interrupts Definition 00143 * @{ 00144 */ 00145 #define RNG_IT_DRDY RNG_SR_DRDY /*!< Data Ready interrupt */ 00146 #define RNG_IT_CEI RNG_SR_CEIS /*!< Clock error interrupt */ 00147 #define RNG_IT_SEI RNG_SR_SEIS /*!< Seed error interrupt */ 00148 /** 00149 * @} 00150 */ 00151 00152 /** @defgroup RNG_Flag_definition RNG Flags Definition 00153 * @{ 00154 */ 00155 #define RNG_FLAG_DRDY RNG_SR_DRDY /*!< Data ready */ 00156 #define RNG_FLAG_CECS RNG_SR_CECS /*!< Clock error current status */ 00157 #define RNG_FLAG_SECS RNG_SR_SECS /*!< Seed error current status */ 00158 /** 00159 * @} 00160 */ 00161 00162 #if defined(RNG_CR_CED) 00163 /** @defgroup RNG_Clock_Error_Detection RNG Clock Error Detection 00164 * @{ 00165 */ 00166 #define RNG_CED_ENABLE ((uint32_t)0x00000000) /*!< Clock error detection enabled */ 00167 #define RNG_CED_DISABLE RNG_CR_CED /*!< Clock error detection disabled */ 00168 /** 00169 * @} 00170 */ 00171 #endif /* defined(RNG_CR_CED) */ 00172 00173 /** @defgroup RNG_Error_Definition RNG Error Definition 00174 * @{ 00175 */ 00176 #define HAL_RNG_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */ 00177 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 00178 #define HAL_RNG_ERROR_INVALID_CALLBACK ((uint32_t)0x00000001U) /*!< Invalid Callback error */ 00179 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 00180 /** 00181 * @} 00182 */ 00183 00184 /** 00185 * @} 00186 */ 00187 00188 /* Exported macros -----------------------------------------------------------*/ 00189 /** @defgroup RNG_Exported_Macros RNG Exported Macros 00190 * @{ 00191 */ 00192 00193 /** @brief Reset RNG handle state. 00194 * @param __HANDLE__: RNG Handle 00195 * @retval None 00196 */ 00197 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 00198 #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) do{ \ 00199 (__HANDLE__)->State = HAL_RNG_STATE_RESET; \ 00200 (__HANDLE__)->MspInitCallback = NULL; \ 00201 (__HANDLE__)->MspDeInitCallback = NULL; \ 00202 } while(0U) 00203 #else 00204 #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET) 00205 #endif /*USE_HAL_RNG_REGISTER_CALLBACKS */ 00206 00207 /** 00208 * @brief Enable the RNG peripheral. 00209 * @param __HANDLE__: RNG Handle 00210 * @retval None 00211 */ 00212 #define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN) 00213 00214 /** 00215 * @brief Disable the RNG peripheral. 00216 * @param __HANDLE__: RNG Handle 00217 * @retval None 00218 */ 00219 #define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN) 00220 00221 /** 00222 * @brief Check whether the specified RNG flag is set or not. 00223 * @param __HANDLE__: RNG Handle 00224 * @param __FLAG__: RNG flag 00225 * This parameter can be one of the following values: 00226 * @arg RNG_FLAG_DRDY: Data ready 00227 * @arg RNG_FLAG_CECS: Clock error current status 00228 * @arg RNG_FLAG_SECS: Seed error current status 00229 * @retval The new state of __FLAG__ (SET or RESET). 00230 */ 00231 #define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) 00232 00233 /** 00234 * @brief Clear the selected RNG flag status. 00235 * @param __HANDLE__: RNG handle 00236 * @param __FLAG__: RNG flag to clear 00237 * @note WARNING: This is a dummy macro for HAL code alignment, 00238 * flags RNG_FLAG_DRDY, RNG_FLAG_CECS and RNG_FLAG_SECS are read-only. 00239 * @retval None 00240 */ 00241 #define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) /* dummy macro */ 00242 00243 /** 00244 * @brief Enable the RNG interrupt. 00245 * @param __HANDLE__: RNG Handle 00246 * @retval None 00247 */ 00248 #define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE) 00249 00250 /** 00251 * @brief Disable the RNG interrupt. 00252 * @param __HANDLE__: RNG Handle 00253 * @retval None 00254 */ 00255 #define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE) 00256 00257 /** 00258 * @brief Check whether the specified RNG interrupt has occurred or not. 00259 * @param __HANDLE__: RNG Handle 00260 * @param __INTERRUPT__: specifies the RNG interrupt status flag to check. 00261 * This parameter can be one of the following values: 00262 * @arg RNG_IT_DRDY: Data ready interrupt 00263 * @arg RNG_IT_CEI: Clock error interrupt 00264 * @arg RNG_IT_SEI: Seed error interrupt 00265 * @retval The new state of __INTERRUPT__ (SET or RESET). 00266 */ 00267 #define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__)) 00268 00269 /** 00270 * @brief Clear the RNG interrupt status flags. 00271 * @param __HANDLE__: RNG Handle 00272 * @param __INTERRUPT__: specifies the RNG interrupt status flag to clear. 00273 * This parameter can be one of the following values: 00274 * @arg RNG_IT_CEI: Clock error interrupt 00275 * @arg RNG_IT_SEI: Seed error interrupt 00276 * @note RNG_IT_DRDY flag is read-only, reading RNG_DR register automatically clears RNG_IT_DRDY. 00277 * @retval None 00278 */ 00279 #define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__)) 00280 00281 /** 00282 * @} 00283 */ 00284 00285 00286 /* Exported functions --------------------------------------------------------*/ 00287 /** @defgroup RNG_Exported_Functions RNG Exported Functions 00288 * @{ 00289 */ 00290 00291 /* Initialization and de-initialization functions ******************************/ 00292 /** @defgroup RNG_Exported_Functions_Group1 Initialization and de-initialization functions 00293 * @{ 00294 */ 00295 HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng); 00296 HAL_StatusTypeDef HAL_RNG_DeInit (RNG_HandleTypeDef *hrng); 00297 void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng); 00298 void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng); 00299 00300 /* Callbacks Register/UnRegister functions ***********************************/ 00301 #if (USE_HAL_RNG_REGISTER_CALLBACKS == 1) 00302 HAL_StatusTypeDef HAL_RNG_RegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID, pRNG_CallbackTypeDef pCallback); 00303 HAL_StatusTypeDef HAL_RNG_UnRegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID); 00304 00305 HAL_StatusTypeDef HAL_RNG_RegisterReadyDataCallback(RNG_HandleTypeDef *hrng, pRNG_ReadyDataCallbackTypeDef pCallback); 00306 HAL_StatusTypeDef HAL_RNG_UnRegisterReadyDataCallback(RNG_HandleTypeDef *hrng); 00307 #endif /* USE_HAL_RNG_REGISTER_CALLBACKS */ 00308 00309 /** 00310 * @} 00311 */ 00312 00313 /* Peripheral Control functions ************************************************/ 00314 /** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions 00315 * @{ 00316 */ 00317 uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber() instead */ 00318 uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber_IT() instead */ 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 /* Peripheral State functions **************************************************/ 00332 /** @defgroup RNG_Exported_Functions_Group3 Peripheral State and Error 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 types -------------------------------------------------------------*/ 00346 /* Private defines -----------------------------------------------------------*/ 00347 /* Private variables ---------------------------------------------------------*/ 00348 /* Private constants ---------------------------------------------------------*/ 00349 /* Private macros ------------------------------------------------------------*/ 00350 /** @addtogroup RNG_Private_Macros RNG Private Macros 00351 * @{ 00352 */ 00353 00354 #if defined(RNG_CR_CED) 00355 /** 00356 * @brief Verify the RNG Clock Error Detection mode. 00357 * @param __MODE__: RNG Clock Error Detection mode 00358 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 00359 */ 00360 #define IS_RNG_CED(__MODE__) (((__MODE__) == RNG_CED_ENABLE) || \ 00361 ((__MODE__) == RNG_CED_DISABLE)) 00362 #endif /* defined(RNG_CR_CED) */ 00363 00364 /** 00365 * @} 00366 */ 00367 /* Private functions prototypes ----------------------------------------------*/ 00368 00369 /** 00370 * @} 00371 */ 00372 00373 /** 00374 * @} 00375 */ 00376 00377 #ifdef __cplusplus 00378 } 00379 #endif 00380 00381 #endif /* __STM32L4xx_HAL_RNG_H */ 00382 00383 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/