mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
shaoziyang
Date:
Sat Sep 13 14:25:46 2014 +0000
Revision:
323:9e901b0a5aa1
Parent:
181:a4cbdfbbd2f4
test with CLOCK_SETUP = 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 181:a4cbdfbbd2f4 1 /**
mbed_official 181:a4cbdfbbd2f4 2 ******************************************************************************
mbed_official 181:a4cbdfbbd2f4 3 * @file stm32l0xx_hal_rng.c
mbed_official 181:a4cbdfbbd2f4 4 * @author MCD Application Team
mbed_official 181:a4cbdfbbd2f4 5 * @version V1.0.0
mbed_official 181:a4cbdfbbd2f4 6 * @date 22-April-2014
mbed_official 181:a4cbdfbbd2f4 7 * @brief RNG HAL module driver.
mbed_official 181:a4cbdfbbd2f4 8 * This file provides firmware functions to manage the following
mbed_official 181:a4cbdfbbd2f4 9 * functionalities of the Random Number Generator (RNG) peripheral:
mbed_official 181:a4cbdfbbd2f4 10 * + Initialization/de-initialization functions
mbed_official 181:a4cbdfbbd2f4 11 * + Peripheral Control functions
mbed_official 181:a4cbdfbbd2f4 12 * + Peripheral State functions
mbed_official 181:a4cbdfbbd2f4 13 *
mbed_official 181:a4cbdfbbd2f4 14 @verbatim
mbed_official 181:a4cbdfbbd2f4 15 ==============================================================================
mbed_official 181:a4cbdfbbd2f4 16 ##### How to use this driver #####
mbed_official 181:a4cbdfbbd2f4 17 ==============================================================================
mbed_official 181:a4cbdfbbd2f4 18 [..]
mbed_official 181:a4cbdfbbd2f4 19 The RNG HAL driver can be used as follows:
mbed_official 181:a4cbdfbbd2f4 20
mbed_official 181:a4cbdfbbd2f4 21 (#) Enable the RNG controller clock using __RNG_CLK_ENABLE() macro.
mbed_official 181:a4cbdfbbd2f4 22 (#) Activate the RNG peripheral using __HAL_RNG_ENABLE() macro.
mbed_official 181:a4cbdfbbd2f4 23 (#) Wait until the 32 bit Random Number Generator contains a valid
mbed_official 181:a4cbdfbbd2f4 24 random data using (polling/interrupt) mode.
mbed_official 181:a4cbdfbbd2f4 25 (#) Get the 32 bit random number using HAL_RNG_GetRandomNumber() function.
mbed_official 181:a4cbdfbbd2f4 26
mbed_official 181:a4cbdfbbd2f4 27 @endverbatim
mbed_official 181:a4cbdfbbd2f4 28 ******************************************************************************
mbed_official 181:a4cbdfbbd2f4 29 * @attention
mbed_official 181:a4cbdfbbd2f4 30 *
mbed_official 181:a4cbdfbbd2f4 31 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 181:a4cbdfbbd2f4 32 *
mbed_official 181:a4cbdfbbd2f4 33 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 181:a4cbdfbbd2f4 34 * are permitted provided that the following conditions are met:
mbed_official 181:a4cbdfbbd2f4 35 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 181:a4cbdfbbd2f4 36 * this list of conditions and the following disclaimer.
mbed_official 181:a4cbdfbbd2f4 37 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 181:a4cbdfbbd2f4 38 * this list of conditions and the following disclaimer in the documentation
mbed_official 181:a4cbdfbbd2f4 39 * and/or other materials provided with the distribution.
mbed_official 181:a4cbdfbbd2f4 40 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 181:a4cbdfbbd2f4 41 * may be used to endorse or promote products derived from this software
mbed_official 181:a4cbdfbbd2f4 42 * without specific prior written permission.
mbed_official 181:a4cbdfbbd2f4 43 *
mbed_official 181:a4cbdfbbd2f4 44 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 181:a4cbdfbbd2f4 45 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 181:a4cbdfbbd2f4 46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 181:a4cbdfbbd2f4 47 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 181:a4cbdfbbd2f4 48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 181:a4cbdfbbd2f4 49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 181:a4cbdfbbd2f4 50 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 181:a4cbdfbbd2f4 51 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 181:a4cbdfbbd2f4 52 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 181:a4cbdfbbd2f4 53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 181:a4cbdfbbd2f4 54 *
mbed_official 181:a4cbdfbbd2f4 55 ******************************************************************************
mbed_official 181:a4cbdfbbd2f4 56 */
mbed_official 181:a4cbdfbbd2f4 57
mbed_official 181:a4cbdfbbd2f4 58 /* Includes ------------------------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 59 #include "stm32l0xx_hal.h"
mbed_official 181:a4cbdfbbd2f4 60
mbed_official 181:a4cbdfbbd2f4 61 /** @addtogroup STM32L0xx_HAL_Driver
mbed_official 181:a4cbdfbbd2f4 62 * @{
mbed_official 181:a4cbdfbbd2f4 63 */
mbed_official 181:a4cbdfbbd2f4 64
mbed_official 181:a4cbdfbbd2f4 65 /** @defgroup RNG
mbed_official 181:a4cbdfbbd2f4 66 * @brief RNG HAL module driver.
mbed_official 181:a4cbdfbbd2f4 67 * @{
mbed_official 181:a4cbdfbbd2f4 68 */
mbed_official 181:a4cbdfbbd2f4 69
mbed_official 181:a4cbdfbbd2f4 70 #ifdef HAL_RNG_MODULE_ENABLED
mbed_official 181:a4cbdfbbd2f4 71 #if !defined (STM32L051xx) && !defined (STM32L061xx)
mbed_official 181:a4cbdfbbd2f4 72
mbed_official 181:a4cbdfbbd2f4 73 /* Private typedef -----------------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 74 /* Private define ------------------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 75 #define RNG_TIMEOUT_VALUE 1000
mbed_official 181:a4cbdfbbd2f4 76 /* Private macro -------------------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 77 /* Private variables ---------------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 78 /* Private function prototypes -----------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 79 /* Private functions ---------------------------------------------------------*/
mbed_official 181:a4cbdfbbd2f4 80
mbed_official 181:a4cbdfbbd2f4 81 /** @defgroup RNG_Private_Functions
mbed_official 181:a4cbdfbbd2f4 82 * @{
mbed_official 181:a4cbdfbbd2f4 83 */
mbed_official 181:a4cbdfbbd2f4 84
mbed_official 181:a4cbdfbbd2f4 85 /** @defgroup RNG_Group1 Initialization and de-initialization functions
mbed_official 181:a4cbdfbbd2f4 86 * @brief Initialization and Configuration functions.
mbed_official 181:a4cbdfbbd2f4 87 *
mbed_official 181:a4cbdfbbd2f4 88 @verbatim
mbed_official 181:a4cbdfbbd2f4 89 ===============================================================================
mbed_official 181:a4cbdfbbd2f4 90 ##### Initialization and de-initialization functions #####
mbed_official 181:a4cbdfbbd2f4 91 ===============================================================================
mbed_official 181:a4cbdfbbd2f4 92 [..] This section provides functions allowing to:
mbed_official 181:a4cbdfbbd2f4 93 (+) Initialize the RNG according to the specified parameters
mbed_official 181:a4cbdfbbd2f4 94 in the RNG_InitTypeDef and create the associated handle
mbed_official 181:a4cbdfbbd2f4 95 (+) DeInitialize the RNG peripheral
mbed_official 181:a4cbdfbbd2f4 96 (+) Initialize the RNG MSP
mbed_official 181:a4cbdfbbd2f4 97 (+) DeInitialize RNG MSP
mbed_official 181:a4cbdfbbd2f4 98
mbed_official 181:a4cbdfbbd2f4 99 @endverbatim
mbed_official 181:a4cbdfbbd2f4 100 * @{
mbed_official 181:a4cbdfbbd2f4 101 */
mbed_official 181:a4cbdfbbd2f4 102
mbed_official 181:a4cbdfbbd2f4 103 /**
mbed_official 181:a4cbdfbbd2f4 104 * @brief Initializes the RNG according to the specified
mbed_official 181:a4cbdfbbd2f4 105 * parameters in the RNG_InitTypeDef and creates the associated handle.
mbed_official 181:a4cbdfbbd2f4 106 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
mbed_official 181:a4cbdfbbd2f4 107 * the configuration information for RNG.
mbed_official 181:a4cbdfbbd2f4 108 * @retval HAL status
mbed_official 181:a4cbdfbbd2f4 109 */
mbed_official 181:a4cbdfbbd2f4 110 HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng)
mbed_official 181:a4cbdfbbd2f4 111 {
mbed_official 181:a4cbdfbbd2f4 112 /* Check the RNG handle allocation */
mbed_official 181:a4cbdfbbd2f4 113 if(hrng == NULL)
mbed_official 181:a4cbdfbbd2f4 114 {
mbed_official 181:a4cbdfbbd2f4 115 return HAL_ERROR;
mbed_official 181:a4cbdfbbd2f4 116 }
mbed_official 181:a4cbdfbbd2f4 117
mbed_official 181:a4cbdfbbd2f4 118 if(hrng->State == HAL_RNG_STATE_RESET)
mbed_official 181:a4cbdfbbd2f4 119 {
mbed_official 181:a4cbdfbbd2f4 120 /* Init the low level hardware */
mbed_official 181:a4cbdfbbd2f4 121 HAL_RNG_MspInit(hrng);
mbed_official 181:a4cbdfbbd2f4 122 }
mbed_official 181:a4cbdfbbd2f4 123
mbed_official 181:a4cbdfbbd2f4 124 /* Change RNG peripheral state */
mbed_official 181:a4cbdfbbd2f4 125 hrng->State = HAL_RNG_STATE_BUSY;
mbed_official 181:a4cbdfbbd2f4 126
mbed_official 181:a4cbdfbbd2f4 127 /* Enable the RNG Peripheral */
mbed_official 181:a4cbdfbbd2f4 128 __HAL_RNG_ENABLE(hrng);
mbed_official 181:a4cbdfbbd2f4 129
mbed_official 181:a4cbdfbbd2f4 130 /* Initialize the RNG state */
mbed_official 181:a4cbdfbbd2f4 131 hrng->State = HAL_RNG_STATE_READY;
mbed_official 181:a4cbdfbbd2f4 132
mbed_official 181:a4cbdfbbd2f4 133 /* Return function status */
mbed_official 181:a4cbdfbbd2f4 134 return HAL_OK;
mbed_official 181:a4cbdfbbd2f4 135 }
mbed_official 181:a4cbdfbbd2f4 136
mbed_official 181:a4cbdfbbd2f4 137 /**
mbed_official 181:a4cbdfbbd2f4 138 * @brief DeInitializes the RNG peripheral.
mbed_official 181:a4cbdfbbd2f4 139 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
mbed_official 181:a4cbdfbbd2f4 140 * the configuration information for RNG.
mbed_official 181:a4cbdfbbd2f4 141 * @retval HAL status
mbed_official 181:a4cbdfbbd2f4 142 */
mbed_official 181:a4cbdfbbd2f4 143 HAL_StatusTypeDef HAL_RNG_DeInit(RNG_HandleTypeDef *hrng)
mbed_official 181:a4cbdfbbd2f4 144 {
mbed_official 181:a4cbdfbbd2f4 145 /* Check the RNG peripheral state */
mbed_official 181:a4cbdfbbd2f4 146 if(hrng->State == HAL_RNG_STATE_BUSY)
mbed_official 181:a4cbdfbbd2f4 147 {
mbed_official 181:a4cbdfbbd2f4 148 return HAL_BUSY;
mbed_official 181:a4cbdfbbd2f4 149 }
mbed_official 181:a4cbdfbbd2f4 150
mbed_official 181:a4cbdfbbd2f4 151 /* Update the RNG state */
mbed_official 181:a4cbdfbbd2f4 152 hrng->State = HAL_RNG_STATE_BUSY;
mbed_official 181:a4cbdfbbd2f4 153
mbed_official 181:a4cbdfbbd2f4 154 /* Disable the RNG Peripheral */
mbed_official 181:a4cbdfbbd2f4 155 __HAL_RNG_DISABLE(hrng);
mbed_official 181:a4cbdfbbd2f4 156
mbed_official 181:a4cbdfbbd2f4 157 /* Set the RNG registers to their reset values */
mbed_official 181:a4cbdfbbd2f4 158 hrng->Instance->CR &= 0xFFFFFFF3;
mbed_official 181:a4cbdfbbd2f4 159 hrng->Instance->SR &= 0xFFFFFF98;
mbed_official 181:a4cbdfbbd2f4 160 hrng->Instance->DR &= 0x0;
mbed_official 181:a4cbdfbbd2f4 161
mbed_official 181:a4cbdfbbd2f4 162 /* DeInit the low level hardware */
mbed_official 181:a4cbdfbbd2f4 163 HAL_RNG_MspDeInit(hrng);
mbed_official 181:a4cbdfbbd2f4 164
mbed_official 181:a4cbdfbbd2f4 165 /* Update the RNG state */
mbed_official 181:a4cbdfbbd2f4 166 hrng->State = HAL_RNG_STATE_RESET;
mbed_official 181:a4cbdfbbd2f4 167
mbed_official 181:a4cbdfbbd2f4 168 /* Release Lock */
mbed_official 181:a4cbdfbbd2f4 169 __HAL_UNLOCK(hrng);
mbed_official 181:a4cbdfbbd2f4 170
mbed_official 181:a4cbdfbbd2f4 171 /* Return the function status */
mbed_official 181:a4cbdfbbd2f4 172 return HAL_OK;
mbed_official 181:a4cbdfbbd2f4 173 }
mbed_official 181:a4cbdfbbd2f4 174
mbed_official 181:a4cbdfbbd2f4 175 /**
mbed_official 181:a4cbdfbbd2f4 176 * @brief Initializes the RNG MSP.
mbed_official 181:a4cbdfbbd2f4 177 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
mbed_official 181:a4cbdfbbd2f4 178 * the configuration information for RNG.
mbed_official 181:a4cbdfbbd2f4 179 * @retval None
mbed_official 181:a4cbdfbbd2f4 180 */
mbed_official 181:a4cbdfbbd2f4 181 __weak void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng)
mbed_official 181:a4cbdfbbd2f4 182 {
mbed_official 181:a4cbdfbbd2f4 183 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 181:a4cbdfbbd2f4 184 the HAL_RNG_MspInit could be implemented in the user file
mbed_official 181:a4cbdfbbd2f4 185 */
mbed_official 181:a4cbdfbbd2f4 186 }
mbed_official 181:a4cbdfbbd2f4 187
mbed_official 181:a4cbdfbbd2f4 188 /**
mbed_official 181:a4cbdfbbd2f4 189 * @brief DeInitializes the RNG MSP.
mbed_official 181:a4cbdfbbd2f4 190 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
mbed_official 181:a4cbdfbbd2f4 191 * the configuration information for RNG.
mbed_official 181:a4cbdfbbd2f4 192 * @retval None
mbed_official 181:a4cbdfbbd2f4 193 */
mbed_official 181:a4cbdfbbd2f4 194 __weak void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng)
mbed_official 181:a4cbdfbbd2f4 195 {
mbed_official 181:a4cbdfbbd2f4 196 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 181:a4cbdfbbd2f4 197 the HAL_RNG_MspDeInit could be implemented in the user file
mbed_official 181:a4cbdfbbd2f4 198 */
mbed_official 181:a4cbdfbbd2f4 199 }
mbed_official 181:a4cbdfbbd2f4 200
mbed_official 181:a4cbdfbbd2f4 201 /**
mbed_official 181:a4cbdfbbd2f4 202 * @}
mbed_official 181:a4cbdfbbd2f4 203 */
mbed_official 181:a4cbdfbbd2f4 204
mbed_official 181:a4cbdfbbd2f4 205 /** @defgroup RNG_Group2 Peripheral Control functions
mbed_official 181:a4cbdfbbd2f4 206 * @brief management functions.
mbed_official 181:a4cbdfbbd2f4 207 *
mbed_official 181:a4cbdfbbd2f4 208 @verbatim
mbed_official 181:a4cbdfbbd2f4 209 ===============================================================================
mbed_official 181:a4cbdfbbd2f4 210 ##### Peripheral Control functions #####
mbed_official 181:a4cbdfbbd2f4 211 ===============================================================================
mbed_official 181:a4cbdfbbd2f4 212 [..] This section provides functions allowing to:
mbed_official 181:a4cbdfbbd2f4 213 (+) Get the 32 bit Random number
mbed_official 181:a4cbdfbbd2f4 214 (+) Get the 32 bit Random number with interrupt enabled
mbed_official 181:a4cbdfbbd2f4 215 (+) Handle RNG interrupt request
mbed_official 181:a4cbdfbbd2f4 216
mbed_official 181:a4cbdfbbd2f4 217
mbed_official 181:a4cbdfbbd2f4 218 @endverbatim
mbed_official 181:a4cbdfbbd2f4 219 * @{
mbed_official 181:a4cbdfbbd2f4 220 */
mbed_official 181:a4cbdfbbd2f4 221
mbed_official 181:a4cbdfbbd2f4 222 /**
mbed_official 181:a4cbdfbbd2f4 223 * @brief Returns a 32-bit random number.
mbed_official 181:a4cbdfbbd2f4 224 * @note Each time the random number data is read the RNG_FLAG_DRDY flag
mbed_official 181:a4cbdfbbd2f4 225 * is automatically cleared.
mbed_official 181:a4cbdfbbd2f4 226 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
mbed_official 181:a4cbdfbbd2f4 227 * the configuration information for RNG.
mbed_official 181:a4cbdfbbd2f4 228 * @retval 32-bit random number
mbed_official 181:a4cbdfbbd2f4 229 */
mbed_official 181:a4cbdfbbd2f4 230 uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng)
mbed_official 181:a4cbdfbbd2f4 231 {
mbed_official 181:a4cbdfbbd2f4 232 uint32_t random32bit = 0;
mbed_official 181:a4cbdfbbd2f4 233 uint32_t tickstart = 0;
mbed_official 181:a4cbdfbbd2f4 234
mbed_official 181:a4cbdfbbd2f4 235 /* Process Locked */
mbed_official 181:a4cbdfbbd2f4 236 __HAL_LOCK(hrng);
mbed_official 181:a4cbdfbbd2f4 237
mbed_official 181:a4cbdfbbd2f4 238 /* Get timeout */
mbed_official 181:a4cbdfbbd2f4 239 tickstart = HAL_GetTick();
mbed_official 181:a4cbdfbbd2f4 240
mbed_official 181:a4cbdfbbd2f4 241 /* Check if data register contains valid random data */
mbed_official 181:a4cbdfbbd2f4 242 while(__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_DRDY) == RESET)
mbed_official 181:a4cbdfbbd2f4 243 {
mbed_official 181:a4cbdfbbd2f4 244 if((HAL_GetTick() - tickstart ) > RNG_TIMEOUT_VALUE)
mbed_official 181:a4cbdfbbd2f4 245 {
mbed_official 181:a4cbdfbbd2f4 246 return HAL_TIMEOUT;
mbed_official 181:a4cbdfbbd2f4 247 }
mbed_official 181:a4cbdfbbd2f4 248 }
mbed_official 181:a4cbdfbbd2f4 249
mbed_official 181:a4cbdfbbd2f4 250 /* Get a 32bit Random number */
mbed_official 181:a4cbdfbbd2f4 251 random32bit = hrng->Instance->DR;
mbed_official 181:a4cbdfbbd2f4 252
mbed_official 181:a4cbdfbbd2f4 253 /* Process Unlocked */
mbed_official 181:a4cbdfbbd2f4 254 __HAL_UNLOCK(hrng);
mbed_official 181:a4cbdfbbd2f4 255
mbed_official 181:a4cbdfbbd2f4 256 /* Return the 32 bit random number */
mbed_official 181:a4cbdfbbd2f4 257 return random32bit;
mbed_official 181:a4cbdfbbd2f4 258 }
mbed_official 181:a4cbdfbbd2f4 259
mbed_official 181:a4cbdfbbd2f4 260 /**
mbed_official 181:a4cbdfbbd2f4 261 * @brief Returns a 32-bit random number with interrupt enabled.
mbed_official 181:a4cbdfbbd2f4 262 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
mbed_official 181:a4cbdfbbd2f4 263 * the configuration information for RNG.
mbed_official 181:a4cbdfbbd2f4 264 * @retval 32-bit random number
mbed_official 181:a4cbdfbbd2f4 265 */
mbed_official 181:a4cbdfbbd2f4 266 uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng)
mbed_official 181:a4cbdfbbd2f4 267 {
mbed_official 181:a4cbdfbbd2f4 268 uint32_t random32bit = 0;
mbed_official 181:a4cbdfbbd2f4 269
mbed_official 181:a4cbdfbbd2f4 270 /* Process Locked */
mbed_official 181:a4cbdfbbd2f4 271 __HAL_LOCK(hrng);
mbed_official 181:a4cbdfbbd2f4 272
mbed_official 181:a4cbdfbbd2f4 273 /* Change RNG peripheral state */
mbed_official 181:a4cbdfbbd2f4 274 hrng->State = HAL_RNG_STATE_BUSY;
mbed_official 181:a4cbdfbbd2f4 275
mbed_official 181:a4cbdfbbd2f4 276 /* Get a 32bit Random number */
mbed_official 181:a4cbdfbbd2f4 277 random32bit = hrng->Instance->DR;
mbed_official 181:a4cbdfbbd2f4 278
mbed_official 181:a4cbdfbbd2f4 279 /* Enable the RNG Interrupts: Data Ready, Clock error, Seed error */
mbed_official 181:a4cbdfbbd2f4 280 __HAL_RNG_ENABLE_IT(hrng);
mbed_official 181:a4cbdfbbd2f4 281
mbed_official 181:a4cbdfbbd2f4 282 /* Return the 32 bit random number */
mbed_official 181:a4cbdfbbd2f4 283 return random32bit;
mbed_official 181:a4cbdfbbd2f4 284 }
mbed_official 181:a4cbdfbbd2f4 285
mbed_official 181:a4cbdfbbd2f4 286 /**
mbed_official 181:a4cbdfbbd2f4 287 * @brief Handles RNG interrupt request.
mbed_official 181:a4cbdfbbd2f4 288 * @note In the case of a clock error, the RNG is no more able to generate
mbed_official 181:a4cbdfbbd2f4 289 * random numbers because the PLL48CLK clock is not correct. User has
mbed_official 181:a4cbdfbbd2f4 290 * to check that the clock controller is correctly configured to provide
mbed_official 181:a4cbdfbbd2f4 291 * the RNG clock and clear the CEIS bit using __HAL_RNG_CLEAR_FLAG().
mbed_official 181:a4cbdfbbd2f4 292 * The clock error has no impact on the previously generated
mbed_official 181:a4cbdfbbd2f4 293 * random numbers, and the RNG_DR register contents can be used.
mbed_official 181:a4cbdfbbd2f4 294 * @note In the case of a seed error, the generation of random numbers is
mbed_official 181:a4cbdfbbd2f4 295 * interrupted as long as the SECS bit is '1'. If a number is
mbed_official 181:a4cbdfbbd2f4 296 * available in the RNG_DR register, it must not be used because it may
mbed_official 181:a4cbdfbbd2f4 297 * not have enough entropy. In this case, it is recommended to clear the
mbed_official 181:a4cbdfbbd2f4 298 * SEIS bit using __HAL_RNG_CLEAR_FLAG(), then disable and enable
mbed_official 181:a4cbdfbbd2f4 299 * the RNG peripheral to reinitialize and restart the RNG.
mbed_official 181:a4cbdfbbd2f4 300 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
mbed_official 181:a4cbdfbbd2f4 301 * the configuration information for RNG.
mbed_official 181:a4cbdfbbd2f4 302 * @retval None
mbed_official 181:a4cbdfbbd2f4 303
mbed_official 181:a4cbdfbbd2f4 304 */
mbed_official 181:a4cbdfbbd2f4 305 void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng)
mbed_official 181:a4cbdfbbd2f4 306 {
mbed_official 181:a4cbdfbbd2f4 307 /* RNG clock error interrupt occurred */
mbed_official 181:a4cbdfbbd2f4 308 if(__HAL_RNG_GET_FLAG(hrng, RNG_IT_CEI) != RESET)
mbed_official 181:a4cbdfbbd2f4 309 {
mbed_official 181:a4cbdfbbd2f4 310 HAL_RNG_ErrorCallback(hrng);
mbed_official 181:a4cbdfbbd2f4 311
mbed_official 181:a4cbdfbbd2f4 312 /* Clear the clock error flag */
mbed_official 181:a4cbdfbbd2f4 313 __HAL_RNG_CLEAR_FLAG(hrng, RNG_IT_CEI);
mbed_official 181:a4cbdfbbd2f4 314
mbed_official 181:a4cbdfbbd2f4 315 /* Change RNG peripheral state */
mbed_official 181:a4cbdfbbd2f4 316 hrng->State = HAL_RNG_STATE_ERROR;
mbed_official 181:a4cbdfbbd2f4 317
mbed_official 181:a4cbdfbbd2f4 318 /* Process Unlocked */
mbed_official 181:a4cbdfbbd2f4 319 __HAL_UNLOCK(hrng);
mbed_official 181:a4cbdfbbd2f4 320 }
mbed_official 181:a4cbdfbbd2f4 321
mbed_official 181:a4cbdfbbd2f4 322 /* RNG seed error interrupt occurred */
mbed_official 181:a4cbdfbbd2f4 323 if(__HAL_RNG_GET_FLAG(hrng, RNG_IT_SEI) != RESET)
mbed_official 181:a4cbdfbbd2f4 324 {
mbed_official 181:a4cbdfbbd2f4 325 HAL_RNG_ErrorCallback(hrng);
mbed_official 181:a4cbdfbbd2f4 326
mbed_official 181:a4cbdfbbd2f4 327 /* Clear the seed error flag */
mbed_official 181:a4cbdfbbd2f4 328 __HAL_RNG_CLEAR_FLAG(hrng, RNG_IT_SEI);
mbed_official 181:a4cbdfbbd2f4 329
mbed_official 181:a4cbdfbbd2f4 330 /* Change RNG peripheral state */
mbed_official 181:a4cbdfbbd2f4 331 hrng->State = HAL_RNG_STATE_ERROR;
mbed_official 181:a4cbdfbbd2f4 332
mbed_official 181:a4cbdfbbd2f4 333 /* Process Unlocked */
mbed_official 181:a4cbdfbbd2f4 334 __HAL_UNLOCK(hrng);
mbed_official 181:a4cbdfbbd2f4 335 }
mbed_official 181:a4cbdfbbd2f4 336
mbed_official 181:a4cbdfbbd2f4 337 /* Check RNG data ready flag */
mbed_official 181:a4cbdfbbd2f4 338 if(__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_DRDY) != RESET)
mbed_official 181:a4cbdfbbd2f4 339 {
mbed_official 181:a4cbdfbbd2f4 340 /* Data Ready callback */
mbed_official 181:a4cbdfbbd2f4 341 HAL_RNG_ReadyCallback(hrng);
mbed_official 181:a4cbdfbbd2f4 342
mbed_official 181:a4cbdfbbd2f4 343 /* Change RNG peripheral state */
mbed_official 181:a4cbdfbbd2f4 344 hrng->State = HAL_RNG_STATE_READY;
mbed_official 181:a4cbdfbbd2f4 345
mbed_official 181:a4cbdfbbd2f4 346 /* Clear the RNG Data Ready flag */
mbed_official 181:a4cbdfbbd2f4 347 __HAL_RNG_CLEAR_FLAG(hrng, RNG_FLAG_DRDY);
mbed_official 181:a4cbdfbbd2f4 348
mbed_official 181:a4cbdfbbd2f4 349 /* Process Unlocked */
mbed_official 181:a4cbdfbbd2f4 350 __HAL_UNLOCK(hrng);
mbed_official 181:a4cbdfbbd2f4 351 }
mbed_official 181:a4cbdfbbd2f4 352 }
mbed_official 181:a4cbdfbbd2f4 353
mbed_official 181:a4cbdfbbd2f4 354 /**
mbed_official 181:a4cbdfbbd2f4 355 * @brief Data Ready callback in non-blocking mode.
mbed_official 181:a4cbdfbbd2f4 356 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
mbed_official 181:a4cbdfbbd2f4 357 * the configuration information for RNG.
mbed_official 181:a4cbdfbbd2f4 358 * @retval None
mbed_official 181:a4cbdfbbd2f4 359 */
mbed_official 181:a4cbdfbbd2f4 360
mbed_official 181:a4cbdfbbd2f4 361 __weak void HAL_RNG_ReadyCallback(RNG_HandleTypeDef* hrng)
mbed_official 181:a4cbdfbbd2f4 362 {
mbed_official 181:a4cbdfbbd2f4 363 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 181:a4cbdfbbd2f4 364 the HAL_RNG_ReadyCallback could be implemented in the user file
mbed_official 181:a4cbdfbbd2f4 365 */
mbed_official 181:a4cbdfbbd2f4 366 }
mbed_official 181:a4cbdfbbd2f4 367
mbed_official 181:a4cbdfbbd2f4 368 /**
mbed_official 181:a4cbdfbbd2f4 369 * @brief RNG error callbacks.
mbed_official 181:a4cbdfbbd2f4 370 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
mbed_official 181:a4cbdfbbd2f4 371 * the configuration information for RNG.
mbed_official 181:a4cbdfbbd2f4 372 * @retval None
mbed_official 181:a4cbdfbbd2f4 373 */
mbed_official 181:a4cbdfbbd2f4 374 __weak void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng)
mbed_official 181:a4cbdfbbd2f4 375 {
mbed_official 181:a4cbdfbbd2f4 376 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 181:a4cbdfbbd2f4 377 the HAL_RNG_ErrorCallback could be implemented in the user file
mbed_official 181:a4cbdfbbd2f4 378 */
mbed_official 181:a4cbdfbbd2f4 379 }
mbed_official 181:a4cbdfbbd2f4 380
mbed_official 181:a4cbdfbbd2f4 381 /**
mbed_official 181:a4cbdfbbd2f4 382 * @}
mbed_official 181:a4cbdfbbd2f4 383 */
mbed_official 181:a4cbdfbbd2f4 384
mbed_official 181:a4cbdfbbd2f4 385 /** @defgroup RNG_Group3 Peripheral State functions
mbed_official 181:a4cbdfbbd2f4 386 * @brief Peripheral State functions.
mbed_official 181:a4cbdfbbd2f4 387 *
mbed_official 181:a4cbdfbbd2f4 388 @verbatim
mbed_official 181:a4cbdfbbd2f4 389 ===============================================================================
mbed_official 181:a4cbdfbbd2f4 390 ##### Peripheral State functions #####
mbed_official 181:a4cbdfbbd2f4 391 ===============================================================================
mbed_official 181:a4cbdfbbd2f4 392 [..]
mbed_official 181:a4cbdfbbd2f4 393 This subsection permits to get in run-time the status of the peripheral
mbed_official 181:a4cbdfbbd2f4 394 and the data flow.
mbed_official 181:a4cbdfbbd2f4 395
mbed_official 181:a4cbdfbbd2f4 396 @endverbatim
mbed_official 181:a4cbdfbbd2f4 397 * @{
mbed_official 181:a4cbdfbbd2f4 398 */
mbed_official 181:a4cbdfbbd2f4 399
mbed_official 181:a4cbdfbbd2f4 400 /**
mbed_official 181:a4cbdfbbd2f4 401 * @brief Returns the RNG state.
mbed_official 181:a4cbdfbbd2f4 402 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
mbed_official 181:a4cbdfbbd2f4 403 * the configuration information for RNG.
mbed_official 181:a4cbdfbbd2f4 404 * @retval HAL state
mbed_official 181:a4cbdfbbd2f4 405 */
mbed_official 181:a4cbdfbbd2f4 406 HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng)
mbed_official 181:a4cbdfbbd2f4 407 {
mbed_official 181:a4cbdfbbd2f4 408 return hrng->State;
mbed_official 181:a4cbdfbbd2f4 409 }
mbed_official 181:a4cbdfbbd2f4 410
mbed_official 181:a4cbdfbbd2f4 411 /**
mbed_official 181:a4cbdfbbd2f4 412 * @}
mbed_official 181:a4cbdfbbd2f4 413 */
mbed_official 181:a4cbdfbbd2f4 414
mbed_official 181:a4cbdfbbd2f4 415 /**
mbed_official 181:a4cbdfbbd2f4 416 * @}
mbed_official 181:a4cbdfbbd2f4 417 */
mbed_official 181:a4cbdfbbd2f4 418 #endif /* STM32L051xx && STM32L061xx*/
mbed_official 181:a4cbdfbbd2f4 419 #endif /* HAL_RNG_MODULE_ENABLED */
mbed_official 181:a4cbdfbbd2f4 420 /**
mbed_official 181:a4cbdfbbd2f4 421 * @}
mbed_official 181:a4cbdfbbd2f4 422 */
mbed_official 181:a4cbdfbbd2f4 423
mbed_official 181:a4cbdfbbd2f4 424 /**
mbed_official 181:a4cbdfbbd2f4 425 * @}
mbed_official 181:a4cbdfbbd2f4 426 */
mbed_official 181:a4cbdfbbd2f4 427
mbed_official 181:a4cbdfbbd2f4 428 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
mbed_official 181:a4cbdfbbd2f4 429