STM32F439xx HAL User Manual
stm32f4xx_hal_rng.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_rng.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of RNG HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00010   *
00011   * Redistribution and use in source and binary forms, with or without modification,
00012   * are permitted provided that the following conditions are met:
00013   *   1. Redistributions of source code must retain the above copyright notice,
00014   *      this list of conditions and the following disclaimer.
00015   *   2. Redistributions in binary form must reproduce the above copyright notice,
00016   *      this list of conditions and the following disclaimer in the documentation
00017   *      and/or other materials provided with the distribution.
00018   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019   *      may be used to endorse or promote products derived from this software
00020   *      without specific prior written permission.
00021   *
00022   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032   *
00033   ******************************************************************************
00034   */
00035 
00036 /* Define to prevent recursive inclusion -------------------------------------*/
00037 #ifndef __STM32F4xx_HAL_RNG_H
00038 #define __STM32F4xx_HAL_RNG_H
00039 
00040 #ifdef __cplusplus
00041  extern "C" {
00042 #endif
00043 
00044 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
00045     defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
00046     defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F469xx) ||\
00047     defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\
00048     defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
00049       
00050 /* Includes ------------------------------------------------------------------*/
00051 #include "stm32f4xx_hal_def.h"
00052 
00053 /** @addtogroup STM32F4xx_HAL_Driver
00054   * @{
00055   */
00056 
00057 /** @defgroup RNG RNG
00058   * @brief RNG HAL module driver
00059   * @{
00060   */
00061 
00062 /* Exported types ------------------------------------------------------------*/ 
00063 
00064 /** @defgroup RNG_Exported_Types RNG Exported Types
00065   * @{
00066   */
00067 
00068 /** @defgroup RNG_Exported_Types_Group1 RNG State Structure definition 
00069   * @{
00070   */
00071 typedef enum
00072 {
00073   HAL_RNG_STATE_RESET     = 0x00U,  /*!< RNG not yet initialized or disabled */
00074   HAL_RNG_STATE_READY     = 0x01U,  /*!< RNG initialized and ready for use   */
00075   HAL_RNG_STATE_BUSY      = 0x02U,  /*!< RNG internal process is ongoing     */ 
00076   HAL_RNG_STATE_TIMEOUT   = 0x03U,  /*!< RNG timeout state                   */
00077   HAL_RNG_STATE_ERROR     = 0x04U   /*!< RNG error state                     */
00078     
00079 }HAL_RNG_StateTypeDef;
00080 
00081 /** 
00082   * @}
00083   */
00084 
00085 /** @defgroup RNG_Exported_Types_Group2 RNG Handle Structure definition   
00086   * @{
00087   */ 
00088 typedef struct
00089 {
00090   RNG_TypeDef                 *Instance;    /*!< Register base address   */ 
00091   
00092   HAL_LockTypeDef             Lock;         /*!< RNG locking object      */
00093   
00094   __IO HAL_RNG_StateTypeDef   State;        /*!< RNG communication state */
00095   
00096   uint32_t                    RandomNumber; /*!< Last Generated RNG Data */
00097   
00098 }RNG_HandleTypeDef;
00099 
00100 /** 
00101   * @}
00102   */
00103 
00104 /**
00105   * @}
00106   */ 
00107    
00108 /* Exported constants --------------------------------------------------------*/
00109 
00110 /** @defgroup RNG_Exported_Constants RNG Exported Constants
00111   * @{
00112   */
00113 
00114 /** @defgroup RNG_Exported_Constants_Group1 RNG Interrupt definition
00115   * @{
00116   */
00117 #define RNG_IT_DRDY  RNG_SR_DRDY  /*!< Data Ready interrupt  */
00118 #define RNG_IT_CEI   RNG_SR_CEIS  /*!< Clock error interrupt */
00119 #define RNG_IT_SEI   RNG_SR_SEIS  /*!< Seed error interrupt  */
00120 /**
00121   * @}
00122   */
00123 
00124 /** @defgroup RNG_Exported_Constants_Group2 RNG Flag definition
00125   * @{
00126   */
00127 #define RNG_FLAG_DRDY   RNG_SR_DRDY  /*!< Data ready                 */
00128 #define RNG_FLAG_CECS   RNG_SR_CECS  /*!< Clock error current status */
00129 #define RNG_FLAG_SECS   RNG_SR_SECS  /*!< Seed error current status  */
00130 
00131 /**
00132   * @}
00133   */
00134 
00135 /**
00136   * @}
00137   */ 
00138   
00139 /* Exported macros -----------------------------------------------------------*/
00140 
00141 /** @defgroup RNG_Exported_Macros RNG Exported Macros
00142   * @{
00143   */
00144 
00145 /** @brief Reset RNG handle state
00146   * @param  __HANDLE__ RNG Handle
00147   * @retval None
00148   */
00149 #define __HAL_RNG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RNG_STATE_RESET)
00150 
00151 /**
00152   * @brief  Enables the RNG peripheral.
00153   * @param  __HANDLE__ RNG Handle
00154   * @retval None
00155   */
00156 #define __HAL_RNG_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |=  RNG_CR_RNGEN)
00157 
00158 /**
00159   * @brief  Disables the RNG peripheral.
00160   * @param  __HANDLE__ RNG Handle
00161   * @retval None
00162   */
00163 #define __HAL_RNG_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_RNGEN)
00164 
00165 /**
00166   * @brief  Check the selected RNG flag status.
00167   * @param  __HANDLE__ RNG Handle
00168   * @param  __FLAG__ RNG flag
00169   *          This parameter can be one of the following values:
00170   *            @arg RNG_FLAG_DRDY: Data ready                
00171   *            @arg RNG_FLAG_CECS: Clock error current status
00172   *            @arg RNG_FLAG_SECS: Seed error current status 
00173   * @retval The new state of __FLAG__ (SET or RESET).
00174   */
00175 #define __HAL_RNG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
00176 
00177 /**
00178   * @brief  Clears the selected RNG flag status.
00179   * @param  __HANDLE__ RNG handle
00180   * @param  __FLAG__ RNG flag to clear  
00181   * @note   WARNING: This is a dummy macro for HAL code alignment,
00182   *         flags RNG_FLAG_DRDY, RNG_FLAG_CECS and RNG_FLAG_SECS are read-only.
00183   * @retval None
00184   */
00185 #define __HAL_RNG_CLEAR_FLAG(__HANDLE__, __FLAG__)                      /* dummy  macro */
00186 
00187 
00188 
00189 /**
00190   * @brief  Enables the RNG interrupts.
00191   * @param  __HANDLE__ RNG Handle
00192   * @retval None
00193   */
00194 #define __HAL_RNG_ENABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR |=  RNG_CR_IE)
00195     
00196 /**
00197   * @brief  Disables the RNG interrupts.
00198   * @param  __HANDLE__ RNG Handle
00199   * @retval None
00200   */
00201 #define __HAL_RNG_DISABLE_IT(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~RNG_CR_IE)
00202 
00203 /**
00204   * @brief  Checks whether the specified RNG interrupt has occurred or not.
00205   * @param  __HANDLE__ RNG Handle
00206   * @param  __INTERRUPT__ specifies the RNG interrupt status flag to check.
00207   *         This parameter can be one of the following values:
00208   *            @arg RNG_IT_DRDY: Data ready interrupt              
00209   *            @arg RNG_IT_CEI: Clock error interrupt
00210   *            @arg RNG_IT_SEI: Seed error interrupt
00211   * @retval The new state of __INTERRUPT__ (SET or RESET).
00212   */
00213 #define __HAL_RNG_GET_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR & (__INTERRUPT__)) == (__INTERRUPT__))   
00214 
00215 /**
00216   * @brief  Clear the RNG interrupt status flags.
00217   * @param  __HANDLE__ RNG Handle
00218   * @param  __INTERRUPT__ specifies the RNG interrupt status flag to clear.
00219   *          This parameter can be one of the following values:            
00220   *            @arg RNG_IT_CEI: Clock error interrupt
00221   *            @arg RNG_IT_SEI: Seed error interrupt
00222   * @note   RNG_IT_DRDY flag is read-only, reading RNG_DR register automatically clears RNG_IT_DRDY.          
00223   * @retval None
00224   */
00225 #define __HAL_RNG_CLEAR_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->SR) = ~(__INTERRUPT__))
00226 
00227 /**
00228   * @}
00229   */ 
00230 
00231 /* Exported functions --------------------------------------------------------*/
00232 /** @defgroup RNG_Exported_Functions RNG Exported Functions
00233   * @{
00234   */
00235 
00236 /** @defgroup RNG_Exported_Functions_Group1 Initialization and de-initialization functions
00237   * @{
00238   */  
00239 HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng);
00240 HAL_StatusTypeDef HAL_RNG_DeInit (RNG_HandleTypeDef *hrng);
00241 void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng);
00242 void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng);
00243 
00244 /**
00245   * @}
00246   */ 
00247 
00248 /** @defgroup RNG_Exported_Functions_Group2 Peripheral Control functions
00249   * @{
00250   */
00251 uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng);    /* Obsolete, use HAL_RNG_GenerateRandomNumber() instead    */
00252 uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng); /* Obsolete, use HAL_RNG_GenerateRandomNumber_IT() instead */
00253 
00254 HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit);
00255 HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng);
00256 uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef *hrng);
00257 
00258 void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng);
00259 void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng);
00260 void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef* hrng, uint32_t random32bit);
00261 
00262 /**
00263   * @}
00264   */ 
00265 
00266 /** @defgroup RNG_Exported_Functions_Group3 Peripheral State functions
00267   * @{
00268   */
00269 HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng);
00270 
00271 /**
00272   * @}
00273   */
00274   
00275 /**
00276   * @}
00277   */ 
00278 
00279 /* Private types -------------------------------------------------------------*/
00280 /** @defgroup RNG_Private_Types RNG Private Types
00281   * @{
00282   */
00283 
00284 /**
00285   * @}
00286   */ 
00287 
00288 /* Private defines -----------------------------------------------------------*/
00289 /** @defgroup RNG_Private_Defines RNG Private Defines
00290   * @{
00291   */
00292 
00293 /**
00294   * @}
00295   */ 
00296           
00297 /* Private variables ---------------------------------------------------------*/
00298 /** @defgroup RNG_Private_Variables RNG Private Variables
00299   * @{
00300   */
00301 
00302 /**
00303   * @}
00304   */ 
00305 
00306 /* Private constants ---------------------------------------------------------*/
00307 /** @defgroup RNG_Private_Constants RNG Private Constants
00308   * @{
00309   */
00310 
00311 /**
00312   * @}
00313   */ 
00314 
00315 /* Private macros ------------------------------------------------------------*/
00316 /** @defgroup RNG_Private_Macros RNG Private Macros
00317   * @{
00318   */
00319 #define IS_RNG_IT(IT) (((IT) == RNG_IT_CEI) || \
00320                        ((IT) == RNG_IT_SEI))
00321 
00322 #define IS_RNG_FLAG(FLAG) (((FLAG) == RNG_FLAG_DRDY) || \
00323                            ((FLAG) == RNG_FLAG_CECS) || \
00324                            ((FLAG) == RNG_FLAG_SECS))
00325 
00326 /**
00327   * @}
00328   */ 
00329 
00330 /* Private functions prototypes ----------------------------------------------*/
00331 /** @defgroup RNG_Private_Functions_Prototypes RNG Private Functions Prototypes
00332   * @{
00333   */
00334 
00335 /**
00336   * @}
00337   */
00338 
00339 /* Private functions ---------------------------------------------------------*/
00340 /** @defgroup RNG_Private_Functions RNG Private Functions
00341   * @{
00342   */
00343 
00344 /**
00345   * @}
00346   */
00347 
00348 /**
00349   * @}
00350   */ 
00351 
00352 /**
00353   * @}
00354   */ 
00355 
00356 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\
00357           STM32F429xx || STM32F439xx || STM32F410xx || STM32F469xx || STM32F479xx || STM32F412Zx ||\
00358           STM32F412Vx || STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
00359 
00360 #ifdef __cplusplus
00361 }
00362 #endif
00363 
00364 
00365 #endif /* __STM32F4xx_HAL_RNG_H */
00366 
00367 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/