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 /* USE_FULL_ASSERT */
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 /** @defgroup RNG_LL_Private_Macros RNG 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 /* RNG_CR_CONDRST */
64 /**
65   * @}
66   */
67 #endif /* RNG_CR_CED */
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(const RNG_TypeDef * RNGx)86 ErrorStatus LL_RNG_DeInit(const RNG_TypeDef *RNGx)
87 {
88   ErrorStatus status = SUCCESS;
89 
90   /* Check the parameters */
91   assert_param(IS_RNG_ALL_INSTANCE(RNGx));
92   if (RNGx == RNG)
93   {
94     /* Enable RNG reset state */
95     LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_RNG);
96 
97     /* Release RNG from reset state */
98     LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_RNG);
99   }
100   else
101   {
102     status = ERROR;
103   }
104 
105   return status;
106 }
107 
108 #if defined(RNG_CR_CED)
109 /**
110   * @brief  Initialize RNG registers according to the specified parameters in RNG_InitStruct.
111   * @param  RNGx RNG Instance
112   * @param  RNG_InitStruct pointer to a LL_RNG_InitTypeDef structure
113   *         that contains the configuration information for the specified RNG peripheral.
114   * @retval An ErrorStatus enumeration value:
115   *          - SUCCESS: RNG registers are initialized according to RNG_InitStruct content
116   *          - ERROR: not applicable
117   */
LL_RNG_Init(RNG_TypeDef * RNGx,const LL_RNG_InitTypeDef * RNG_InitStruct)118 ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, const LL_RNG_InitTypeDef *RNG_InitStruct)
119 {
120   /* Check the parameters */
121   assert_param(IS_RNG_ALL_INSTANCE(RNGx));
122   assert_param(IS_LL_RNG_CED(RNG_InitStruct->ClockErrorDetection));
123 
124 #if defined(RNG_CR_CONDRST)
125   /* Clock Error Detection Configuration when CONDRT bit is set to 1 */
126   MODIFY_REG(RNGx->CR, RNG_CR_CED | RNG_CR_CONDRST, RNG_InitStruct->ClockErrorDetection | RNG_CR_CONDRST);
127   /* Writing bits CONDRST=0*/
128   CLEAR_BIT(RNGx->CR, RNG_CR_CONDRST);
129 #else
130   /* Clock Error Detection configuration */
131   MODIFY_REG(RNGx->CR, RNG_CR_CED, RNG_InitStruct->ClockErrorDetection);
132 #endif /* RNG_CR_CONDRST */
133 
134   return (SUCCESS);
135 }
136 
137 /**
138   * @brief Set each @ref LL_RNG_InitTypeDef field to default value.
139   * @param RNG_InitStruct pointer to a @ref LL_RNG_InitTypeDef structure
140   *                       whose fields will be set to default values.
141   * @retval None
142   */
LL_RNG_StructInit(LL_RNG_InitTypeDef * RNG_InitStruct)143 void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct)
144 {
145   /* Set RNG_InitStruct fields to default values */
146   RNG_InitStruct->ClockErrorDetection = LL_RNG_CED_ENABLE;
147 
148 }
149 #endif /* RNG_CR_CED */
150 /**
151   * @}
152   */
153 
154 /**
155   * @}
156   */
157 
158 /**
159   * @}
160   */
161 
162 #endif /* RNG */
163 
164 /**
165   * @}
166   */
167 
168 #endif /* USE_FULL_LL_DRIVER */
169