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