annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_rng.c @ 60:96026ba1834f

more language updates
author heinrichsweikamp
date Fri, 10 Aug 2018 19:40:55 +0200
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file stm32f4xx_hal_rng.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V1.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 26-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief RNG HAL module driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * This file provides firmware functions to manage the following
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * functionalities of the Random Number Generator (RNG) peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * + Initialization/de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * + Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 * + Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 ##### How to use this driver #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 The RNG HAL driver can be used as follows:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 (#) Enable the RNG controller clock using __HAL_RCC_RNG_CLK_ENABLE() macro
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 in HAL_RNG_MspInit().
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 (#) Activate the RNG peripheral using HAL_RNG_Init() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 (#) Wait until the 32 bit Random Number Generator contains a valid
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 random data using (polling/interrupt) mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 (#) Get the 32 bit random number using HAL_RNG_GenerateRandomNumber() function.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 /** @addtogroup RNG
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 #ifdef HAL_RNG_MODULE_ENABLED
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 /* Private types -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 /* Private defines -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 /* Private constants ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 /** @addtogroup RNG_Private_Constants
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 #define RNG_TIMEOUT_VALUE 2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 /* Private macros ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 /* Private functions prototypes ----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 /** @addtogroup RNG_Exported_Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 /** @addtogroup RNG_Exported_Functions_Group1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 * @brief Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 ##### Initialization and de-initialization functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 [..] This section provides functions allowing to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 (+) Initialize the RNG according to the specified parameters
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 in the RNG_InitTypeDef and create the associated handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 (+) DeInitialize the RNG peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 (+) Initialize the RNG MSP
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 (+) DeInitialize RNG MSP
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 * @brief Initializes the RNG peripheral and creates the associated handle.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 * the configuration information for RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 HAL_StatusTypeDef HAL_RNG_Init(RNG_HandleTypeDef *hrng)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 /* Check the RNG handle allocation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 if(hrng == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 __HAL_LOCK(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 if(hrng->State == HAL_RNG_STATE_RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 /* Init the low level hardware */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 HAL_RNG_MspInit(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 /* Change RNG peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 hrng->State = HAL_RNG_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 /* Enable the RNG Peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 __HAL_RNG_ENABLE(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 /* Initialize the RNG state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 hrng->State = HAL_RNG_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 __HAL_UNLOCK(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 /* Return function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 * @brief DeInitializes the RNG peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 * the configuration information for RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 HAL_StatusTypeDef HAL_RNG_DeInit(RNG_HandleTypeDef *hrng)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 /* Check the RNG handle allocation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 if(hrng == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 /* Disable the RNG Peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 CLEAR_BIT(hrng->Instance->CR, RNG_CR_IE | RNG_CR_RNGEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 /* Clear RNG interrupt status flags */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 CLEAR_BIT(hrng->Instance->SR, RNG_SR_CEIS | RNG_SR_SEIS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 /* DeInit the low level hardware */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 HAL_RNG_MspDeInit(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 /* Update the RNG state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 hrng->State = HAL_RNG_STATE_RESET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 /* Release Lock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 __HAL_UNLOCK(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 /* Return the function status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 * @brief Initializes the RNG MSP.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 * the configuration information for RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 __weak void HAL_RNG_MspInit(RNG_HandleTypeDef *hrng)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 /* NOTE : This function should not be modified. When the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 function HAL_RNG_MspInit must be implemented in the user file.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 * @brief DeInitializes the RNG MSP.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 * the configuration information for RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 __weak void HAL_RNG_MspDeInit(RNG_HandleTypeDef *hrng)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 /* NOTE : This function should not be modified. When the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 function HAL_RNG_MspDeInit must be implemented in the user file.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 /** @addtogroup RNG_Exported_Functions_Group2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 * @brief Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 ##### Peripheral Control functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 [..] This section provides functions allowing to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 (+) Get the 32 bit Random number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 (+) Get the 32 bit Random number with interrupt enabled
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 (+) Handle RNG interrupt request
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 * @brief Generates a 32-bit random number.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 * @note Each time the random number data is read the RNG_FLAG_DRDY flag
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 * is automatically cleared.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 * the configuration information for RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 * @param random32bit: pointer to generated random number variable if successful.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber(RNG_HandleTypeDef *hrng, uint32_t *random32bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 __HAL_LOCK(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 /* Check RNG peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 if(hrng->State == HAL_RNG_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 /* Change RNG peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 hrng->State = HAL_RNG_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 /* Check if data register contains valid random data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 while(__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_DRDY) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 if((HAL_GetTick() - tickstart ) > RNG_TIMEOUT_VALUE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 hrng->State = HAL_RNG_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 __HAL_UNLOCK(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 /* Get a 32bit Random number */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 hrng->RandomNumber = hrng->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 *random32bit = hrng->RandomNumber;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 hrng->State = HAL_RNG_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 status = HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 __HAL_UNLOCK(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 * @brief Generates a 32-bit random number in interrupt mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 * the configuration information for RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 HAL_StatusTypeDef HAL_RNG_GenerateRandomNumber_IT(RNG_HandleTypeDef *hrng)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 __HAL_LOCK(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 /* Check RNG peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 if(hrng->State == HAL_RNG_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 /* Change RNG peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 hrng->State = HAL_RNG_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 __HAL_UNLOCK(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 /* Enable the RNG Interrupts: Data Ready, Clock error, Seed error */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 __HAL_RNG_ENABLE_IT(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 __HAL_UNLOCK(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 status = HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 * @brief Handles RNG interrupt request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 * @note In the case of a clock error, the RNG is no more able to generate
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 * random numbers because the PLL48CLK clock is not correct. User has
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 * to check that the clock controller is correctly configured to provide
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 * the RNG clock and clear the CEIS bit using __HAL_RNG_CLEAR_IT().
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 * The clock error has no impact on the previously generated
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 * random numbers, and the RNG_DR register contents can be used.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 * @note In the case of a seed error, the generation of random numbers is
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 * interrupted as long as the SECS bit is '1'. If a number is
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 * available in the RNG_DR register, it must not be used because it may
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 * not have enough entropy. In this case, it is recommended to clear the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 * SEIS bit using __HAL_RNG_CLEAR_IT(), then disable and enable
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 * the RNG peripheral to reinitialize and restart the RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 * @note User-written HAL_RNG_ErrorCallback() API is called once whether SEIS
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 * or CEIS are set.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 * the configuration information for RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 void HAL_RNG_IRQHandler(RNG_HandleTypeDef *hrng)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 /* RNG clock error interrupt occurred */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 if((__HAL_RNG_GET_IT(hrng, RNG_IT_CEI) != RESET) || (__HAL_RNG_GET_IT(hrng, RNG_IT_SEI) != RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 /* Change RNG peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 hrng->State = HAL_RNG_STATE_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 HAL_RNG_ErrorCallback(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 /* Clear the clock error flag */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 __HAL_RNG_CLEAR_IT(hrng, RNG_IT_CEI|RNG_IT_SEI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 /* Check RNG data ready interrupt occurred */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 if(__HAL_RNG_GET_IT(hrng, RNG_IT_DRDY) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 /* Generate random number once, so disable the IT */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 __HAL_RNG_DISABLE_IT(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 /* Get the 32bit Random number (DRDY flag automatically cleared) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 hrng->RandomNumber = hrng->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 if(hrng->State != HAL_RNG_STATE_ERROR)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 /* Change RNG peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 hrng->State = HAL_RNG_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 /* Data Ready callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 HAL_RNG_ReadyDataCallback(hrng, hrng->RandomNumber);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 * @brief Returns generated random number in polling mode (Obsolete)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 * Use HAL_RNG_GenerateRandomNumber() API instead.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 * the configuration information for RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 * @retval Random value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 uint32_t HAL_RNG_GetRandomNumber(RNG_HandleTypeDef *hrng)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 if(HAL_RNG_GenerateRandomNumber(hrng, &(hrng->RandomNumber)) == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 return hrng->RandomNumber;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 * @brief Returns a 32-bit random number with interrupt enabled (Obsolete),
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 * Use HAL_RNG_GenerateRandomNumber_IT() API instead.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 * the configuration information for RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 * @retval 32-bit random number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 uint32_t HAL_RNG_GetRandomNumber_IT(RNG_HandleTypeDef *hrng)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 uint32_t random32bit = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 /* Process locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 __HAL_LOCK(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 /* Change RNG peripheral state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 hrng->State = HAL_RNG_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 /* Get a 32bit Random number */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 random32bit = hrng->Instance->DR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 /* Enable the RNG Interrupts: Data Ready, Clock error, Seed error */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 __HAL_RNG_ENABLE_IT(hrng);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 /* Return the 32 bit random number */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 return random32bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 * @brief Read latest generated random number.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 * the configuration information for RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 * @retval random value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 uint32_t HAL_RNG_ReadLastRandomNumber(RNG_HandleTypeDef *hrng)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 return(hrng->RandomNumber);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 * @brief Data Ready callback in non-blocking mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 * the configuration information for RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 * @param random32bit: generated random number.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 __weak void HAL_RNG_ReadyDataCallback(RNG_HandleTypeDef *hrng, uint32_t random32bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 /* NOTE : This function should not be modified. When the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 function HAL_RNG_ReadyDataCallback must be implemented in the user file.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 * @brief RNG error callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 * the configuration information for RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 __weak void HAL_RNG_ErrorCallback(RNG_HandleTypeDef *hrng)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 /* NOTE : This function should not be modified. When the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 function HAL_RNG_ErrorCallback must be implemented in the user file.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 /** @addtogroup RNG_Exported_Functions_Group3
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 * @brief Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 ##### Peripheral State functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 This subsection permits to get in run-time the status of the peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 and the data flow.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 * @brief Returns the RNG state.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 * @param hrng: pointer to a RNG_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 * the configuration information for RNG.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 HAL_RNG_StateTypeDef HAL_RNG_GetState(RNG_HandleTypeDef *hrng)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 return hrng->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 #endif /* HAL_RNG_MODULE_ENABLED */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/