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