2 ******************************************************************************
3 * @file stm32l0xx_hal_rng.h
5 * @author MCD Application Team
7 * @date 06-February-2015
8 * @brief Header file of RNG HAL module.
9 ******************************************************************************
12 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
14 * Redistribution and use in source and binary forms, with or without modification,
15 * are permitted provided that the following conditions are met:
16 * 1. Redistributions of source code must retain the above copyright notice,
17 * this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 ******************************************************************************
39 /* Define to prevent recursive inclusion -------------------------------------*/
40 #ifndef __STM32L0xx_HAL_RNG_H
41 #define __STM32L0xx_HAL_RNG_H
47 #if defined (STM32L052xx) || defined (STM32L053xx) || defined (STM32L062xx) || defined (STM32L063xx) || \
48 defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L082xx) || defined (STM32L083xx)
50 /* Includes ------------------------------------------------------------------*/
51 #include "stm32l0xx_hal_def.h"
53 /** @addtogroup STM32L0xx_HAL_Driver
58 * @brief RNG HAL module driver
62 /* Exported types ------------------------------------------------------------*/
64 /** @defgroup RNG_Exported_Types RNG Exported Types
68 /** @defgroup RNG_Exported_Types_Group1 RNG State Structure definition
73 HAL_RNG_STATE_RESET = 0x00, /*!< RNG not yet initialized or disabled */
74 HAL_RNG_STATE_READY = 0x01, /*!< RNG initialized and ready for use */
75 HAL_RNG_STATE_BUSY = 0x02, /*!< RNG internal process is ongoing */
76 HAL_RNG_STATE_TIMEOUT = 0x03, /*!< RNG timeout state */
77 HAL_RNG_STATE_ERROR = 0x04 /*!< RNG error state */
79 }HAL_RNG_StateTypeDef;
85 /** @defgroup RNG_Exported_Types_Group2 RNG Handle Structure definition
90 RNG_TypeDef *Instance; /*!< Register base address */
92 HAL_LockTypeDef Lock; /*!< RNG locking object */
94 __IO HAL_RNG_StateTypeDef State; /*!< RNG communication state */
96 uint32_t RandomNumber; /*!< Last Generated RNG Data */
108 /* Exported constants --------------------------------------------------------*/
110 /** @defgroup RNG_Exported_Constants RNG Exported Constants
114 /** @defgroup RNG_Exported_Constants_Group1 RNG Interrupt definition
117 #define RNG_IT_DRDY ((uint32_t)RNG_SR_DRDY) /*!< Data ready interrupt */
118 #define RNG_IT_CEI ((uint32_t)RNG_SR_CEIS) /*!< Clock error interrupt */
119 #define RNG_IT_SEI ((uint32_t)RNG_SR_SEIS) /*!< Seed error interrupt */
126 /** @defgroup RNG_Exported_Constants_Group2 RNG Flag definition
129 #define RNG_FLAG_DRDY ((uint32_t)RNG_SR_DRDY) /*!< Data ready */
130 #define RNG_FLAG_CECS ((uint32_t)RNG_SR_CECS) /*!< Clock error current status */
131 #define RNG_FLAG_SECS ((uint32_t)RNG_SR_SECS) /*!< Seed error current status */
141 /* Exported macros -----------------------------------------------------------*/
142 /** @defgroup RNG_Exported_Macros RNG Exported Macros
146 /** @brief Reset RNG handle state
147 * @param __HANDLE__: RNG Handle
150 #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET)
153 * @brief Enables the RNG peripheral.
154 * @param __HANDLE__: RNG Handle
157 #define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_RNGEN)
160 * @brief Disables the RNG peripheral.
161 * @param __HANDLE__: RNG Handle
164 #define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN)
167 * @brief Check the selected RNG flag status.
168 * @param __HANDLE__: RNG Handle
169 * @param __FLAG__: RNG flag
170 * This parameter can be one of the following values:
171 * @arg RNG_FLAG_DRDY: Data ready
172 * @arg RNG_FLAG_CECS: Clock error current status
173 * @arg RNG_FLAG_SECS: Seed error current status
174 * @retval The new state of __FLAG__ (SET or RESET).
176 #define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
180 * @brief Clears the selected RNG flag status.
181 * @param __HANDLE__: RNG handle
182 * @param __FLAG__: RNG flag to clear
183 * @note WARNING: This is a dummy macro for HAL code alignment,
184 * flags RNG_FLAG_DRDY, RNG_FLAG_CECS and RNG_FLAG_SECS are read-only.
187 #define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__) /* dummy macro */
192 * @brief Enables the RNG interrupts.
193 * @param __HANDLE__: RNG Handle
196 #define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |= RNG_CR_IE)
199 * @brief Disables the RNG interrupts.
200 * @param __HANDLE__: RNG Handle
203 #define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE)
206 * @brief Checks whether the specified RNG interrupt has occurred or not.
207 * @param __HANDLE__: RNG Handle
208 * @param __INTERRUPT__: specifies the RNG interrupt status flag to check.
209 * This parameter can be one of the following values:
210 * @arg RNG_IT_DRDY: Data ready interrupt
211 * @arg RNG_IT_CEI: Clock error interrupt
212 * @arg RNG_IT_SEI: Seed error interrupt
213 * @retval The new state of __INTERRUPT__ (SET or RESET).
215 #define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))
218 * @brief Clears the RNG interrupt status flags.
219 * @param __HANDLE__: RNG Handle
220 * @param __INTERRUPT__: specifies the RNG interrupt status flag to clear.
221 * This parameter can be one of the following values:
222 * @arg RNG_IT_CEI: Clock error interrupt
223 * @arg RNG_IT_SEI: Seed error interrupt
224 * @note RNG_IT_DRDY flag is read-only, reading RNG_DR register automatically clears RNG_IT_DRDY.
227 #define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__))
233 /* Exported functions --------------------------------------------------------*/
234 /** @defgroup RNG_Exported_Functions RNG Exported Functions
238 /* Initialization and de-initialization functions ******************************/
239 /** @defgroup RNG_Exported_Functions_Group1 Initialization and de-initialization functions
242 HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng);
243 HAL_StatusTypeDef HAL_RNG_DeInit (RNG_HandleTypeDef *hrng);
244 void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng);
245 void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng);
251 /* Peripheral Control functions ************************************************/
252 /** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions
255 uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber() instead */
256 uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber_IT() instead */
258 HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit);
259 HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng);
260 uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef *hrng);
262 void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng);
263 void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng);
264 void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef* hrng, uint32_t random32bit);
270 /* Peripheral State functions **************************************************/
271 /** @defgroup RNG_Exported_Functions_Group3 Peripheral State functions
274 HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng);
283 /* Private types -------------------------------------------------------------*/
284 /** @defgroup RNG_Private_Types RNG Private Types
292 /* Private defines -----------------------------------------------------------*/
293 /** @defgroup RNG_Private_Defines RNG Private Defines
301 /* Private variables ---------------------------------------------------------*/
302 /** @defgroup RNG_Private_Variables RNG Private Variables
310 /* Private constants ---------------------------------------------------------*/
311 /** @defgroup RNG_Private_Constants RNG Private Constants
318 /* Private macros ------------------------------------------------------------*/
319 /** @defgroup RNG_Private_Macros RNG Private Macros
327 /* Private functions prototypes ----------------------------------------------*/
328 /** @defgroup RNG_Private_Functions_Prototypes RNG Private Functions Prototypes
336 /* Private functions ---------------------------------------------------------*/
337 /** @defgroup RNG_Private_Functions RNG Private Functions
352 #endif /* if defined (STM32L052xx) || defined (STM32L053xx) || defined (STM32L062xx) || defined (STM32L063xx) || \
353 defined (STM32L072xx) || defined (STM32L073xx) || defined (STM32L082xx) || defined (STM32L083xx) */
358 #endif /* __STM32L0xx_HAL_RNG_H */
361 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/