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