STM32L443xx HAL User Manual
stm32l4xx_ll_rng.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_ll_rng.c
00004   * @author  MCD Application Team
00005   * @brief   RNG LL module driver.
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 #if defined(USE_FULL_LL_DRIVER)
00019 
00020 /* Includes ------------------------------------------------------------------*/
00021 #include "stm32l4xx_ll_rng.h"
00022 #include "stm32l4xx_ll_bus.h"
00023 
00024 #ifdef  USE_FULL_ASSERT
00025 #include "stm32_assert.h"
00026 #else
00027 #define assert_param(expr) ((void)0U)
00028 #endif
00029 
00030 /** @addtogroup STM32L4xx_LL_Driver
00031   * @{
00032   */
00033 
00034 #if defined (RNG)
00035 
00036 /** @addtogroup RNG_LL
00037   * @{
00038   */
00039 
00040 /* Private types -------------------------------------------------------------*/
00041 /* Private variables ---------------------------------------------------------*/
00042 /* Private constants ---------------------------------------------------------*/
00043 /* Private macros ------------------------------------------------------------*/
00044 #if defined(RNG_CR_CED)
00045 /** @addtogroup RNG_LL_Private_Macros
00046   * @{
00047   */
00048 #define IS_LL_RNG_CED(__MODE__) (((__MODE__) == LL_RNG_CED_ENABLE) || \
00049                                  ((__MODE__) == LL_RNG_CED_DISABLE))
00050 
00051 #if defined(RNG_CR_CONDRST)
00052 #define IS_LL_RNG_CLOCK_DIVIDER(__CLOCK_DIV__) ((__CLOCK_DIV__) <=0x0Fu)
00053 
00054 
00055 #define IS_LL_RNG_NIST_COMPLIANCE(__NIST_COMPLIANCE__) (((__NIST_COMPLIANCE__) == LL_RNG_NIST_COMPLIANT) || \
00056                                                      ((__NIST_COMPLIANCE__) == LL_RNG_NOTNIST_COMPLIANT))
00057 
00058 #define IS_LL_RNG_CONFIG1 (__CONFIG1__) ((__CONFIG1__) <= 0x3FUL)
00059 
00060 #define IS_LL_RNG_CONFIG2 (__CONFIG2__) ((__CONFIG2__) <= 0x07UL)
00061 
00062 #define IS_LL_RNG_CONFIG3 (__CONFIG3__) ((__CONFIG3__) <= 0xFUL)
00063 #endif /* end of RNG_CR_CONDRST*/
00064 /**
00065   * @}
00066   */
00067 #endif
00068 /* Private function prototypes -----------------------------------------------*/
00069 
00070 /* Exported functions --------------------------------------------------------*/
00071 /** @addtogroup RNG_LL_Exported_Functions
00072   * @{
00073   */
00074 
00075 /** @addtogroup RNG_LL_EF_Init
00076   * @{
00077   */
00078 
00079 /**
00080   * @brief  De-initialize RNG registers (Registers restored to their default values).
00081   * @param  RNGx RNG Instance
00082   * @retval An ErrorStatus enumeration value:
00083   *          - SUCCESS: RNG registers are de-initialized
00084   *          - ERROR: not applicable
00085   */
00086 ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx)
00087 {
00088   /* Check the parameters */
00089   assert_param(IS_RNG_ALL_INSTANCE(RNGx));
00090   /* Enable RNG reset state */
00091   LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_RNG);
00092 
00093   /* Release RNG from reset state */
00094   LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_RNG);
00095   return (SUCCESS);
00096 }
00097 
00098 #if defined(RNG_CR_CED)
00099 /**
00100   * @brief  Initialize RNG registers according to the specified parameters in RNG_InitStruct.
00101   * @param  RNGx RNG Instance
00102   * @param  RNG_InitStruct pointer to a LL_RNG_InitTypeDef structure
00103   *         that contains the configuration information for the specified RNG peripheral.
00104   * @retval An ErrorStatus enumeration value:
00105   *          - SUCCESS: RNG registers are initialized according to RNG_InitStruct content
00106   *          - ERROR: not applicable
00107   */
00108 ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct)
00109 {
00110   /* Check the parameters */
00111   assert_param(IS_RNG_ALL_INSTANCE(RNGx));
00112   assert_param(IS_LL_RNG_CED(RNG_InitStruct->ClockErrorDetection));
00113 
00114 #if defined(RNG_CR_CONDRST)
00115   /* Clock Error Detection Configuration when CONDRT bit is set to 1 */
00116   MODIFY_REG(RNGx->CR, RNG_CR_CED | RNG_CR_CONDRST, RNG_InitStruct->ClockErrorDetection | RNG_CR_CONDRST);
00117   /* Writing bits CONDRST=0*/
00118   CLEAR_BIT(RNGx->CR, RNG_CR_CONDRST);
00119 #else
00120   /* Clock Error Detection configuration */
00121   MODIFY_REG(RNGx->CR, RNG_CR_CED, RNG_InitStruct->ClockErrorDetection);
00122 #endif
00123 
00124   return (SUCCESS);
00125 }
00126 
00127 /**
00128   * @brief Set each @ref LL_RNG_InitTypeDef field to default value.
00129   * @param RNG_InitStruct pointer to a @ref LL_RNG_InitTypeDef structure
00130   *                       whose fields will be set to default values.
00131   * @retval None
00132   */
00133 void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct)
00134 {
00135   /* Set RNG_InitStruct fields to default values */
00136   RNG_InitStruct->ClockErrorDetection = LL_RNG_CED_ENABLE;
00137 
00138 }
00139 #endif
00140 /**
00141   * @}
00142   */
00143 
00144 /**
00145   * @}
00146   */
00147 
00148 /**
00149   * @}
00150   */
00151 
00152 #endif /* RNG */
00153 
00154 /**
00155   * @}
00156   */
00157 
00158 #endif /* USE_FULL_LL_DRIVER */