1 /** 2 ****************************************************************************** 3 * @file stm32l4xx_ll_rng.c 4 * @author MCD Application Team 5 * @brief RNG LL module driver. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2017 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 #if defined(USE_FULL_LL_DRIVER) 19 20 /* Includes ------------------------------------------------------------------*/ 21 #include "stm32l4xx_ll_rng.h" 22 #include "stm32l4xx_ll_bus.h" 23 24 #ifdef USE_FULL_ASSERT 25 #include "stm32_assert.h" 26 #else 27 #define assert_param(expr) ((void)0U) 28 #endif 29 30 /** @addtogroup STM32L4xx_LL_Driver 31 * @{ 32 */ 33 34 #if defined (RNG) 35 36 /** @addtogroup RNG_LL 37 * @{ 38 */ 39 40 /* Private types -------------------------------------------------------------*/ 41 /* Private variables ---------------------------------------------------------*/ 42 /* Private constants ---------------------------------------------------------*/ 43 /* Private macros ------------------------------------------------------------*/ 44 #if defined(RNG_CR_CED) 45 /** @addtogroup RNG_LL_Private_Macros 46 * @{ 47 */ 48 #define IS_LL_RNG_CED(__MODE__) (((__MODE__) == LL_RNG_CED_ENABLE) || \ 49 ((__MODE__) == LL_RNG_CED_DISABLE)) 50 51 #if defined(RNG_CR_CONDRST) 52 #define IS_LL_RNG_CLOCK_DIVIDER(__CLOCK_DIV__) ((__CLOCK_DIV__) <=0x0Fu) 53 54 55 #define IS_LL_RNG_NIST_COMPLIANCE(__NIST_COMPLIANCE__) (((__NIST_COMPLIANCE__) == LL_RNG_NIST_COMPLIANT) || \ 56 ((__NIST_COMPLIANCE__) == LL_RNG_NOTNIST_COMPLIANT)) 57 58 #define IS_LL_RNG_CONFIG1 (__CONFIG1__) ((__CONFIG1__) <= 0x3FUL) 59 60 #define IS_LL_RNG_CONFIG2 (__CONFIG2__) ((__CONFIG2__) <= 0x07UL) 61 62 #define IS_LL_RNG_CONFIG3 (__CONFIG3__) ((__CONFIG3__) <= 0xFUL) 63 #endif /* end of RNG_CR_CONDRST*/ 64 /** 65 * @} 66 */ 67 #endif 68 /* Private function prototypes -----------------------------------------------*/ 69 70 /* Exported functions --------------------------------------------------------*/ 71 /** @addtogroup RNG_LL_Exported_Functions 72 * @{ 73 */ 74 75 /** @addtogroup RNG_LL_EF_Init 76 * @{ 77 */ 78 79 /** 80 * @brief De-initialize RNG registers (Registers restored to their default values). 81 * @param RNGx RNG Instance 82 * @retval An ErrorStatus enumeration value: 83 * - SUCCESS: RNG registers are de-initialized 84 * - ERROR: not applicable 85 */ LL_RNG_DeInit(RNG_TypeDef * RNGx)86ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx) 87 { 88 /* Check the parameters */ 89 assert_param(IS_RNG_ALL_INSTANCE(RNGx)); 90 /* Enable RNG reset state */ 91 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_RNG); 92 93 /* Release RNG from reset state */ 94 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_RNG); 95 return (SUCCESS); 96 } 97 98 #if defined(RNG_CR_CED) 99 /** 100 * @brief Initialize RNG registers according to the specified parameters in RNG_InitStruct. 101 * @param RNGx RNG Instance 102 * @param RNG_InitStruct pointer to a LL_RNG_InitTypeDef structure 103 * that contains the configuration information for the specified RNG peripheral. 104 * @retval An ErrorStatus enumeration value: 105 * - SUCCESS: RNG registers are initialized according to RNG_InitStruct content 106 * - ERROR: not applicable 107 */ LL_RNG_Init(RNG_TypeDef * RNGx,LL_RNG_InitTypeDef * RNG_InitStruct)108ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct) 109 { 110 /* Check the parameters */ 111 assert_param(IS_RNG_ALL_INSTANCE(RNGx)); 112 assert_param(IS_LL_RNG_CED(RNG_InitStruct->ClockErrorDetection)); 113 114 #if defined(RNG_CR_CONDRST) 115 /* Clock Error Detection Configuration when CONDRT bit is set to 1 */ 116 MODIFY_REG(RNGx->CR, RNG_CR_CED | RNG_CR_CONDRST, RNG_InitStruct->ClockErrorDetection | RNG_CR_CONDRST); 117 /* Writing bits CONDRST=0*/ 118 CLEAR_BIT(RNGx->CR, RNG_CR_CONDRST); 119 #else 120 /* Clock Error Detection configuration */ 121 MODIFY_REG(RNGx->CR, RNG_CR_CED, RNG_InitStruct->ClockErrorDetection); 122 #endif 123 124 return (SUCCESS); 125 } 126 127 /** 128 * @brief Set each @ref LL_RNG_InitTypeDef field to default value. 129 * @param RNG_InitStruct pointer to a @ref LL_RNG_InitTypeDef structure 130 * whose fields will be set to default values. 131 * @retval None 132 */ LL_RNG_StructInit(LL_RNG_InitTypeDef * RNG_InitStruct)133void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct) 134 { 135 /* Set RNG_InitStruct fields to default values */ 136 RNG_InitStruct->ClockErrorDetection = LL_RNG_CED_ENABLE; 137 138 } 139 #endif 140 /** 141 * @} 142 */ 143 144 /** 145 * @} 146 */ 147 148 /** 149 * @} 150 */ 151 152 #endif /* RNG */ 153 154 /** 155 * @} 156 */ 157 158 #endif /* USE_FULL_LL_DRIVER */ 159