1 /** 2 ****************************************************************************** 3 * @file stm32wbaxx_ll_rng.c 4 * @author MCD Application Team 5 * @brief RNG LL module driver. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2022 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 "stm32wbaxx_ll_rng.h" 22 #include "stm32wbaxx_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 STM32WBAxx_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(const RNG_TypeDef * RNGx)82ErrorStatus LL_RNG_DeInit(const RNG_TypeDef *RNGx) 83 { 84 ErrorStatus status = SUCCESS; 85 86 /* Check the parameters */ 87 assert_param(IS_RNG_ALL_INSTANCE(RNGx)); 88 if (RNGx == RNG) 89 { 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 } 96 else 97 { 98 status = ERROR; 99 } 100 101 return status; 102 } 103 104 /** 105 * @brief Initialize RNG registers according to the specified parameters in RNG_InitStruct. 106 * @param RNGx RNG Instance 107 * @param RNG_InitStruct pointer to a LL_RNG_InitTypeDef structure 108 * that contains the configuration information for the specified RNG peripheral. 109 * @retval An ErrorStatus enumeration value: 110 * - SUCCESS: RNG registers are initialized according to RNG_InitStruct content 111 * - ERROR: not applicable 112 */ LL_RNG_Init(RNG_TypeDef * RNGx,LL_RNG_InitTypeDef * RNG_InitStruct)113ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct) 114 { 115 /* Check the parameters */ 116 assert_param(IS_RNG_ALL_INSTANCE(RNGx)); 117 assert_param(IS_LL_RNG_CED(RNG_InitStruct->ClockErrorDetection)); 118 119 /* Clock Error Detection Configuration when CONDRT bit is set to 1 */ 120 MODIFY_REG(RNGx->CR, RNG_CR_CED | RNG_CR_CONDRST, RNG_InitStruct->ClockErrorDetection | RNG_CR_CONDRST); 121 /* Writing bits CONDRST=0*/ 122 CLEAR_BIT(RNGx->CR, RNG_CR_CONDRST); 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 /** 140 * @} 141 */ 142 143 /** 144 * @} 145 */ 146 147 /** 148 * @} 149 */ 150 151 #endif /* RNG */ 152 153 /** 154 * @} 155 */ 156 157 #endif /* USE_FULL_LL_DRIVER */ 158 159