Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:10

0001 /**
0002   ******************************************************************************
0003   * @file    stm32h7xx_ll_rng.c
0004   * @author  MCD Application Team
0005   * @brief   RNG LL module driver.
0006   ******************************************************************************
0007   * @attention
0008   *
0009   * Copyright (c) 2017 STMicroelectronics.
0010   * All rights reserved.
0011   *
0012   * This software is licensed under terms that can be found in the LICENSE file
0013   * in the root directory of this software component.
0014   * If no LICENSE file comes with this software, it is provided AS-IS.
0015   *
0016   ******************************************************************************
0017   */
0018 #if defined(USE_FULL_LL_DRIVER) || defined(__rtems__)
0019 
0020 /* Includes ------------------------------------------------------------------*/
0021 #include "stm32h7xx_ll_rng.h"
0022 #include "stm32h7xx_ll_bus.h"
0023 
0024 #ifdef  USE_FULL_ASSERT
0025 #include "stm32_assert.h"
0026 #else
0027 #define assert_param(expr) ((void)0U)
0028 #endif /* USE_FULL_ASSERT */
0029 
0030 /** @addtogroup STM32H7xx_LL_Driver
0031   * @{
0032   */
0033 
0034 #if defined (RNG)
0035 
0036 /** @addtogroup RNG_LL
0037   * @{
0038   */
0039 
0040 /* Private types -------------------------------------------------------------*/
0041 /* Private variables ---------------------------------------------------------*/
0042 /* Private constants ---------------------------------------------------------*/
0043 /* Private macros ------------------------------------------------------------*/
0044 /** @defgroup RNG_LL_Private_Macros RNG Private Macros
0045   * @ingroup RTEMSBSPsARMSTM32H7
0046   * @{
0047   */
0048 #define IS_LL_RNG_CED(__MODE__) (((__MODE__) == LL_RNG_CED_ENABLE) || \
0049                                  ((__MODE__) == LL_RNG_CED_DISABLE))
0050 
0051 #if defined(RNG_CR_CONDRST)
0052 #define IS_LL_RNG_CLOCK_DIVIDER(__CLOCK_DIV__) ((__CLOCK_DIV__) <=0x0Fu)
0053 
0054 
0055 #define IS_LL_RNG_NIST_COMPLIANCE(__NIST_COMPLIANCE__) (((__NIST_COMPLIANCE__) == LL_RNG_NIST_COMPLIANT) || \
0056                                                         ((__NIST_COMPLIANCE__) == LL_RNG_NOTNIST_COMPLIANT))
0057 
0058 #define IS_LL_RNG_CONFIG1 (__CONFIG1__) ((__CONFIG1__) <= 0x3FUL)
0059 
0060 #define IS_LL_RNG_CONFIG2 (__CONFIG2__) ((__CONFIG2__) <= 0x07UL)
0061 
0062 #define IS_LL_RNG_CONFIG3 (__CONFIG3__) ((__CONFIG3__) <= 0xFUL)
0063 #endif /* RNG_CR_CONDRST */
0064 /**
0065   * @}
0066   */
0067 /* Private function prototypes -----------------------------------------------*/
0068 
0069 /* Exported functions --------------------------------------------------------*/
0070 /** @addtogroup RNG_LL_Exported_Functions
0071   * @{
0072   */
0073 
0074 /** @addtogroup RNG_LL_EF_Init
0075   * @{
0076   */
0077 
0078 /**
0079   * @brief  De-initialize RNG registers (Registers restored to their default values).
0080   * @param  RNGx RNG Instance
0081   * @retval An ErrorStatus enumeration value:
0082   *          - SUCCESS: RNG registers are de-initialized
0083   *          - ERROR: not applicable
0084   */
0085 ErrorStatus LL_RNG_DeInit(const RNG_TypeDef *RNGx)
0086 {
0087   ErrorStatus status = SUCCESS;
0088 
0089   /* Check the parameters */
0090   assert_param(IS_RNG_ALL_INSTANCE(RNGx));
0091   if (RNGx == RNG)
0092   {
0093     /* Enable RNG reset state */
0094     LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_RNG);
0095 
0096     /* Release RNG from reset state */
0097     LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_RNG);
0098   }
0099   else
0100   {
0101     status = ERROR;
0102   }
0103 
0104   return status;
0105 }
0106 
0107 /**
0108   * @brief  Initialize RNG registers according to the specified parameters in RNG_InitStruct.
0109   * @param  RNGx RNG Instance
0110   * @param  RNG_InitStruct pointer to a LL_RNG_InitTypeDef structure
0111   *         that contains the configuration information for the specified RNG peripheral.
0112   * @retval An ErrorStatus enumeration value:
0113   *          - SUCCESS: RNG registers are initialized according to RNG_InitStruct content
0114   *          - ERROR: not applicable
0115   */
0116 ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct)
0117 {
0118   /* Check the parameters */
0119   assert_param(IS_RNG_ALL_INSTANCE(RNGx));
0120   assert_param(IS_LL_RNG_CED(RNG_InitStruct->ClockErrorDetection));
0121 
0122 #if defined(RNG_CR_CONDRST)
0123   /* Clock Error Detection Configuration when CONDRT bit is set to 1 */
0124   MODIFY_REG(RNGx->CR, RNG_CR_CED | RNG_CR_CONDRST, RNG_InitStruct->ClockErrorDetection | RNG_CR_CONDRST);
0125   /* Writing bits CONDRST=0*/
0126   CLEAR_BIT(RNGx->CR, RNG_CR_CONDRST);
0127 #else
0128   /* Clock Error Detection configuration */
0129   MODIFY_REG(RNGx->CR, RNG_CR_CED, RNG_InitStruct->ClockErrorDetection);
0130 #endif /* RNG_CR_CONDRST */
0131 
0132   return (SUCCESS);
0133 }
0134 
0135 /**
0136   * @brief Set each @ref LL_RNG_InitTypeDef field to default value.
0137   * @param RNG_InitStruct pointer to a @ref LL_RNG_InitTypeDef structure
0138   *                       whose fields will be set to default values.
0139   * @retval None
0140   */
0141 void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct)
0142 {
0143   /* Set RNG_InitStruct fields to default values */
0144   RNG_InitStruct->ClockErrorDetection = LL_RNG_CED_ENABLE;
0145 
0146 }
0147 /**
0148   * @}
0149   */
0150 
0151 /**
0152   * @}
0153   */
0154 
0155 /**
0156   * @}
0157   */
0158 
0159 #endif /* RNG */
0160 
0161 /**
0162   * @}
0163   */
0164 
0165 #endif /* USE_FULL_LL_DRIVER */
0166