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