xref: /btstack/port/stm32-l451-miromico-sx1280/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_rng.c (revision 2fd737d36a1de5d778cacc671d4b4d8c4f3fed82)
1 /**
2   ******************************************************************************
3   * @file    stm32l4xx_ll_rng.c
4   * @author  MCD Application Team
5   * @brief   RNG LL module driver.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
10   * All rights reserved.</center></h2>
11   *
12   * This software component is licensed by ST under BSD 3-Clause license,
13   * the "License"; You may not use this file except in compliance with the
14   * License. You may obtain a copy of the License at:
15   *                        opensource.org/licenses/BSD-3-Clause
16   *
17   ******************************************************************************
18   */
19 #if defined(USE_FULL_LL_DRIVER)
20 
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32l4xx_ll_rng.h"
23 #include "stm32l4xx_ll_bus.h"
24 
25 #ifdef  USE_FULL_ASSERT
26 #include "stm32_assert.h"
27 #else
28 #define assert_param(expr) ((void)0U)
29 #endif
30 
31 /** @addtogroup STM32L4xx_LL_Driver
32   * @{
33   */
34 
35 #if defined (RNG)
36 
37 /** @addtogroup RNG_LL
38   * @{
39   */
40 
41 /* Private types -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 /* Private constants ---------------------------------------------------------*/
44 /* Private macros ------------------------------------------------------------*/
45 #if defined(RNG_CR_CED)
46 /** @addtogroup RNG_LL_Private_Macros
47   * @{
48   */
49 #define IS_LL_RNG_CED(__MODE__) (((__MODE__) == LL_RNG_CED_ENABLE) || \
50                                  ((__MODE__) == LL_RNG_CED_DISABLE))
51 
52 #if defined(RNG_CR_CONDRST)
53 #define IS_LL_RNG_CLOCK_DIVIDER(__CLOCK_DIV__) ((__CLOCK_DIV__) <=0x0Fu)
54 
55 
56 #define IS_LL_RNG_NIST_COMPLIANCE(__NIST_COMPLIANCE__) (((__NIST_COMPLIANCE__) == LL_RNG_NIST_COMPLIANT) || \
57                                                      ((__NIST_COMPLIANCE__) == LL_RNG_NOTNIST_COMPLIANT))
58 
59 #define IS_LL_RNG_CONFIG1 (__CONFIG1__) ((__CONFIG1__) <= 0x3FUL)
60 
61 #define IS_LL_RNG_CONFIG2 (__CONFIG2__) ((__CONFIG2__) <= 0x07UL)
62 
63 #define IS_LL_RNG_CONFIG3 (__CONFIG3__) ((__CONFIG3__) <= 0xFUL)
64 #endif /* end of RNG_CR_CONDRST*/
65 /**
66   * @}
67   */
68 #endif
69 /* Private function prototypes -----------------------------------------------*/
70 
71 /* Exported functions --------------------------------------------------------*/
72 /** @addtogroup RNG_LL_Exported_Functions
73   * @{
74   */
75 
76 /** @addtogroup RNG_LL_EF_Init
77   * @{
78   */
79 
80 /**
81   * @brief  De-initialize RNG registers (Registers restored to their default values).
82   * @param  RNGx RNG Instance
83   * @retval An ErrorStatus enumeration value:
84   *          - SUCCESS: RNG registers are de-initialized
85   *          - ERROR: not applicable
86   */
LL_RNG_DeInit(RNG_TypeDef * RNGx)87 ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx)
88 {
89   /* Check the parameters */
90   assert_param(IS_RNG_ALL_INSTANCE(RNGx));
91   /* Enable RNG reset state */
92   LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_RNG);
93 
94   /* Release RNG from reset state */
95   LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_RNG);
96   return (SUCCESS);
97 }
98 
99 #if defined(RNG_CR_CED)
100 /**
101   * @brief  Initialize RNG registers according to the specified parameters in RNG_InitStruct.
102   * @param  RNGx RNG Instance
103   * @param  RNG_InitStruct pointer to a LL_RNG_InitTypeDef structure
104   *         that contains the configuration information for the specified RNG peripheral.
105   * @retval An ErrorStatus enumeration value:
106   *          - SUCCESS: RNG registers are initialized according to RNG_InitStruct content
107   *          - ERROR: not applicable
108   */
LL_RNG_Init(RNG_TypeDef * RNGx,LL_RNG_InitTypeDef * RNG_InitStruct)109 ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct)
110 {
111   /* Check the parameters */
112   assert_param(IS_RNG_ALL_INSTANCE(RNGx));
113   assert_param(IS_LL_RNG_CED(RNG_InitStruct->ClockErrorDetection));
114 
115 #if defined(RNG_CR_CONDRST)
116   /* Clock Error Detection Configuration when CONDRT bit is set to 1 */
117   MODIFY_REG(RNGx->CR, RNG_CR_CED | RNG_CR_CONDRST, RNG_InitStruct->ClockErrorDetection | RNG_CR_CONDRST);
118   /* Writing bits CONDRST=0*/
119   CLEAR_BIT(RNGx->CR, RNG_CR_CONDRST);
120 #else
121   /* Clock Error Detection configuration */
122   MODIFY_REG(RNGx->CR, RNG_CR_CED, RNG_InitStruct->ClockErrorDetection);
123 #endif
124 
125   return (SUCCESS);
126 }
127 
128 /**
129   * @brief Set each @ref LL_RNG_InitTypeDef field to default value.
130   * @param RNG_InitStruct pointer to a @ref LL_RNG_InitTypeDef structure
131   *                       whose fields will be set to default values.
132   * @retval None
133   */
LL_RNG_StructInit(LL_RNG_InitTypeDef * RNG_InitStruct)134 void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct)
135 {
136   /* Set RNG_InitStruct fields to default values */
137   RNG_InitStruct->ClockErrorDetection = LL_RNG_CED_ENABLE;
138 
139 }
140 #endif
141 /**
142   * @}
143   */
144 
145 /**
146   * @}
147   */
148 
149 /**
150   * @}
151   */
152 
153 #endif /* RNG */
154 
155 /**
156   * @}
157   */
158 
159 #endif /* USE_FULL_LL_DRIVER */
160 
161 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
162 
163