1 /** 2 ****************************************************************************** 3 * @file stm32h7xx_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 "stm32h7xx_ll_rng.h" 22 #include "stm32h7xx_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 /* USE_FULL_ASSERT */ 29 30 /** @addtogroup STM32H7xx_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 /** @defgroup RNG_LL_Private_Macros RNG Private Macros 45 * @{ 46 */ 47 #define IS_LL_RNG_CED(__MODE__) (((__MODE__) == LL_RNG_CED_ENABLE) || \ 48 ((__MODE__) == LL_RNG_CED_DISABLE)) 49 50 #if defined(RNG_CR_CONDRST) 51 #define IS_LL_RNG_CLOCK_DIVIDER(__CLOCK_DIV__) ((__CLOCK_DIV__) <=0x0Fu) 52 53 54 #define IS_LL_RNG_NIST_COMPLIANCE(__NIST_COMPLIANCE__) (((__NIST_COMPLIANCE__) == LL_RNG_NIST_COMPLIANT) || \ 55 ((__NIST_COMPLIANCE__) == LL_RNG_NOTNIST_COMPLIANT)) 56 57 #define IS_LL_RNG_CONFIG1 (__CONFIG1__) ((__CONFIG1__) <= 0x3FUL) 58 59 #define IS_LL_RNG_CONFIG2 (__CONFIG2__) ((__CONFIG2__) <= 0x07UL) 60 61 #define IS_LL_RNG_CONFIG3 (__CONFIG3__) ((__CONFIG3__) <= 0xFUL) 62 #endif /* RNG_CR_CONDRST*/ 63 /** 64 * @} 65 */ 66 /* Private function prototypes -----------------------------------------------*/ 67 68 /* Exported functions --------------------------------------------------------*/ 69 /** @addtogroup RNG_LL_Exported_Functions 70 * @{ 71 */ 72 73 /** @addtogroup RNG_LL_EF_Init 74 * @{ 75 */ 76 77 /** 78 * @brief De-initialize RNG registers (Registers restored to their default values). 79 * @param RNGx RNG Instance 80 * @retval An ErrorStatus enumeration value: 81 * - SUCCESS: RNG registers are de-initialized 82 * - ERROR: not applicable 83 */ LL_RNG_DeInit(RNG_TypeDef * RNGx)84ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx) 85 { 86 ErrorStatus status = SUCCESS; 87 88 /* Check the parameters */ 89 assert_param(IS_RNG_ALL_INSTANCE(RNGx)); 90 if (RNGx == RNG) 91 { 92 /* Enable RNG reset state */ 93 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_RNG); 94 95 /* Release RNG from reset state */ 96 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_RNG); 97 } 98 else 99 { 100 status = ERROR; 101 } 102 103 return status; 104 } 105 106 /** 107 * @brief Initialize RNG registers according to the specified parameters in RNG_InitStruct. 108 * @param RNGx RNG Instance 109 * @param RNG_InitStruct pointer to a LL_RNG_InitTypeDef structure 110 * that contains the configuration information for the specified RNG peripheral. 111 * @retval An ErrorStatus enumeration value: 112 * - SUCCESS: RNG registers are initialized according to RNG_InitStruct content 113 * - ERROR: not applicable 114 */ LL_RNG_Init(RNG_TypeDef * RNGx,LL_RNG_InitTypeDef * RNG_InitStruct)115ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct) 116 { 117 /* Check the parameters */ 118 assert_param(IS_RNG_ALL_INSTANCE(RNGx)); 119 assert_param(IS_LL_RNG_CED(RNG_InitStruct->ClockErrorDetection)); 120 121 #if defined(RNG_CR_CONDRST) 122 /* Clock Error Detection Configuration when CONDRT bit is set to 1 */ 123 MODIFY_REG(RNGx->CR, RNG_CR_CED | RNG_CR_CONDRST, RNG_InitStruct->ClockErrorDetection | RNG_CR_CONDRST); 124 /* Writing bits CONDRST=0*/ 125 CLEAR_BIT(RNGx->CR, RNG_CR_CONDRST); 126 #else 127 /* Clock Error Detection configuration */ 128 MODIFY_REG(RNGx->CR, RNG_CR_CED, RNG_InitStruct->ClockErrorDetection); 129 #endif /* RNG_CR_CONDRST */ 130 131 return (SUCCESS); 132 } 133 134 /** 135 * @brief Set each @ref LL_RNG_InitTypeDef field to default value. 136 * @param RNG_InitStruct pointer to a @ref LL_RNG_InitTypeDef structure 137 * whose fields will be set to default values. 138 * @retval None 139 */ LL_RNG_StructInit(LL_RNG_InitTypeDef * RNG_InitStruct)140void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct) 141 { 142 /* Set RNG_InitStruct fields to default values */ 143 RNG_InitStruct->ClockErrorDetection = LL_RNG_CED_ENABLE; 144 145 } 146 /** 147 * @} 148 */ 149 150 /** 151 * @} 152 */ 153 154 /** 155 * @} 156 */ 157 158 #endif /* RNG */ 159 160 /** 161 * @} 162 */ 163 164 #endif /* USE_FULL_LL_DRIVER */ 165 166