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