1 /**
2   ******************************************************************************
3   * @file    stm32wlxx_hal_rng_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of RNG HAL Extension module.
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 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32WLxx_HAL_RNG_EX_H
21 #define STM32WLxx_HAL_RNG_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32wlxx_hal_def.h"
29 
30 /** @addtogroup STM32WLxx_HAL_Driver
31   * @{
32   */
33 
34 #if defined(RNG)
35 #if defined(RNG_CR_CONDRST)
36 
37 /** @defgroup RNG_Ex RNG_Ex
38   * @brief RNG Extension HAL module driver
39   * @{
40   */
41 
42 /* Exported types ------------------------------------------------------------*/
43 /** @defgroup RNG_Ex_Exported_Types RNG_Ex Exported Types
44   * @brief RNG_Ex Exported types
45   * @{
46   */
47 
48 /**
49   * @brief RNG_Ex Configuration Structure definition
50   */
51 
52 typedef struct
53 {
54   uint32_t        Config1;           /*!< Config1 must be a value between 0 and 0x3F */
55   uint32_t        Config2;           /*!< Config2 must be a value between 0 and 0x7 */
56   uint32_t        Config3;           /*!< Config3 must be a value between 0 and 0xF */
57   uint32_t        ClockDivider;      /*!< Clock Divider factor.This parameter can
58                                           be a value of @ref RNG_Ex_Clock_Divider_Factor   */
59   uint32_t        NistCompliance;    /*!< NIST compliance.This parameter can be a
60                                           value of @ref RNG_Ex_NIST_Compliance   */
61 } RNG_ConfigTypeDef;
62 
63 /**
64   * @}
65   */
66 
67 /* Exported constants --------------------------------------------------------*/
68 /** @defgroup RNG_Ex_Exported_Constants RNG_Ex Exported Constants
69   * @{
70   */
71 
72 /** @defgroup RNG_Ex_Clock_Divider_Factor  Value used to configure an internal
73   *            programmable divider acting on the incoming RNG clock
74   * @{
75   */
76 #define RNG_CLKDIV_BY_1       (0x00000000UL)      /*!< No clock division  */
77 #define RNG_CLKDIV_BY_2       (RNG_CR_CLKDIV_0)
78 /*!< 2 RNG clock cycles per internal RNG clock    */
79 #define RNG_CLKDIV_BY_4       (RNG_CR_CLKDIV_1)
80 /*!< 4 RNG clock cycles per internal RNG clock    */
81 #define RNG_CLKDIV_BY_8       (RNG_CR_CLKDIV_1 | RNG_CR_CLKDIV_0)
82 /*!< 8 RNG clock cycles per internal RNG clock    */
83 #define RNG_CLKDIV_BY_16      (RNG_CR_CLKDIV_2)
84 /*!< 16 RNG clock cycles per internal RNG clock   */
85 #define RNG_CLKDIV_BY_32      (RNG_CR_CLKDIV_2 | RNG_CR_CLKDIV_0)
86 /*!< 32 RNG clock cycles per internal RNG clock   */
87 #define RNG_CLKDIV_BY_64      (RNG_CR_CLKDIV_2 | RNG_CR_CLKDIV_1)
88 /*!< 64 RNG clock cycles per internal RNG clock   */
89 #define RNG_CLKDIV_BY_128     (RNG_CR_CLKDIV_2 | RNG_CR_CLKDIV_1 | RNG_CR_CLKDIV_0)
90 /*!< 128 RNG clock cycles per internal RNG clock  */
91 #define RNG_CLKDIV_BY_256     (RNG_CR_CLKDIV_3)
92 /*!< 256 RNG clock cycles per internal RNG clock  */
93 #define RNG_CLKDIV_BY_512     (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_0)
94 /*!< 512 RNG clock cycles per internal RNG clock  */
95 #define RNG_CLKDIV_BY_1024    (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_1)
96 /*!< 1024 RNG clock cycles per internal RNG clock */
97 #define RNG_CLKDIV_BY_2048    (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_1 | RNG_CR_CLKDIV_0)
98 /*!< 2048 RNG clock cycles per internal RNG clock  */
99 #define RNG_CLKDIV_BY_4096    (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_2)
100 /*!< 4096 RNG clock cycles per internal RNG clock  */
101 #define RNG_CLKDIV_BY_8192    (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_2 | RNG_CR_CLKDIV_0)
102 /*!< 8192 RNG clock cycles per internal RNG clock  */
103 #define RNG_CLKDIV_BY_16384   (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_2 | RNG_CR_CLKDIV_1)
104 /*!< 16384 RNG clock cycles per internal RNG clock */
105 #define RNG_CLKDIV_BY_32768   (RNG_CR_CLKDIV_3 | RNG_CR_CLKDIV_2 | RNG_CR_CLKDIV_1 | RNG_CR_CLKDIV_0)
106 /*!< 32768 RNG clock cycles per internal RNG clock */
107 /**
108   * @}
109   */
110 
111 /** @defgroup RNG_Ex_NIST_Compliance  NIST Compliance configuration
112   * @{
113   */
114 #define RNG_NIST_COMPLIANT     (0x00000000UL) /*!< NIST compliant configuration*/
115 #define RNG_CUSTOM_NIST        (RNG_CR_NISTC) /*!< Custom NIST configuration */
116 
117 /**
118   * @}
119   */
120 
121 /**
122   * @}
123   */
124 
125 /* Private types -------------------------------------------------------------*/
126 /** @defgroup RNG_Ex_Private_Types RNG_Ex Private Types
127   * @{
128   */
129 
130 /**
131   * @}
132   */
133 
134 /* Private variables ---------------------------------------------------------*/
135 /** @defgroup RNG_Ex_Private_Variables RNG_Ex Private Variables
136   * @{
137   */
138 
139 /**
140   * @}
141   */
142 
143 /* Private constants ---------------------------------------------------------*/
144 /** @defgroup RNG_Ex_Private_Constants RNG_Ex Private Constants
145   * @{
146   */
147 
148 /**
149   * @}
150   */
151 
152 /* Private macros ------------------------------------------------------------*/
153 /** @defgroup RNG_Ex_Private_Macros RNG_Ex Private Macros
154   * @{
155   */
156 
157 #define IS_RNG_CLOCK_DIVIDER(__CLOCK_DIV__) (((__CLOCK_DIV__) == RNG_CLKDIV_BY_1)     || \
158                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_2)     || \
159                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_4)     || \
160                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_8)     || \
161                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_16)    || \
162                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_32)    || \
163                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_64)    || \
164                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_128)   || \
165                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_256)   || \
166                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_512)   || \
167                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_1024)  || \
168                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_2048)  || \
169                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_4096)  || \
170                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_8192)  || \
171                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_16384) || \
172                                              ((__CLOCK_DIV__) == RNG_CLKDIV_BY_32768))
173 
174 
175 #define IS_RNG_NIST_COMPLIANCE(__NIST_COMPLIANCE__) (((__NIST_COMPLIANCE__) == RNG_NIST_COMPLIANT) || \
176                                                      ((__NIST_COMPLIANCE__) == RNG_CUSTOM_NIST))
177 
178 #define IS_RNG_CONFIG1(__CONFIG1__) ((__CONFIG1__) <= 0x3FUL)
179 
180 #define IS_RNG_CONFIG2(__CONFIG2__) ((__CONFIG2__) <= 0x07UL)
181 
182 #define IS_RNG_CONFIG3(__CONFIG3__) ((__CONFIG3__) <= 0xFUL)
183 
184 
185 /**
186   * @}
187   */
188 
189 /* Private functions ---------------------------------------------------------*/
190 /** @defgroup RNG_Ex_Private_Functions RNG_Ex Private Functions
191   * @{
192   */
193 
194 /**
195   * @}
196   */
197 
198 /* Exported functions --------------------------------------------------------*/
199 /** @defgroup RNG_Ex_Exported_Functions RNG_Ex Exported Functions
200   * @{
201   */
202 
203 /** @addtogroup RNG_Ex_Exported_Functions_Group1
204   * @{
205   */
206 HAL_StatusTypeDef HAL_RNGEx_SetConfig(RNG_HandleTypeDef *hrng, RNG_ConfigTypeDef *pConf);
207 HAL_StatusTypeDef HAL_RNGEx_GetConfig(RNG_HandleTypeDef *hrng, RNG_ConfigTypeDef *pConf);
208 HAL_StatusTypeDef HAL_RNGEx_LockConfig(RNG_HandleTypeDef *hrng);
209 
210 /**
211   * @}
212   */
213 
214 /** @addtogroup RNG_Ex_Exported_Functions_Group2
215   * @{
216   */
217 HAL_StatusTypeDef HAL_RNGEx_RecoverSeedError(RNG_HandleTypeDef *hrng);
218 
219 /**
220   * @}
221   */
222 
223 /**
224   * @}
225   */
226 
227 /**
228   * @}
229   */
230 
231 /**
232   * @}
233   */
234 
235 #endif /* RNG_CR_CONDRST */
236 #endif /* RNG */
237 
238 /**
239   * @}
240   */
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 
246 
247 #endif /* STM32WLxx_HAL_RNG_EX_H */
248