STM32L486xx HAL User Manual
stm32l4xx_ll_rng.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_ll_rng.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of RNG LL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; 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_LL_RNG_H
00038 #define __STM32L4xx_LL_RNG_H
00039 
00040 #ifdef __cplusplus
00041 extern "C" {
00042 #endif
00043 
00044 /* Includes ------------------------------------------------------------------*/
00045 #include "stm32l4xx.h"
00046 
00047 /** @addtogroup STM32L4xx_LL_Driver
00048   * @{
00049   */
00050 
00051 #if defined(RNG)
00052 
00053 /** @defgroup RNG_LL RNG
00054   * @{
00055   */
00056 
00057 /* Private types -------------------------------------------------------------*/
00058 /* Private variables ---------------------------------------------------------*/
00059 /* Private constants ---------------------------------------------------------*/
00060 /* Private macros ------------------------------------------------------------*/
00061 
00062 /* Exported types ------------------------------------------------------------*/
00063 #if defined(USE_FULL_LL_DRIVER)
00064 /** @defgroup RNG_LL_ES_Init_Struct RNG Exported Init structures
00065   * @{
00066   */
00067   
00068 
00069 #if defined(RNG_CR_CED)
00070 /**
00071   * @brief LL RNG Init Structure Definition
00072   */
00073 typedef struct
00074 {
00075   uint32_t         ClockErrorDetection; /*!< Clock error detection.
00076                                       This parameter can be one value of @ref RNG_LL_CED.
00077                                       
00078                                       This parameter can be modified using unitary functions @ref LL_RNG_EnableClkErrorDetect(). */
00079 }LL_RNG_InitTypeDef;
00080 #endif /* defined(RNG_CR_CED) */
00081 
00082 /**
00083   * @}
00084   */
00085 #endif /* USE_FULL_LL_DRIVER */
00086   
00087 /* Exported constants --------------------------------------------------------*/
00088 /** @defgroup RNG_LL_Exported_Constants RNG Exported Constants
00089   * @{
00090   */
00091   
00092 #if defined(RNG_CR_CED)
00093 /** @defgroup RNG_LL_CED Clock Error Detection
00094   * @{
00095   */
00096 #define LL_RNG_CED_ENABLE         0x00000000U              /*!< Clock error detection enabled  */
00097 #define LL_RNG_CED_DISABLE        RNG_CR_CED               /*!< Clock error detection disabled */
00098 /**
00099   * @}
00100   */
00101 #endif /* defined(RNG_CR_CED) */
00102 
00103   
00104 /** @defgroup RNG_LL_EC_GET_FLAG Get Flags Defines
00105   * @brief    Flags defines which can be used with LL_RNG_ReadReg function
00106   * @{
00107   */
00108 #define LL_RNG_SR_DRDY RNG_SR_DRDY    /*!< Register contains valid random data */
00109 #define LL_RNG_SR_CECS RNG_SR_CECS    /*!< Clock error current status */
00110 #define LL_RNG_SR_SECS RNG_SR_SECS    /*!< Seed error current status */
00111 #define LL_RNG_SR_CEIS RNG_SR_CEIS    /*!< Clock error interrupt status */
00112 #define LL_RNG_SR_SEIS RNG_SR_SEIS    /*!< Seed error interrupt status */
00113 /**
00114   * @}
00115   */
00116 
00117 /** @defgroup RNG_LL_EC_IT IT Defines
00118   * @brief    IT defines which can be used with LL_RNG_ReadReg and  LL_RNG_WriteReg macros
00119   * @{
00120   */
00121 #define LL_RNG_CR_IE   RNG_CR_IE      /*!< RNG Interrupt enable */
00122 /**
00123   * @}
00124   */
00125 
00126 /**
00127   * @}
00128   */
00129 
00130 /* Exported macro ------------------------------------------------------------*/
00131 /** @defgroup RNG_LL_Exported_Macros RNG Exported Macros
00132   * @{
00133   */
00134 
00135 /** @defgroup RNG_LL_EM_WRITE_READ Common Write and read registers Macros
00136   * @{
00137   */
00138 
00139 /**
00140   * @brief  Write a value in RNG register
00141   * @param  __INSTANCE__ RNG Instance
00142   * @param  __REG__ Register to be written
00143   * @param  __VALUE__ Value to be written in the register
00144   * @retval None
00145   */
00146 #define LL_RNG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
00147 
00148 /**
00149   * @brief  Read a value in RNG register
00150   * @param  __INSTANCE__ RNG Instance
00151   * @param  __REG__ Register to be read
00152   * @retval Register value
00153   */
00154 #define LL_RNG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
00155 /**
00156   * @}
00157   */
00158 
00159 /**
00160   * @}
00161   */
00162 
00163 
00164 /* Exported functions --------------------------------------------------------*/
00165 /** @defgroup RNG_LL_Exported_Functions RNG Exported Functions
00166   * @{
00167   */
00168 /** @defgroup RNG_LL_EF_Configuration RNG Configuration functions
00169   * @{
00170   */
00171 
00172 /**
00173   * @brief  Enable Random Number Generation
00174   * @rmtoll CR           RNGEN         LL_RNG_Enable
00175   * @param  RNGx RNG Instance
00176   * @retval None
00177   */
00178 __STATIC_INLINE void LL_RNG_Enable(RNG_TypeDef *RNGx)
00179 {
00180   SET_BIT(RNGx->CR, RNG_CR_RNGEN);
00181 }
00182 
00183 /**
00184   * @brief  Disable Random Number Generation
00185   * @rmtoll CR           RNGEN         LL_RNG_Disable
00186   * @param  RNGx RNG Instance
00187   * @retval None
00188   */
00189 __STATIC_INLINE void LL_RNG_Disable(RNG_TypeDef *RNGx)
00190 {
00191   CLEAR_BIT(RNGx->CR, RNG_CR_RNGEN);
00192 }
00193 
00194 /**
00195   * @brief  Check if Random Number Generator is enabled
00196   * @rmtoll CR           RNGEN         LL_RNG_IsEnabled
00197   * @param  RNGx RNG Instance
00198   * @retval State of bit (1 or 0).
00199   */
00200 __STATIC_INLINE uint32_t LL_RNG_IsEnabled(RNG_TypeDef *RNGx)
00201 {
00202   return (READ_BIT(RNGx->CR, RNG_CR_RNGEN) == (RNG_CR_RNGEN));
00203 }
00204 
00205 #if defined(RNG_CR_CED)
00206 /**
00207   * @brief  Enable RNG Clock Error Detection
00208   * @rmtoll CR           CED         LL_RNG_EnableClkErrorDetect
00209   * @param  RNGx RNG Instance
00210   * @retval None
00211   */
00212 __STATIC_INLINE void LL_RNG_EnableClkErrorDetect(RNG_TypeDef *RNGx)
00213 {
00214   CLEAR_BIT(RNGx->CR, RNG_CR_CED);
00215 }
00216 
00217 /**
00218   * @brief  Disable RNG Clock Error Detection
00219   * @rmtoll CR           CED         LL_RNG_DisableClkErrorDetect
00220   * @param  RNGx RNG Instance
00221   * @retval None
00222   */
00223 __STATIC_INLINE void LL_RNG_DisableClkErrorDetect(RNG_TypeDef *RNGx)
00224 {
00225   SET_BIT(RNGx->CR, RNG_CR_CED);
00226 }
00227 
00228 /**
00229   * @brief  Check if RNG Clock Error Detection is enabled
00230   * @rmtoll CR           CED         LL_RNG_IsEnabledClkErrorDetect
00231   * @param  RNGx RNG Instance
00232   * @retval State of bit (1 or 0).
00233   */
00234 __STATIC_INLINE uint32_t LL_RNG_IsEnabledClkErrorDetect(RNG_TypeDef *RNGx)
00235 {
00236   return (!(READ_BIT(RNGx->CR, RNG_CR_CED) == (RNG_CR_CED)));
00237 }
00238 #endif /* defined(RNG_CR_CED) */
00239 
00240 
00241 /**
00242   * @}
00243   */
00244 
00245 /** @defgroup RNG_LL_EF_FLAG_Management FLAG Management
00246   * @{
00247   */
00248 
00249 /**
00250   * @brief  Indicate if the RNG Data ready Flag is set or not
00251   * @rmtoll SR           DRDY          LL_RNG_IsActiveFlag_DRDY
00252   * @param  RNGx RNG Instance
00253   * @retval State of bit (1 or 0).
00254   */
00255 __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_DRDY(RNG_TypeDef *RNGx)
00256 {
00257   return (READ_BIT(RNGx->SR, RNG_SR_DRDY) == (RNG_SR_DRDY));
00258 }
00259 
00260 /**
00261   * @brief  Indicate if the Clock Error Current Status Flag is set or not
00262   * @rmtoll SR           CECS          LL_RNG_IsActiveFlag_CECS
00263   * @param  RNGx RNG Instance
00264   * @retval State of bit (1 or 0).
00265   */
00266 __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_CECS(RNG_TypeDef *RNGx)
00267 {
00268   return (READ_BIT(RNGx->SR, RNG_SR_CECS) == (RNG_SR_CECS));
00269 }
00270 
00271 /**
00272   * @brief  Indicate if the Seed Error Current Status Flag is set or not
00273   * @rmtoll SR           SECS          LL_RNG_IsActiveFlag_SECS
00274   * @param  RNGx RNG Instance
00275   * @retval State of bit (1 or 0).
00276   */
00277 __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_SECS(RNG_TypeDef *RNGx)
00278 {
00279   return (READ_BIT(RNGx->SR, RNG_SR_SECS) == (RNG_SR_SECS));
00280 }
00281 
00282 /**
00283   * @brief  Indicate if the Clock Error Interrupt Status Flag is set or not
00284   * @rmtoll SR           CEIS          LL_RNG_IsActiveFlag_CEIS
00285   * @param  RNGx RNG Instance
00286   * @retval State of bit (1 or 0).
00287   */
00288 __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_CEIS(RNG_TypeDef *RNGx)
00289 {
00290   return (READ_BIT(RNGx->SR, RNG_SR_CEIS) == (RNG_SR_CEIS));
00291 }
00292 
00293 /**
00294   * @brief  Indicate if the Seed Error Interrupt Status Flag is set or not
00295   * @rmtoll SR           SEIS          LL_RNG_IsActiveFlag_SEIS
00296   * @param  RNGx RNG Instance
00297   * @retval State of bit (1 or 0).
00298   */
00299 __STATIC_INLINE uint32_t LL_RNG_IsActiveFlag_SEIS(RNG_TypeDef *RNGx)
00300 {
00301   return (READ_BIT(RNGx->SR, RNG_SR_SEIS) == (RNG_SR_SEIS));
00302 }
00303 
00304 /**
00305   * @brief  Clear Clock Error interrupt Status (CEIS) Flag
00306   * @rmtoll SR           CEIS          LL_RNG_ClearFlag_CEIS
00307   * @param  RNGx RNG Instance
00308   * @retval None
00309   */
00310 __STATIC_INLINE void LL_RNG_ClearFlag_CEIS(RNG_TypeDef *RNGx)
00311 {
00312   WRITE_REG(RNGx->SR, ~RNG_SR_CEIS);
00313 }
00314 
00315 /**
00316   * @brief  Clear Seed Error interrupt Status (SEIS) Flag
00317   * @rmtoll SR           SEIS          LL_RNG_ClearFlag_SEIS
00318   * @param  RNGx RNG Instance
00319   * @retval None
00320   */
00321 __STATIC_INLINE void LL_RNG_ClearFlag_SEIS(RNG_TypeDef *RNGx)
00322 {
00323   WRITE_REG(RNGx->SR, ~RNG_SR_SEIS);
00324 }
00325 
00326 /**
00327   * @}
00328   */
00329 
00330 /** @defgroup RNG_LL_EF_IT_Management IT Management
00331   * @{
00332   */
00333 
00334 /**
00335   * @brief  Enable Random Number Generator Interrupt
00336   *         (applies for either Seed error, Clock Error or Data ready interrupts)
00337   * @rmtoll CR           IE            LL_RNG_EnableIT
00338   * @param  RNGx RNG Instance
00339   * @retval None
00340   */
00341 __STATIC_INLINE void LL_RNG_EnableIT(RNG_TypeDef *RNGx)
00342 {
00343   SET_BIT(RNGx->CR, RNG_CR_IE);
00344 }
00345 
00346 /**
00347   * @brief  Disable Random Number Generator Interrupt
00348   *         (applies for either Seed error, Clock Error or Data ready interrupts)
00349   * @rmtoll CR           IE            LL_RNG_DisableIT
00350   * @param  RNGx RNG Instance
00351   * @retval None
00352   */
00353 __STATIC_INLINE void LL_RNG_DisableIT(RNG_TypeDef *RNGx)
00354 {
00355   CLEAR_BIT(RNGx->CR, RNG_CR_IE);
00356 }
00357 
00358 /**
00359   * @brief  Check if Random Number Generator Interrupt is enabled
00360   *         (applies for either Seed error, Clock Error or Data ready interrupts)
00361   * @rmtoll CR           IE            LL_RNG_IsEnabledIT
00362   * @param  RNGx RNG Instance
00363   * @retval State of bit (1 or 0).
00364   */
00365 __STATIC_INLINE uint32_t LL_RNG_IsEnabledIT(RNG_TypeDef *RNGx)
00366 {
00367   return (READ_BIT(RNGx->CR, RNG_CR_IE) == (RNG_CR_IE));
00368 }
00369 
00370 /**
00371   * @}
00372   */
00373 
00374 /** @defgroup RNG_LL_EF_Data_Management Data Management
00375   * @{
00376   */
00377 
00378 /**
00379   * @brief  Return32-bit Random Number value
00380   * @rmtoll DR           RNDATA        LL_RNG_ReadRandData32
00381   * @param  RNGx RNG Instance
00382   * @retval Generated 32-bit random value
00383   */
00384 __STATIC_INLINE uint32_t LL_RNG_ReadRandData32(RNG_TypeDef *RNGx)
00385 {
00386   return (uint32_t)(READ_REG(RNGx->DR));
00387 }
00388 
00389 /**
00390   * @}
00391   */
00392 
00393 #if defined(USE_FULL_LL_DRIVER)
00394 /** @defgroup RNG_LL_EF_Init Initialization and de-initialization functions
00395   * @{
00396   */
00397 #if defined(RNG_CR_CED)
00398 ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct);
00399 void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct);
00400 #endif /* defined(RNG_CR_CED) */
00401 ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx);
00402 
00403 /**
00404   * @}
00405   */
00406 #endif /* USE_FULL_LL_DRIVER */
00407 
00408 /**
00409   * @}
00410   */
00411 
00412 /**
00413   * @}
00414   */
00415 
00416 #endif /* defined(RNG) */
00417 
00418 /**
00419   * @}
00420   */
00421 
00422 #ifdef __cplusplus
00423 }
00424 #endif
00425 
00426 #endif /* __STM32L4xx_LL_RNG_H */
00427 
00428 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/