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