source: S-port/trunk/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rng.h

Last change on this file was 1, checked in by AlexLir, 3 years ago
File size: 12.1 KB
Line 
1/**
2 ******************************************************************************
3 * @file stm32f4xx_hal_rng.h
4 * @author MCD Application Team
5 * @brief Header file of RNG HAL module.
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>&copy; Copyright (c) 2016 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 STM32F4xx_HAL_RNG_H
22#define STM32F4xx_HAL_RNG_H
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/* Includes ------------------------------------------------------------------*/
29#include "stm32f4xx_hal_def.h"
30
31/** @addtogroup STM32F4xx_HAL_Driver
32 * @{
33 */
34
35#if defined (RNG)
36
37/** @defgroup RNG RNG
38 * @brief RNG HAL module driver
39 * @{
40 */
41
42/* Exported types ------------------------------------------------------------*/
43
44/** @defgroup RNG_Exported_Types RNG Exported Types
45 * @{
46 */
47
48/** @defgroup RNG_Exported_Types_Group1 RNG Init Structure definition
49 * @{
50 */
51
52/**
53 * @}
54 */
55
56/** @defgroup RNG_Exported_Types_Group2 RNG State Structure definition
57 * @{
58 */
59typedef enum
60{
61 HAL_RNG_STATE_RESET = 0x00U, /*!< RNG not yet initialized or disabled */
62 HAL_RNG_STATE_READY = 0x01U, /*!< RNG initialized and ready for use */
63 HAL_RNG_STATE_BUSY = 0x02U, /*!< RNG internal process is ongoing */
64 HAL_RNG_STATE_TIMEOUT = 0x03U, /*!< RNG timeout state */
65 HAL_RNG_STATE_ERROR = 0x04U /*!< RNG error state */
66
67} HAL_RNG_StateTypeDef;
68
69/**
70 * @}
71 */
72
73/** @defgroup RNG_Exported_Types_Group3 RNG Handle Structure definition
74 * @{
75 */
76#if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
77typedef struct __RNG_HandleTypeDef
78#else
79typedef struct
80#endif /* (USE_HAL_RNG_REGISTER_CALLBACKS) */
81{
82 RNG_TypeDef *Instance; /*!< Register base address */
83
84 HAL_LockTypeDef Lock; /*!< RNG locking object */
85
86 __IO HAL_RNG_StateTypeDef State; /*!< RNG communication state */
87
88 __IO uint32_t ErrorCode; /*!< RNG Error code */
89
90 uint32_t RandomNumber; /*!< Last Generated RNG Data */
91
92#if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
93 void (* ReadyDataCallback)(struct __RNG_HandleTypeDef *hrng, uint32_t random32bit); /*!< RNG Data Ready Callback */
94 void (* ErrorCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Error Callback */
95
96 void (* MspInitCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Msp Init callback */
97 void (* MspDeInitCallback)(struct __RNG_HandleTypeDef *hrng); /*!< RNG Msp DeInit callback */
98#endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
99
100} RNG_HandleTypeDef;
101
102#if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
103/**
104 * @brief HAL RNG Callback ID enumeration definition
105 */
106typedef enum
107{
108 HAL_RNG_ERROR_CB_ID = 0x00U, /*!< RNG Error Callback ID */
109
110 HAL_RNG_MSPINIT_CB_ID = 0x01U, /*!< RNG MspInit callback ID */
111 HAL_RNG_MSPDEINIT_CB_ID = 0x02U /*!< RNG MspDeInit callback ID */
112
113} HAL_RNG_CallbackIDTypeDef;
114
115/**
116 * @brief HAL RNG Callback pointer definition
117 */
118typedef void (*pRNG_CallbackTypeDef)(RNG_HandleTypeDef *hrng); /*!< pointer to a common RNG callback function */
119typedef void (*pRNG_ReadyDataCallbackTypeDef)(RNG_HandleTypeDef *hrng, uint32_t random32bit); /*!< pointer to an RNG Data Ready specific callback function */
120
121#endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
122
123/**
124 * @}
125 */
126
127/**
128 * @}
129 */
130
131/* Exported constants --------------------------------------------------------*/
132/** @defgroup RNG_Exported_Constants RNG Exported Constants
133 * @{
134 */
135
136/** @defgroup RNG_Exported_Constants_Group1 RNG Interrupt definition
137 * @{
138 */
139#define RNG_IT_DRDY RNG_SR_DRDY /*!< Data Ready interrupt */
140#define RNG_IT_CEI RNG_SR_CEIS /*!< Clock error interrupt */
141#define RNG_IT_SEI RNG_SR_SEIS /*!< Seed error interrupt */
142/**
143 * @}
144 */
145
146/** @defgroup RNG_Exported_Constants_Group2 RNG Flag definition
147 * @{
148 */
149#define RNG_FLAG_DRDY RNG_SR_DRDY /*!< Data ready */
150#define RNG_FLAG_CECS RNG_SR_CECS /*!< Clock error current status */
151#define RNG_FLAG_SECS RNG_SR_SECS /*!< Seed error current status */
152/**
153 * @}
154 */
155
156/** @defgroup RNG_Error_Definition RNG Error Definition
157 * @{
158 */
159#define HAL_RNG_ERROR_NONE 0x00000000U /*!< No error */
160#if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
161#define HAL_RNG_ERROR_INVALID_CALLBACK 0x00000001U /*!< Invalid Callback error */
162#endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
163#define HAL_RNG_ERROR_TIMEOUT 0x00000002U /*!< Timeout error */
164#define HAL_RNG_ERROR_BUSY 0x00000004U /*!< Busy error */
165#define HAL_RNG_ERROR_SEED 0x00000008U /*!< Seed error */
166#define HAL_RNG_ERROR_CLOCK 0x00000010U /*!< Clock error */
167/**
168 * @}
169 */
170
171/**
172 * @}
173 */
174
175/* Exported macros -----------------------------------------------------------*/
176/** @defgroup RNG_Exported_Macros RNG Exported Macros
177 * @{
178 */
179
180/** @brief Reset RNG handle state
181 * @param __HANDLE__ RNG Handle
182 * @retval None
183 */
184#if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
185#define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) do{ \
186 (__HANDLE__)->State = HAL_RNG_STATE_RESET; \
187 (__HANDLE__)->MspInitCallback = NULL; \
188 (__HANDLE__)->MspDeInitCallback = NULL; \
189 } while(0U)
190#else
191#define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET)
192#endif /*USE_HAL_RNG_REGISTER_CALLBACKS */
193
194/**
195 * @brief Enables the RNG peripheral.
196 * @param __HANDLE__ RNG Handle
197 * @retval None
198 */
199#define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN)
200
201/**
202 * @brief Disables the RNG peripheral.
203 * @param __HANDLE__ RNG Handle
204 * @retval None
205 */
206#define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN)
207
208/**
209 * @brief Check the selected RNG flag status.
210 * @param __HANDLE__ RNG Handle
211 * @param __FLAG__ RNG flag
212 * This parameter can be one of the following values:
213 * @arg RNG_FLAG_DRDY: Data ready
214 * @arg RNG_FLAG_CECS: Clock error current status
215 * @arg RNG_FLAG_SECS: Seed error current status
216 * @retval The new state of __FLAG__ (SET or RESET).
217 */
218#define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
219
220/**
221 * @brief Clears the selected RNG flag status.
222 * @param __HANDLE__ RNG handle
223 * @param __FLAG__ RNG flag to clear
224 * @note WARNING: This is a dummy macro for HAL code alignment,
225 * flags RNG_FLAG_DRDY, RNG_FLAG_CECS and RNG_FLAG_SECS are read-only.
226 * @retval None
227 */
228#define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) /* dummy macro */
229
230/**
231 * @brief Enables the RNG interrupts.
232 * @param __HANDLE__ RNG Handle
233 * @retval None
234 */
235#define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE)
236
237/**
238 * @brief Disables the RNG interrupts.
239 * @param __HANDLE__ RNG Handle
240 * @retval None
241 */
242#define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE)
243
244/**
245 * @brief Checks whether the specified RNG interrupt has occurred or not.
246 * @param __HANDLE__ RNG Handle
247 * @param __INTERRUPT__ specifies the RNG interrupt status flag to check.
248 * This parameter can be one of the following values:
249 * @arg RNG_IT_DRDY: Data ready interrupt
250 * @arg RNG_IT_CEI: Clock error interrupt
251 * @arg RNG_IT_SEI: Seed error interrupt
252 * @retval The new state of __INTERRUPT__ (SET or RESET).
253 */
254#define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))
255
256/**
257 * @brief Clear the RNG interrupt status flags.
258 * @param __HANDLE__ RNG Handle
259 * @param __INTERRUPT__ specifies the RNG interrupt status flag to clear.
260 * This parameter can be one of the following values:
261 * @arg RNG_IT_CEI: Clock error interrupt
262 * @arg RNG_IT_SEI: Seed error interrupt
263 * @note RNG_IT_DRDY flag is read-only, reading RNG_DR register automatically clears RNG_IT_DRDY.
264 * @retval None
265 */
266#define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__))
267
268/**
269 * @}
270 */
271
272/* Exported functions --------------------------------------------------------*/
273/** @defgroup RNG_Exported_Functions RNG Exported Functions
274 * @{
275 */
276
277/** @defgroup RNG_Exported_Functions_Group1 Initialization and configuration functions
278 * @{
279 */
280HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng);
281HAL_StatusTypeDef HAL_RNG_DeInit(RNG_HandleTypeDef *hrng);
282void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng);
283void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng);
284
285/* Callbacks Register/UnRegister functions ***********************************/
286#if (USE_HAL_RNG_REGISTER_CALLBACKS == 1)
287HAL_StatusTypeDef HAL_RNG_RegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID, pRNG_CallbackTypeDef pCallback);
288HAL_StatusTypeDef HAL_RNG_UnRegisterCallback(RNG_HandleTypeDef *hrng, HAL_RNG_CallbackIDTypeDef CallbackID);
289
290HAL_StatusTypeDef HAL_RNG_RegisterReadyDataCallback(RNG_HandleTypeDef *hrng, pRNG_ReadyDataCallbackTypeDef pCallback);
291HAL_StatusTypeDef HAL_RNG_UnRegisterReadyDataCallback(RNG_HandleTypeDef *hrng);
292#endif /* USE_HAL_RNG_REGISTER_CALLBACKS */
293
294/**
295 * @}
296 */
297
298/** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions
299 * @{
300 */
301uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber() instead */
302uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber_IT() instead */
303HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit);
304HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng);
305uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef *hrng);
306
307void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng);
308void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng);
309void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef *hrng, uint32_t random32bit);
310
311/**
312 * @}
313 */
314
315/** @defgroup RNG_Exported_Functions_Group3 Peripheral State functions
316 * @{
317 */
318HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng);
319uint32_t HAL_RNG_GetError(RNG_HandleTypeDef *hrng);
320/**
321 * @}
322 */
323
324/**
325 * @}
326 */
327
328/* Private macros ------------------------------------------------------------*/
329/** @defgroup RNG_Private_Macros RNG Private Macros
330 * @{
331 */
332#define IS_RNG_IT(IT) (((IT) == RNG_IT_CEI) || \
333 ((IT) == RNG_IT_SEI))
334
335#define IS_RNG_FLAG(FLAG) (((FLAG) == RNG_FLAG_DRDY) || \
336 ((FLAG) == RNG_FLAG_CECS) || \
337 ((FLAG) == RNG_FLAG_SECS))
338
339/**
340 * @}
341 */
342
343/**
344 * @}
345 */
346
347#endif /* RNG */
348
349/**
350 * @}
351 */
352
353#ifdef __cplusplus
354}
355#endif
356
357
358#endif /* STM32F4xx_HAL_RNG_H */
359
360/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Note: See TracBrowser for help on using the repository browser.