mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F401RE/stm32f4xx_hal_rng.c@106:ced8cbb51063, 2014-02-26 (annotated)
- Committer:
- mbed_official
- Date:
- Wed Feb 26 09:45:12 2014 +0000
- Revision:
- 106:ced8cbb51063
- Parent:
- 87:085cde657901
- Child:
- 226:b062af740e40
Synchronized with git revision 4222735eff5868389433f0e9271976b39c8115cd
Full URL: https://github.com/mbedmicro/mbed/commit/4222735eff5868389433f0e9271976b39c8115cd/
[NUCLEO_xxx] Update STM32CubeF4 driver V1.0.0 + update license
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 | 106:ced8cbb51063 | 5 | * @version V1.0.0 |
mbed_official | 106:ced8cbb51063 | 6 | * @date 18-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 | /* Enable the RNG Peripheral */ |
mbed_official | 87:085cde657901 | 123 | __HAL_RNG_ENABLE(hrng); |
mbed_official | 87:085cde657901 | 124 | |
mbed_official | 87:085cde657901 | 125 | /* Initialize the RNG state */ |
mbed_official | 87:085cde657901 | 126 | hrng->State = HAL_RNG_STATE_READY; |
mbed_official | 87:085cde657901 | 127 | |
mbed_official | 87:085cde657901 | 128 | /* Return function status */ |
mbed_official | 87:085cde657901 | 129 | return HAL_OK; |
mbed_official | 87:085cde657901 | 130 | } |
mbed_official | 87:085cde657901 | 131 | |
mbed_official | 87:085cde657901 | 132 | /** |
mbed_official | 87:085cde657901 | 133 | * @brief DeInitializes the RNG peripheral. |
mbed_official | 87:085cde657901 | 134 | * @param hrng: RNG handle |
mbed_official | 87:085cde657901 | 135 | * @retval HAL status |
mbed_official | 87:085cde657901 | 136 | */ |
mbed_official | 87:085cde657901 | 137 | HAL_StatusTypeDef HAL_RNG_DeInit(RNG_HandleTypeDef *hrng) |
mbed_official | 87:085cde657901 | 138 | { |
mbed_official | 87:085cde657901 | 139 | /* Check the RNG peripheral state */ |
mbed_official | 87:085cde657901 | 140 | if(hrng->State == HAL_RNG_STATE_BUSY) |
mbed_official | 87:085cde657901 | 141 | { |
mbed_official | 87:085cde657901 | 142 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 143 | } |
mbed_official | 87:085cde657901 | 144 | |
mbed_official | 87:085cde657901 | 145 | /* Update the RNG state */ |
mbed_official | 87:085cde657901 | 146 | hrng->State = HAL_RNG_STATE_BUSY; |
mbed_official | 87:085cde657901 | 147 | |
mbed_official | 87:085cde657901 | 148 | /* Disable the RNG Peripheral */ |
mbed_official | 87:085cde657901 | 149 | __HAL_RNG_DISABLE(hrng); |
mbed_official | 87:085cde657901 | 150 | |
mbed_official | 87:085cde657901 | 151 | /* Set the RNG registers to their reset values */ |
mbed_official | 87:085cde657901 | 152 | hrng->Instance->CR &= 0xFFFFFFF3; |
mbed_official | 87:085cde657901 | 153 | hrng->Instance->SR &= 0xFFFFFF98; |
mbed_official | 87:085cde657901 | 154 | hrng->Instance->DR &= 0x0; |
mbed_official | 87:085cde657901 | 155 | |
mbed_official | 87:085cde657901 | 156 | /* DeInit the low level hardware */ |
mbed_official | 87:085cde657901 | 157 | HAL_RNG_MspDeInit(hrng); |
mbed_official | 87:085cde657901 | 158 | |
mbed_official | 106:ced8cbb51063 | 159 | /* Update the RNG state */ |
mbed_official | 87:085cde657901 | 160 | hrng->State = HAL_RNG_STATE_RESET; |
mbed_official | 87:085cde657901 | 161 | |
mbed_official | 106:ced8cbb51063 | 162 | /* Release Lock */ |
mbed_official | 106:ced8cbb51063 | 163 | __HAL_UNLOCK(hrng); |
mbed_official | 106:ced8cbb51063 | 164 | |
mbed_official | 106:ced8cbb51063 | 165 | /* Return the function status */ |
mbed_official | 87:085cde657901 | 166 | return HAL_OK; |
mbed_official | 87:085cde657901 | 167 | } |
mbed_official | 87:085cde657901 | 168 | |
mbed_official | 87:085cde657901 | 169 | /** |
mbed_official | 87:085cde657901 | 170 | * @brief Initializes the RNG MSP. |
mbed_official | 87:085cde657901 | 171 | * @param hrng: RNG handle |
mbed_official | 87:085cde657901 | 172 | * @retval None |
mbed_official | 87:085cde657901 | 173 | */ |
mbed_official | 87:085cde657901 | 174 | __weak void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng) |
mbed_official | 87:085cde657901 | 175 | { |
mbed_official | 87:085cde657901 | 176 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 177 | the HAL_RNG_MspInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 178 | */ |
mbed_official | 87:085cde657901 | 179 | } |
mbed_official | 87:085cde657901 | 180 | |
mbed_official | 87:085cde657901 | 181 | /** |
mbed_official | 87:085cde657901 | 182 | * @brief DeInitializes the RNG MSP. |
mbed_official | 87:085cde657901 | 183 | * @param hrng: RNG handle |
mbed_official | 87:085cde657901 | 184 | * @retval None |
mbed_official | 87:085cde657901 | 185 | */ |
mbed_official | 87:085cde657901 | 186 | __weak void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng) |
mbed_official | 87:085cde657901 | 187 | { |
mbed_official | 87:085cde657901 | 188 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 189 | the HAL_RNG_MspDeInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 190 | */ |
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 | /** @defgroup RNG_Group2 Peripheral Control functions |
mbed_official | 87:085cde657901 | 198 | * @brief management functions. |
mbed_official | 87:085cde657901 | 199 | * |
mbed_official | 87:085cde657901 | 200 | @verbatim |
mbed_official | 87:085cde657901 | 201 | =============================================================================== |
mbed_official | 87:085cde657901 | 202 | ##### Peripheral Control functions ##### |
mbed_official | 87:085cde657901 | 203 | =============================================================================== |
mbed_official | 87:085cde657901 | 204 | [..] This section provides functions allowing to: |
mbed_official | 87:085cde657901 | 205 | (+) Get the 32 bit Random number |
mbed_official | 87:085cde657901 | 206 | (+) Get the 32 bit Random number with interrupt enabled |
mbed_official | 87:085cde657901 | 207 | (+) Handle RNG interrupt request |
mbed_official | 87:085cde657901 | 208 | |
mbed_official | 87:085cde657901 | 209 | |
mbed_official | 87:085cde657901 | 210 | @endverbatim |
mbed_official | 87:085cde657901 | 211 | * @{ |
mbed_official | 87:085cde657901 | 212 | */ |
mbed_official | 87:085cde657901 | 213 | |
mbed_official | 87:085cde657901 | 214 | /** |
mbed_official | 87:085cde657901 | 215 | * @brief Returns a 32-bit random number. |
mbed_official | 87:085cde657901 | 216 | * @note Each time the random number data is read the RNG_FLAG_DRDY flag |
mbed_official | 87:085cde657901 | 217 | * is automatically cleared. |
mbed_official | 87:085cde657901 | 218 | * @param hrng: RNG handle |
mbed_official | 87:085cde657901 | 219 | * @retval 32-bit random number |
mbed_official | 87:085cde657901 | 220 | */ |
mbed_official | 87:085cde657901 | 221 | uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng) |
mbed_official | 87:085cde657901 | 222 | { |
mbed_official | 87:085cde657901 | 223 | uint32_t random32bit = 0; |
mbed_official | 87:085cde657901 | 224 | uint32_t timeout = 0; |
mbed_official | 87:085cde657901 | 225 | |
mbed_official | 87:085cde657901 | 226 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 227 | __HAL_LOCK(hrng); |
mbed_official | 87:085cde657901 | 228 | |
mbed_official | 87:085cde657901 | 229 | timeout = HAL_GetTick() + RNG_TIMEOUT_VALUE; |
mbed_official | 87:085cde657901 | 230 | |
mbed_official | 87:085cde657901 | 231 | /* Check if data register contains valid random data */ |
mbed_official | 87:085cde657901 | 232 | while(__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_DRDY) == RESET) |
mbed_official | 87:085cde657901 | 233 | { |
mbed_official | 87:085cde657901 | 234 | if(HAL_GetTick() >= timeout) |
mbed_official | 87:085cde657901 | 235 | { |
mbed_official | 87:085cde657901 | 236 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 237 | } |
mbed_official | 87:085cde657901 | 238 | } |
mbed_official | 87:085cde657901 | 239 | |
mbed_official | 87:085cde657901 | 240 | /* Get a 32bit Random number */ |
mbed_official | 87:085cde657901 | 241 | random32bit = hrng->Instance->DR; |
mbed_official | 87:085cde657901 | 242 | |
mbed_official | 87:085cde657901 | 243 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 244 | __HAL_UNLOCK(hrng); |
mbed_official | 87:085cde657901 | 245 | |
mbed_official | 87:085cde657901 | 246 | /* Return the 32 bit random number */ |
mbed_official | 87:085cde657901 | 247 | return random32bit; |
mbed_official | 87:085cde657901 | 248 | } |
mbed_official | 87:085cde657901 | 249 | |
mbed_official | 87:085cde657901 | 250 | /** |
mbed_official | 87:085cde657901 | 251 | * @brief Returns a 32-bit random number with interrupt enabled. |
mbed_official | 87:085cde657901 | 252 | * @param hrng: RNG handle |
mbed_official | 87:085cde657901 | 253 | * @retval 32-bit random number |
mbed_official | 87:085cde657901 | 254 | */ |
mbed_official | 87:085cde657901 | 255 | uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng) |
mbed_official | 87:085cde657901 | 256 | { |
mbed_official | 87:085cde657901 | 257 | uint32_t random32bit = 0; |
mbed_official | 87:085cde657901 | 258 | |
mbed_official | 87:085cde657901 | 259 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 260 | __HAL_LOCK(hrng); |
mbed_official | 87:085cde657901 | 261 | |
mbed_official | 87:085cde657901 | 262 | /* Change RNG peripheral state */ |
mbed_official | 87:085cde657901 | 263 | hrng->State = HAL_RNG_STATE_BUSY; |
mbed_official | 87:085cde657901 | 264 | |
mbed_official | 87:085cde657901 | 265 | /* Get a 32bit Random number */ |
mbed_official | 87:085cde657901 | 266 | random32bit = hrng->Instance->DR; |
mbed_official | 87:085cde657901 | 267 | |
mbed_official | 87:085cde657901 | 268 | /* Enable the RNG Interrupts: Data Ready, Clock error, Seed error */ |
mbed_official | 87:085cde657901 | 269 | __HAL_RNG_ENABLE_IT(hrng); |
mbed_official | 87:085cde657901 | 270 | |
mbed_official | 87:085cde657901 | 271 | /* Return the 32 bit random number */ |
mbed_official | 87:085cde657901 | 272 | return random32bit; |
mbed_official | 87:085cde657901 | 273 | } |
mbed_official | 87:085cde657901 | 274 | |
mbed_official | 87:085cde657901 | 275 | /** |
mbed_official | 87:085cde657901 | 276 | * @brief Handles RNG interrupt request. |
mbed_official | 87:085cde657901 | 277 | * @note In the case of a clock error, the RNG is no more able to generate |
mbed_official | 87:085cde657901 | 278 | * random numbers because the PLL48CLK clock is not correct. User has |
mbed_official | 87:085cde657901 | 279 | * to check that the clock controller is correctly configured to provide |
mbed_official | 87:085cde657901 | 280 | * the RNG clock and clear the CEIS bit using __HAL_RNG_CLEAR_FLAG(). |
mbed_official | 87:085cde657901 | 281 | * The clock error has no impact on the previously generated |
mbed_official | 87:085cde657901 | 282 | * random numbers, and the RNG_DR register contents can be used. |
mbed_official | 87:085cde657901 | 283 | * @note In the case of a seed error, the generation of random numbers is |
mbed_official | 87:085cde657901 | 284 | * interrupted as long as the SECS bit is '1'. If a number is |
mbed_official | 87:085cde657901 | 285 | * available in the RNG_DR register, it must not be used because it may |
mbed_official | 87:085cde657901 | 286 | * not have enough entropy. In this case, it is recommended to clear the |
mbed_official | 87:085cde657901 | 287 | * SEIS bit using __HAL_RNG_CLEAR_FLAG(), then disable and enable |
mbed_official | 87:085cde657901 | 288 | * the RNG peripheral to reinitialize and restart the RNG. |
mbed_official | 87:085cde657901 | 289 | * @param hrng: RNG handle |
mbed_official | 87:085cde657901 | 290 | * @retval None |
mbed_official | 87:085cde657901 | 291 | |
mbed_official | 87:085cde657901 | 292 | */ |
mbed_official | 87:085cde657901 | 293 | void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng) |
mbed_official | 87:085cde657901 | 294 | { |
mbed_official | 87:085cde657901 | 295 | /* RNG clock error interrupt occured */ |
mbed_official | 87:085cde657901 | 296 | if(__HAL_RNG_GET_FLAG(hrng, RNG_IT_CEI) != RESET) |
mbed_official | 87:085cde657901 | 297 | { |
mbed_official | 87:085cde657901 | 298 | HAL_RNG_ErrorCallback(hrng); |
mbed_official | 87:085cde657901 | 299 | |
mbed_official | 87:085cde657901 | 300 | /* Clear the clock error flag */ |
mbed_official | 87:085cde657901 | 301 | __HAL_RNG_CLEAR_FLAG(hrng, RNG_IT_CEI); |
mbed_official | 87:085cde657901 | 302 | |
mbed_official | 87:085cde657901 | 303 | /* Change RNG peripheral state */ |
mbed_official | 87:085cde657901 | 304 | hrng->State = HAL_RNG_STATE_ERROR; |
mbed_official | 87:085cde657901 | 305 | |
mbed_official | 87:085cde657901 | 306 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 307 | __HAL_UNLOCK(hrng); |
mbed_official | 87:085cde657901 | 308 | } |
mbed_official | 87:085cde657901 | 309 | |
mbed_official | 87:085cde657901 | 310 | /* RNG seed error interrupt occured */ |
mbed_official | 87:085cde657901 | 311 | if(__HAL_RNG_GET_FLAG(hrng, RNG_IT_SEI) != RESET) |
mbed_official | 87:085cde657901 | 312 | { |
mbed_official | 87:085cde657901 | 313 | HAL_RNG_ErrorCallback(hrng); |
mbed_official | 87:085cde657901 | 314 | |
mbed_official | 87:085cde657901 | 315 | /* Clear the seed error flag */ |
mbed_official | 87:085cde657901 | 316 | __HAL_RNG_CLEAR_FLAG(hrng, RNG_IT_SEI); |
mbed_official | 87:085cde657901 | 317 | |
mbed_official | 87:085cde657901 | 318 | /* Change RNG peripheral state */ |
mbed_official | 87:085cde657901 | 319 | hrng->State = HAL_RNG_STATE_ERROR; |
mbed_official | 87:085cde657901 | 320 | |
mbed_official | 87:085cde657901 | 321 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 322 | __HAL_UNLOCK(hrng); |
mbed_official | 87:085cde657901 | 323 | } |
mbed_official | 87:085cde657901 | 324 | |
mbed_official | 87:085cde657901 | 325 | /* Check RNG data ready flag */ |
mbed_official | 87:085cde657901 | 326 | if(__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_DRDY) != RESET) |
mbed_official | 87:085cde657901 | 327 | { |
mbed_official | 87:085cde657901 | 328 | /* Data Ready callback */ |
mbed_official | 87:085cde657901 | 329 | HAL_RNG_ReadyCallback(hrng); |
mbed_official | 87:085cde657901 | 330 | |
mbed_official | 87:085cde657901 | 331 | /* Change RNG peripheral state */ |
mbed_official | 87:085cde657901 | 332 | hrng->State = HAL_RNG_STATE_READY; |
mbed_official | 87:085cde657901 | 333 | |
mbed_official | 87:085cde657901 | 334 | /* Clear the RNG Data Ready flag */ |
mbed_official | 87:085cde657901 | 335 | __HAL_RNG_CLEAR_FLAG(hrng, RNG_FLAG_DRDY); |
mbed_official | 87:085cde657901 | 336 | |
mbed_official | 87:085cde657901 | 337 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 338 | __HAL_UNLOCK(hrng); |
mbed_official | 87:085cde657901 | 339 | } |
mbed_official | 87:085cde657901 | 340 | } |
mbed_official | 87:085cde657901 | 341 | |
mbed_official | 87:085cde657901 | 342 | /** |
mbed_official | 87:085cde657901 | 343 | * @brief Data Ready callback in non-blocking mode. |
mbed_official | 87:085cde657901 | 344 | * @param hrng: RNG handle |
mbed_official | 87:085cde657901 | 345 | * @retval None |
mbed_official | 87:085cde657901 | 346 | */ |
mbed_official | 87:085cde657901 | 347 | |
mbed_official | 87:085cde657901 | 348 | __weak void HAL_RNG_ReadyCallback(RNG_HandleTypeDef* hrng) |
mbed_official | 87:085cde657901 | 349 | { |
mbed_official | 87:085cde657901 | 350 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 351 | the HAL_RNG_ReadyCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 352 | */ |
mbed_official | 87:085cde657901 | 353 | } |
mbed_official | 87:085cde657901 | 354 | |
mbed_official | 87:085cde657901 | 355 | /** |
mbed_official | 87:085cde657901 | 356 | * @brief RNG error callbacks. |
mbed_official | 87:085cde657901 | 357 | * @param hrng: RNG handle |
mbed_official | 87:085cde657901 | 358 | * @retval None |
mbed_official | 87:085cde657901 | 359 | */ |
mbed_official | 87:085cde657901 | 360 | __weak void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng) |
mbed_official | 87:085cde657901 | 361 | { |
mbed_official | 87:085cde657901 | 362 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 363 | the HAL_RNG_ErrorCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 364 | */ |
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 | /** @defgroup RNG_Group3 Peripheral State functions |
mbed_official | 87:085cde657901 | 372 | * @brief Peripheral State functions. |
mbed_official | 87:085cde657901 | 373 | * |
mbed_official | 87:085cde657901 | 374 | @verbatim |
mbed_official | 87:085cde657901 | 375 | =============================================================================== |
mbed_official | 87:085cde657901 | 376 | ##### Peripheral State functions ##### |
mbed_official | 87:085cde657901 | 377 | =============================================================================== |
mbed_official | 87:085cde657901 | 378 | [..] |
mbed_official | 87:085cde657901 | 379 | This subsection permits to get in run-time the status of the peripheral |
mbed_official | 87:085cde657901 | 380 | and the data flow. |
mbed_official | 87:085cde657901 | 381 | |
mbed_official | 87:085cde657901 | 382 | @endverbatim |
mbed_official | 87:085cde657901 | 383 | * @{ |
mbed_official | 87:085cde657901 | 384 | */ |
mbed_official | 87:085cde657901 | 385 | |
mbed_official | 87:085cde657901 | 386 | /** |
mbed_official | 87:085cde657901 | 387 | * @brief Returns the RNG state. |
mbed_official | 87:085cde657901 | 388 | * @param hrng: RNG handle |
mbed_official | 87:085cde657901 | 389 | * @retval HAL state |
mbed_official | 87:085cde657901 | 390 | */ |
mbed_official | 87:085cde657901 | 391 | HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng) |
mbed_official | 87:085cde657901 | 392 | { |
mbed_official | 87:085cde657901 | 393 | return hrng->State; |
mbed_official | 87:085cde657901 | 394 | } |
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 | #endif /* HAL_RNG_MODULE_ENABLED */ |
mbed_official | 87:085cde657901 | 405 | /** |
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 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
mbed_official | 87:085cde657901 | 414 |