1 /** 2 ****************************************************************************** 3 * @file stm32wlxx_ll_rng.c 4 * @author MCD Application Team 5 * @brief RNG LL module driver. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2020 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 "stm32wlxx_ll_rng.h" 22 #include "stm32wlxx_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 STM32WLxx_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 #define IS_LL_RNG_CLOCK_DIVIDER(__CLOCK_DIV__) ((__CLOCK_DIV__) <=0x0Fu) 51 52 53 #define IS_LL_RNG_NIST_COMPLIANCE(__NIST_COMPLIANCE__) (((__NIST_COMPLIANCE__) == LL_RNG_NIST_COMPLIANT) || \ 54 ((__NIST_COMPLIANCE__) == LL_RNG_NOTNIST_COMPLIANT)) 55 56 #define IS_LL_RNG_CONFIG1 (__CONFIG1__) ((__CONFIG1__) <= 0x3FUL) 57 58 #define IS_LL_RNG_CONFIG2 (__CONFIG2__) ((__CONFIG2__) <= 0x07UL) 59 60 #define IS_LL_RNG_CONFIG3 (__CONFIG3__) ((__CONFIG3__) <= 0xFUL) 61 /** 62 * @} 63 */ 64 /* Private function prototypes -----------------------------------------------*/ 65 66 /* Exported functions --------------------------------------------------------*/ 67 /** @addtogroup RNG_LL_Exported_Functions 68 * @{ 69 */ 70 71 /** @addtogroup RNG_LL_EF_Init 72 * @{ 73 */ 74 75 /** 76 * @brief De-initialize RNG registers (Registers restored to their default values). 77 * @param RNGx RNG Instance 78 * @retval An ErrorStatus enumeration value: 79 * - SUCCESS: RNG registers are de-initialized 80 * - ERROR: not applicable 81 */ LL_RNG_DeInit(RNG_TypeDef * RNGx)82ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx) 83 { 84 /* Check the parameters */ 85 assert_param(IS_RNG_ALL_INSTANCE(RNGx)); 86 /* Enable RNG reset state */ 87 LL_AHB3_GRP1_ForceReset(LL_AHB3_GRP1_PERIPH_RNG); 88 89 /* Release RNG from reset state */ 90 LL_AHB3_GRP1_ReleaseReset(LL_AHB3_GRP1_PERIPH_RNG); 91 return (SUCCESS); 92 } 93 94 /** 95 * @brief Initialize RNG registers according to the specified parameters in RNG_InitStruct. 96 * @param RNGx RNG Instance 97 * @param RNG_InitStruct pointer to a LL_RNG_InitTypeDef structure 98 * that contains the configuration information for the specified RNG peripheral. 99 * @retval An ErrorStatus enumeration value: 100 * - SUCCESS: RNG registers are initialized according to RNG_InitStruct content 101 * - ERROR: not applicable 102 */ LL_RNG_Init(RNG_TypeDef * RNGx,LL_RNG_InitTypeDef * RNG_InitStruct)103ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct) 104 { 105 /* Check the parameters */ 106 assert_param(IS_RNG_ALL_INSTANCE(RNGx)); 107 assert_param(IS_LL_RNG_CED(RNG_InitStruct->ClockErrorDetection)); 108 109 /* Clock Error Detection Configuration when CONDRT bit is set to 1 */ 110 MODIFY_REG(RNGx->CR, RNG_CR_CED | RNG_CR_CONDRST, RNG_InitStruct->ClockErrorDetection | RNG_CR_CONDRST); 111 /* Writing bits CONDRST=0*/ 112 CLEAR_BIT(RNGx->CR, RNG_CR_CONDRST); 113 114 return (SUCCESS); 115 } 116 117 /** 118 * @brief Set each @ref LL_RNG_InitTypeDef field to default value. 119 * @param RNG_InitStruct pointer to a @ref LL_RNG_InitTypeDef structure 120 * whose fields will be set to default values. 121 * @retval None 122 */ LL_RNG_StructInit(LL_RNG_InitTypeDef * RNG_InitStruct)123void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct) 124 { 125 /* Set RNG_InitStruct fields to default values */ 126 RNG_InitStruct->ClockErrorDetection = LL_RNG_CED_ENABLE; 127 128 } 129 /** 130 * @} 131 */ 132 133 /** 134 * @} 135 */ 136 137 /** 138 * @} 139 */ 140 141 #endif /* RNG */ 142 143 /** 144 * @} 145 */ 146 147 #endif /* USE_FULL_LL_DRIVER */ 148 149