2 ******************************************************************************
3 * @file stm32f4xx_hal_rng.h
4 * @author MCD Application Team
7 * @brief Header file of RNG HAL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F4xx_HAL_RNG_H
40 #define __STM32F4xx_HAL_RNG_H
46 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
47 defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
48 /* Includes ------------------------------------------------------------------*/
49 #include "stm32f4xx_hal_def.h"
51 /** @addtogroup STM32F4xx_HAL_Driver
59 /* Exported types ------------------------------------------------------------*/
62 * @brief RNG HAL State Structure definition
66 HAL_RNG_STATE_RESET = 0x00, /*!< RNG not yet initialized or disabled */
67 HAL_RNG_STATE_READY = 0x01, /*!< RNG initialized and ready for use */
68 HAL_RNG_STATE_BUSY = 0x02, /*!< RNG internal process is ongoing */
69 HAL_RNG_STATE_TIMEOUT = 0x03, /*!< RNG timeout state */
70 HAL_RNG_STATE_ERROR = 0x04 /*!< RNG error state */
72 }HAL_RNG_StateTypeDef;
75 * @brief RNG Handle Structure definition
79 RNG_TypeDef *Instance; /*!< Register base address */
81 HAL_LockTypeDef Lock; /*!< RNG locking object */
83 __IO HAL_RNG_StateTypeDef State; /*!< RNG communication state */
87 /* Exported constants --------------------------------------------------------*/
89 /** @defgroup RNG_Exported_Constants
93 /** @defgroup RNG_Interrupt_definition
96 #define RNG_IT_CEI ((uint32_t)0x20) /*!< Clock error interrupt */
97 #define RNG_IT_SEI ((uint32_t)0x40) /*!< Seed error interrupt */
99 #define IS_RNG_IT(IT) (((IT) == RNG_IT_CEI) || \
100 ((IT) == RNG_IT_SEI))
106 /** @defgroup RNG_Flag_definition
109 #define RNG_FLAG_DRDY ((uint32_t)0x0001) /*!< Data ready */
110 #define RNG_FLAG_CECS ((uint32_t)0x0002) /*!< Clock error current status */
111 #define RNG_FLAG_SECS ((uint32_t)0x0004) /*!< Seed error current status */
113 #define IS_RNG_FLAG(FLAG) (((FLAG) == RNG_FLAG_DRDY) || \
114 ((FLAG) == RNG_FLAG_CECS) || \
115 ((FLAG) == RNG_FLAG_SECS))
124 /* Exported macro ------------------------------------------------------------*/
126 /** @brief Reset RNG handle state
127 * @param __HANDLE__: RNG Handle
130 #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET)
133 * @brief Enables the RNG peripheral.
134 * @param __HANDLE__: RNG Handle
137 #define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN)
140 * @brief Disables the RNG peripheral.
141 * @param __HANDLE__: RNG Handle
144 #define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN)
147 * @brief Gets the selected RNG's flag status.
148 * @param __HANDLE__: RNG Handle
149 * @param __FLAG__: RNG flag
150 * @retval The new state of RNG_FLAG (SET or RESET).
152 #define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
155 * @brief Clears the RNG's pending flags.
156 * @param __HANDLE__: RNG Handle
157 * @param __FLAG__: RNG flag
160 #define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = ~(__FLAG__))
163 * @brief Enables the RNG interrupts.
164 * @param __HANDLE__: RNG Handle
167 #define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE)
170 * @brief Disables the RNG interrupts.
171 * @param __HANDLE__: RNG Handle
174 #define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE)
177 * @brief Checks whether the specified RNG interrupt has occurred or not.
178 * @param __HANDLE__: RNG Handle
179 * @param __INTERRUPT__: specifies the RNG interrupt source to check.
180 * This parameter can be one of the following values:
181 * @arg RNG_FLAG_DRDY: Data ready interrupt
182 * @arg RNG_FLAG_CECS: Clock error interrupt
183 * @arg RNG_FLAG_SECS: Seed error interrupt
184 * @retval The new state of RNG_FLAG (SET or RESET).
186 #define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))
188 /* Exported functions --------------------------------------------------------*/
190 /* Initialization/de-initialization functions **********************************/
191 HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng);
192 HAL_StatusTypeDef HAL_RNG_DeInit (RNG_HandleTypeDef *hrng);
193 void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng);
194 void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng);
196 /* Peripheral Control functions ************************************************/
197 uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng);
198 uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng);
199 void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng);
200 void HAL_RNG_ReadyCallback(RNG_HandleTypeDef* hrng);
201 void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng);
203 /* Peripheral State functions **************************************************/
204 HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng);
206 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
220 #endif /* __STM32F4xx_HAL_RNG_H */
222 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/