MacroRat / MouseCode

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sun May 14 23:18:57 2017 +0000
Revision:
18:6a4db94011d3
Publishing again

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 18:6a4db94011d3 1 /**
sahilmgandhi 18:6a4db94011d3 2 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 3 * @file stm32f1xx_hal_iwdg.c
sahilmgandhi 18:6a4db94011d3 4 * @author MCD Application Team
sahilmgandhi 18:6a4db94011d3 5 * @version V1.0.5
sahilmgandhi 18:6a4db94011d3 6 * @date 06-December-2016
sahilmgandhi 18:6a4db94011d3 7 * @brief IWDG HAL module driver.
sahilmgandhi 18:6a4db94011d3 8 * This file provides firmware functions to manage the following
sahilmgandhi 18:6a4db94011d3 9 * functionalities of the Independent Watchdog (IWDG) peripheral:
sahilmgandhi 18:6a4db94011d3 10 * + Initialization and Configuration functions
sahilmgandhi 18:6a4db94011d3 11 * + IO operation functions
sahilmgandhi 18:6a4db94011d3 12 * + Peripheral State functions
sahilmgandhi 18:6a4db94011d3 13 @verbatim
sahilmgandhi 18:6a4db94011d3 14 ================================================================================
sahilmgandhi 18:6a4db94011d3 15 ##### IWDG specific features #####
sahilmgandhi 18:6a4db94011d3 16 ================================================================================
sahilmgandhi 18:6a4db94011d3 17 [..]
sahilmgandhi 18:6a4db94011d3 18 (+) The IWDG can be started by either software or hardware (configurable
sahilmgandhi 18:6a4db94011d3 19 through option byte).
sahilmgandhi 18:6a4db94011d3 20 (+) The IWDG is clocked by its own dedicated Low-Speed clock (LSI) and
sahilmgandhi 18:6a4db94011d3 21 thus stays active even if the main clock fails.
sahilmgandhi 18:6a4db94011d3 22 (+) Once the IWDG is started, the LSI is forced ON and cannot be disabled
sahilmgandhi 18:6a4db94011d3 23 (LSI cannot be disabled too), and the counter starts counting down from
sahilmgandhi 18:6a4db94011d3 24 the reset value of 0xFFF. When it reaches the end of count value (0x000)
sahilmgandhi 18:6a4db94011d3 25 a system reset is generated.
sahilmgandhi 18:6a4db94011d3 26 (+) The IWDG counter should be refreshed at regular intervals, otherwise the
sahilmgandhi 18:6a4db94011d3 27 watchdog generates an MCU reset when the counter reaches 0.
sahilmgandhi 18:6a4db94011d3 28 (+) The IWDG is implemented in the VDD voltage domain that is still functional
sahilmgandhi 18:6a4db94011d3 29 in STOP and STANDBY mode (IWDG reset can wake-up from STANDBY).
sahilmgandhi 18:6a4db94011d3 30 (+) IWDGRST flag in RCC_CSR register can be used to inform when an IWDG
sahilmgandhi 18:6a4db94011d3 31 reset occurs.
sahilmgandhi 18:6a4db94011d3 32
sahilmgandhi 18:6a4db94011d3 33 (+) Min-max timeout value at 40KHz (LSI): 0.1us / 26.2s .
sahilmgandhi 18:6a4db94011d3 34 The IWDG timeout may vary due to LSI frequency dispersion. STM32F1xx
sahilmgandhi 18:6a4db94011d3 35 devices provide the capability to measure the LSI frequency (LSI clock
sahilmgandhi 18:6a4db94011d3 36 connected internally to TIM5 CH4 input capture). The measured value
sahilmgandhi 18:6a4db94011d3 37 can be used to have an IWDG timeout with an acceptable accuracy.
sahilmgandhi 18:6a4db94011d3 38 For more information, please refer to the STM32F1xx Reference manual.
sahilmgandhi 18:6a4db94011d3 39 Note: LSI Calibration is only available on: High density, XL-density and Connectivity line devices.
sahilmgandhi 18:6a4db94011d3 40
sahilmgandhi 18:6a4db94011d3 41 ##### How to use this driver #####
sahilmgandhi 18:6a4db94011d3 42 ==============================================================================
sahilmgandhi 18:6a4db94011d3 43 [..]
sahilmgandhi 18:6a4db94011d3 44 (+) Use IWDG using HAL_IWDG_Init() function to :
sahilmgandhi 18:6a4db94011d3 45 (++) Enable write access to IWDG_PR, IWDG_RLR.
sahilmgandhi 18:6a4db94011d3 46 (++) Configure the IWDG prescaler, counter reload value.
sahilmgandhi 18:6a4db94011d3 47 This reload value will be loaded in the IWDG counter each time the counter
sahilmgandhi 18:6a4db94011d3 48 is reloaded, then the IWDG will start counting down from this value.
sahilmgandhi 18:6a4db94011d3 49 (+) Use IWDG using HAL_IWDG_Start() function to :
sahilmgandhi 18:6a4db94011d3 50 (++) Reload IWDG counter with value defined in the IWDG_RLR register.
sahilmgandhi 18:6a4db94011d3 51 (++) Start the IWDG, when the IWDG is used in software mode (no need
sahilmgandhi 18:6a4db94011d3 52 to enable the LSI, it will be enabled by hardware).
sahilmgandhi 18:6a4db94011d3 53 (+) Then the application program must refresh the IWDG counter at regular
sahilmgandhi 18:6a4db94011d3 54 intervals during normal operation to prevent an MCU reset, using
sahilmgandhi 18:6a4db94011d3 55 HAL_IWDG_Refresh() function.
sahilmgandhi 18:6a4db94011d3 56
sahilmgandhi 18:6a4db94011d3 57 *** IWDG HAL driver macros list ***
sahilmgandhi 18:6a4db94011d3 58 ====================================
sahilmgandhi 18:6a4db94011d3 59 [..]
sahilmgandhi 18:6a4db94011d3 60 Below the list of most used macros in IWDG HAL driver.
sahilmgandhi 18:6a4db94011d3 61
sahilmgandhi 18:6a4db94011d3 62 (+) __HAL_IWDG_START: Enable the IWDG peripheral
sahilmgandhi 18:6a4db94011d3 63 (+) __HAL_IWDG_RELOAD_COUNTER: Reloads IWDG counter with value defined in the reload register
sahilmgandhi 18:6a4db94011d3 64 (+) __HAL_IWDG_GET_FLAG: Get the selected IWDG's flag status
sahilmgandhi 18:6a4db94011d3 65
sahilmgandhi 18:6a4db94011d3 66 @endverbatim
sahilmgandhi 18:6a4db94011d3 67 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 68 * @attention
sahilmgandhi 18:6a4db94011d3 69 *
sahilmgandhi 18:6a4db94011d3 70 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
sahilmgandhi 18:6a4db94011d3 71 *
sahilmgandhi 18:6a4db94011d3 72 * Redistribution and use in source and binary forms, with or without modification,
sahilmgandhi 18:6a4db94011d3 73 * are permitted provided that the following conditions are met:
sahilmgandhi 18:6a4db94011d3 74 * 1. Redistributions of source code must retain the above copyright notice,
sahilmgandhi 18:6a4db94011d3 75 * this list of conditions and the following disclaimer.
sahilmgandhi 18:6a4db94011d3 76 * 2. Redistributions in binary form must reproduce the above copyright notice,
sahilmgandhi 18:6a4db94011d3 77 * this list of conditions and the following disclaimer in the documentation
sahilmgandhi 18:6a4db94011d3 78 * and/or other materials provided with the distribution.
sahilmgandhi 18:6a4db94011d3 79 * 3. Neither the name of STMicroelectronics nor the names of its contributors
sahilmgandhi 18:6a4db94011d3 80 * may be used to endorse or promote products derived from this software
sahilmgandhi 18:6a4db94011d3 81 * without specific prior written permission.
sahilmgandhi 18:6a4db94011d3 82 *
sahilmgandhi 18:6a4db94011d3 83 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
sahilmgandhi 18:6a4db94011d3 84 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
sahilmgandhi 18:6a4db94011d3 85 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
sahilmgandhi 18:6a4db94011d3 86 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
sahilmgandhi 18:6a4db94011d3 87 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
sahilmgandhi 18:6a4db94011d3 88 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
sahilmgandhi 18:6a4db94011d3 89 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
sahilmgandhi 18:6a4db94011d3 90 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
sahilmgandhi 18:6a4db94011d3 91 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
sahilmgandhi 18:6a4db94011d3 92 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
sahilmgandhi 18:6a4db94011d3 93 *
sahilmgandhi 18:6a4db94011d3 94 ******************************************************************************
sahilmgandhi 18:6a4db94011d3 95 */
sahilmgandhi 18:6a4db94011d3 96
sahilmgandhi 18:6a4db94011d3 97 /* Includes ------------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 98 #include "stm32f1xx_hal.h"
sahilmgandhi 18:6a4db94011d3 99
sahilmgandhi 18:6a4db94011d3 100 /** @addtogroup STM32F1xx_HAL_Driver
sahilmgandhi 18:6a4db94011d3 101 * @{
sahilmgandhi 18:6a4db94011d3 102 */
sahilmgandhi 18:6a4db94011d3 103
sahilmgandhi 18:6a4db94011d3 104 /** @defgroup IWDG IWDG
sahilmgandhi 18:6a4db94011d3 105 * @brief IWDG HAL module driver.
sahilmgandhi 18:6a4db94011d3 106 * @{
sahilmgandhi 18:6a4db94011d3 107 */
sahilmgandhi 18:6a4db94011d3 108
sahilmgandhi 18:6a4db94011d3 109 #ifdef HAL_IWDG_MODULE_ENABLED
sahilmgandhi 18:6a4db94011d3 110
sahilmgandhi 18:6a4db94011d3 111 /* Private typedef -----------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 112 /* Private define ------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 113
sahilmgandhi 18:6a4db94011d3 114 /** @defgroup IWDG_Private_Constants IWDG Private Constants
sahilmgandhi 18:6a4db94011d3 115 * @{
sahilmgandhi 18:6a4db94011d3 116 */
sahilmgandhi 18:6a4db94011d3 117
sahilmgandhi 18:6a4db94011d3 118 #define IWDG_DEFAULT_TIMEOUT (uint32_t)1000
sahilmgandhi 18:6a4db94011d3 119
sahilmgandhi 18:6a4db94011d3 120 /**
sahilmgandhi 18:6a4db94011d3 121 * @}
sahilmgandhi 18:6a4db94011d3 122 */
sahilmgandhi 18:6a4db94011d3 123
sahilmgandhi 18:6a4db94011d3 124 /* Private macro -------------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 125 /* Private variables ---------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 126 /* Private function prototypes -----------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 127 /* Private functions ---------------------------------------------------------*/
sahilmgandhi 18:6a4db94011d3 128
sahilmgandhi 18:6a4db94011d3 129 /** @defgroup IWDG_Exported_Functions IWDG Exported Functions
sahilmgandhi 18:6a4db94011d3 130 * @{
sahilmgandhi 18:6a4db94011d3 131 */
sahilmgandhi 18:6a4db94011d3 132
sahilmgandhi 18:6a4db94011d3 133 /** @defgroup IWDG_Exported_Functions_Group1 Initialization and de-initialization functions
sahilmgandhi 18:6a4db94011d3 134 * @brief Initialization and Configuration functions.
sahilmgandhi 18:6a4db94011d3 135 *
sahilmgandhi 18:6a4db94011d3 136 @verbatim
sahilmgandhi 18:6a4db94011d3 137 ===============================================================================
sahilmgandhi 18:6a4db94011d3 138 ##### Initialization and de-initialization functions #####
sahilmgandhi 18:6a4db94011d3 139 ===============================================================================
sahilmgandhi 18:6a4db94011d3 140 [..] This section provides functions allowing to:
sahilmgandhi 18:6a4db94011d3 141 (+) Initialize the IWDG according to the specified parameters
sahilmgandhi 18:6a4db94011d3 142 in the IWDG_InitTypeDef and create the associated handle
sahilmgandhi 18:6a4db94011d3 143 (+) Initialize the IWDG MSP
sahilmgandhi 18:6a4db94011d3 144 (+) DeInitialize IWDG MSP
sahilmgandhi 18:6a4db94011d3 145
sahilmgandhi 18:6a4db94011d3 146 @endverbatim
sahilmgandhi 18:6a4db94011d3 147 * @{
sahilmgandhi 18:6a4db94011d3 148 */
sahilmgandhi 18:6a4db94011d3 149
sahilmgandhi 18:6a4db94011d3 150 /**
sahilmgandhi 18:6a4db94011d3 151 * @brief Initializes the IWDG according to the specified
sahilmgandhi 18:6a4db94011d3 152 * parameters in the IWDG_InitTypeDef and creates the associated handle.
sahilmgandhi 18:6a4db94011d3 153 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
sahilmgandhi 18:6a4db94011d3 154 * the configuration information for the specified IWDG module.
sahilmgandhi 18:6a4db94011d3 155 * @retval HAL status
sahilmgandhi 18:6a4db94011d3 156 */
sahilmgandhi 18:6a4db94011d3 157 HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
sahilmgandhi 18:6a4db94011d3 158 {
sahilmgandhi 18:6a4db94011d3 159 /* Check the IWDG handle allocation */
sahilmgandhi 18:6a4db94011d3 160 if(hiwdg == NULL)
sahilmgandhi 18:6a4db94011d3 161 {
sahilmgandhi 18:6a4db94011d3 162 return HAL_ERROR;
sahilmgandhi 18:6a4db94011d3 163 }
sahilmgandhi 18:6a4db94011d3 164
sahilmgandhi 18:6a4db94011d3 165 /* Check the parameters */
sahilmgandhi 18:6a4db94011d3 166 assert_param(IS_IWDG_ALL_INSTANCE(hiwdg->Instance));
sahilmgandhi 18:6a4db94011d3 167 assert_param(IS_IWDG_PRESCALER(hiwdg->Init.Prescaler));
sahilmgandhi 18:6a4db94011d3 168 assert_param(IS_IWDG_RELOAD(hiwdg->Init.Reload));
sahilmgandhi 18:6a4db94011d3 169
sahilmgandhi 18:6a4db94011d3 170 /* Check pending flag, if previous update not done, return error */
sahilmgandhi 18:6a4db94011d3 171 if((__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_PVU) != RESET)
sahilmgandhi 18:6a4db94011d3 172 &&(__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_RVU) != RESET))
sahilmgandhi 18:6a4db94011d3 173 {
sahilmgandhi 18:6a4db94011d3 174 return HAL_ERROR;
sahilmgandhi 18:6a4db94011d3 175 }
sahilmgandhi 18:6a4db94011d3 176
sahilmgandhi 18:6a4db94011d3 177 if(hiwdg->State == HAL_IWDG_STATE_RESET)
sahilmgandhi 18:6a4db94011d3 178 {
sahilmgandhi 18:6a4db94011d3 179 /* Allocate lock resource and initialize it */
sahilmgandhi 18:6a4db94011d3 180 hiwdg->Lock = HAL_UNLOCKED;
sahilmgandhi 18:6a4db94011d3 181
sahilmgandhi 18:6a4db94011d3 182 /* Init the low level hardware */
sahilmgandhi 18:6a4db94011d3 183 HAL_IWDG_MspInit(hiwdg);
sahilmgandhi 18:6a4db94011d3 184 }
sahilmgandhi 18:6a4db94011d3 185
sahilmgandhi 18:6a4db94011d3 186 /* Change IWDG peripheral state */
sahilmgandhi 18:6a4db94011d3 187 hiwdg->State = HAL_IWDG_STATE_BUSY;
sahilmgandhi 18:6a4db94011d3 188
sahilmgandhi 18:6a4db94011d3 189 /* Enable write access to IWDG_PR and IWDG_RLR registers */
sahilmgandhi 18:6a4db94011d3 190 IWDG_ENABLE_WRITE_ACCESS(hiwdg);
sahilmgandhi 18:6a4db94011d3 191
sahilmgandhi 18:6a4db94011d3 192 /* Write to IWDG registers the IWDG_Prescaler & IWDG_Reload values to work with */
sahilmgandhi 18:6a4db94011d3 193 MODIFY_REG(hiwdg->Instance->PR, IWDG_PR_PR, hiwdg->Init.Prescaler);
sahilmgandhi 18:6a4db94011d3 194 MODIFY_REG(hiwdg->Instance->RLR, IWDG_RLR_RL, hiwdg->Init.Reload);
sahilmgandhi 18:6a4db94011d3 195
sahilmgandhi 18:6a4db94011d3 196 /* Change IWDG peripheral state */
sahilmgandhi 18:6a4db94011d3 197 hiwdg->State = HAL_IWDG_STATE_READY;
sahilmgandhi 18:6a4db94011d3 198
sahilmgandhi 18:6a4db94011d3 199 /* Return function status */
sahilmgandhi 18:6a4db94011d3 200 return HAL_OK;
sahilmgandhi 18:6a4db94011d3 201 }
sahilmgandhi 18:6a4db94011d3 202
sahilmgandhi 18:6a4db94011d3 203 /**
sahilmgandhi 18:6a4db94011d3 204 * @brief Initializes the IWDG MSP.
sahilmgandhi 18:6a4db94011d3 205 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
sahilmgandhi 18:6a4db94011d3 206 * the configuration information for the specified IWDG module.
sahilmgandhi 18:6a4db94011d3 207 * @retval None
sahilmgandhi 18:6a4db94011d3 208 */
sahilmgandhi 18:6a4db94011d3 209 __weak void HAL_IWDG_MspInit(IWDG_HandleTypeDef *hiwdg)
sahilmgandhi 18:6a4db94011d3 210 {
sahilmgandhi 18:6a4db94011d3 211 /* Prevent unused argument(s) compilation warning */
sahilmgandhi 18:6a4db94011d3 212 UNUSED(hiwdg);
sahilmgandhi 18:6a4db94011d3 213 /* NOTE : This function Should not be modified, when the callback is needed,
sahilmgandhi 18:6a4db94011d3 214 the HAL_IWDG_MspInit could be implemented in the user file
sahilmgandhi 18:6a4db94011d3 215 */
sahilmgandhi 18:6a4db94011d3 216 }
sahilmgandhi 18:6a4db94011d3 217
sahilmgandhi 18:6a4db94011d3 218 /**
sahilmgandhi 18:6a4db94011d3 219 * @}
sahilmgandhi 18:6a4db94011d3 220 */
sahilmgandhi 18:6a4db94011d3 221
sahilmgandhi 18:6a4db94011d3 222 /** @defgroup IWDG_Exported_Functions_Group2 IO operation functions
sahilmgandhi 18:6a4db94011d3 223 * @brief IO operation functions
sahilmgandhi 18:6a4db94011d3 224 *
sahilmgandhi 18:6a4db94011d3 225 @verbatim
sahilmgandhi 18:6a4db94011d3 226 ===============================================================================
sahilmgandhi 18:6a4db94011d3 227 ##### IO operation functions #####
sahilmgandhi 18:6a4db94011d3 228 ===============================================================================
sahilmgandhi 18:6a4db94011d3 229 [..] This section provides functions allowing to:
sahilmgandhi 18:6a4db94011d3 230 (+) Start the IWDG.
sahilmgandhi 18:6a4db94011d3 231 (+) Refresh the IWDG.
sahilmgandhi 18:6a4db94011d3 232
sahilmgandhi 18:6a4db94011d3 233 @endverbatim
sahilmgandhi 18:6a4db94011d3 234 * @{
sahilmgandhi 18:6a4db94011d3 235 */
sahilmgandhi 18:6a4db94011d3 236
sahilmgandhi 18:6a4db94011d3 237 /**
sahilmgandhi 18:6a4db94011d3 238 * @brief Starts the IWDG.
sahilmgandhi 18:6a4db94011d3 239 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
sahilmgandhi 18:6a4db94011d3 240 * the configuration information for the specified IWDG module.
sahilmgandhi 18:6a4db94011d3 241 * @retval HAL status
sahilmgandhi 18:6a4db94011d3 242 */
sahilmgandhi 18:6a4db94011d3 243 HAL_StatusTypeDef HAL_IWDG_Start(IWDG_HandleTypeDef *hiwdg)
sahilmgandhi 18:6a4db94011d3 244 {
sahilmgandhi 18:6a4db94011d3 245 /* Process Locked */
sahilmgandhi 18:6a4db94011d3 246 __HAL_LOCK(hiwdg);
sahilmgandhi 18:6a4db94011d3 247
sahilmgandhi 18:6a4db94011d3 248 /* Change IWDG peripheral state */
sahilmgandhi 18:6a4db94011d3 249 hiwdg->State = HAL_IWDG_STATE_BUSY;
sahilmgandhi 18:6a4db94011d3 250
sahilmgandhi 18:6a4db94011d3 251 /* Start the IWDG peripheral */
sahilmgandhi 18:6a4db94011d3 252 __HAL_IWDG_START(hiwdg);
sahilmgandhi 18:6a4db94011d3 253
sahilmgandhi 18:6a4db94011d3 254 /* Reload IWDG counter with value defined in the RLR register */
sahilmgandhi 18:6a4db94011d3 255 __HAL_IWDG_RELOAD_COUNTER(hiwdg);
sahilmgandhi 18:6a4db94011d3 256
sahilmgandhi 18:6a4db94011d3 257 /* Change IWDG peripheral state */
sahilmgandhi 18:6a4db94011d3 258 hiwdg->State = HAL_IWDG_STATE_READY;
sahilmgandhi 18:6a4db94011d3 259
sahilmgandhi 18:6a4db94011d3 260 /* Process Unlocked */
sahilmgandhi 18:6a4db94011d3 261 __HAL_UNLOCK(hiwdg);
sahilmgandhi 18:6a4db94011d3 262
sahilmgandhi 18:6a4db94011d3 263 /* Return function status */
sahilmgandhi 18:6a4db94011d3 264 return HAL_OK;
sahilmgandhi 18:6a4db94011d3 265 }
sahilmgandhi 18:6a4db94011d3 266
sahilmgandhi 18:6a4db94011d3 267 /**
sahilmgandhi 18:6a4db94011d3 268 * @brief Refreshes the IWDG.
sahilmgandhi 18:6a4db94011d3 269 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
sahilmgandhi 18:6a4db94011d3 270 * the configuration information for the specified IWDG module.
sahilmgandhi 18:6a4db94011d3 271 * @retval HAL status
sahilmgandhi 18:6a4db94011d3 272 */
sahilmgandhi 18:6a4db94011d3 273 HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg)
sahilmgandhi 18:6a4db94011d3 274 {
sahilmgandhi 18:6a4db94011d3 275 uint32_t tickstart = 0;
sahilmgandhi 18:6a4db94011d3 276
sahilmgandhi 18:6a4db94011d3 277 /* Process Locked */
sahilmgandhi 18:6a4db94011d3 278 __HAL_LOCK(hiwdg);
sahilmgandhi 18:6a4db94011d3 279
sahilmgandhi 18:6a4db94011d3 280 /* Change IWDG peripheral state */
sahilmgandhi 18:6a4db94011d3 281 hiwdg->State = HAL_IWDG_STATE_BUSY;
sahilmgandhi 18:6a4db94011d3 282
sahilmgandhi 18:6a4db94011d3 283 tickstart = HAL_GetTick();
sahilmgandhi 18:6a4db94011d3 284
sahilmgandhi 18:6a4db94011d3 285 /* Wait until RVU flag is RESET */
sahilmgandhi 18:6a4db94011d3 286 while(__HAL_IWDG_GET_FLAG(hiwdg, IWDG_FLAG_RVU) != RESET)
sahilmgandhi 18:6a4db94011d3 287 {
sahilmgandhi 18:6a4db94011d3 288 if((HAL_GetTick() - tickstart ) > IWDG_DEFAULT_TIMEOUT)
sahilmgandhi 18:6a4db94011d3 289 {
sahilmgandhi 18:6a4db94011d3 290 /* Set IWDG state */
sahilmgandhi 18:6a4db94011d3 291 hiwdg->State = HAL_IWDG_STATE_TIMEOUT;
sahilmgandhi 18:6a4db94011d3 292
sahilmgandhi 18:6a4db94011d3 293 /* Process unlocked */
sahilmgandhi 18:6a4db94011d3 294 __HAL_UNLOCK(hiwdg);
sahilmgandhi 18:6a4db94011d3 295
sahilmgandhi 18:6a4db94011d3 296 return HAL_TIMEOUT;
sahilmgandhi 18:6a4db94011d3 297 }
sahilmgandhi 18:6a4db94011d3 298 }
sahilmgandhi 18:6a4db94011d3 299
sahilmgandhi 18:6a4db94011d3 300 /* Reload IWDG counter with value defined in the reload register */
sahilmgandhi 18:6a4db94011d3 301 __HAL_IWDG_RELOAD_COUNTER(hiwdg);
sahilmgandhi 18:6a4db94011d3 302
sahilmgandhi 18:6a4db94011d3 303 /* Change IWDG peripheral state */
sahilmgandhi 18:6a4db94011d3 304 hiwdg->State = HAL_IWDG_STATE_READY;
sahilmgandhi 18:6a4db94011d3 305
sahilmgandhi 18:6a4db94011d3 306 /* Process Unlocked */
sahilmgandhi 18:6a4db94011d3 307 __HAL_UNLOCK(hiwdg);
sahilmgandhi 18:6a4db94011d3 308
sahilmgandhi 18:6a4db94011d3 309 /* Return function status */
sahilmgandhi 18:6a4db94011d3 310 return HAL_OK;
sahilmgandhi 18:6a4db94011d3 311 }
sahilmgandhi 18:6a4db94011d3 312
sahilmgandhi 18:6a4db94011d3 313 /**
sahilmgandhi 18:6a4db94011d3 314 * @}
sahilmgandhi 18:6a4db94011d3 315 */
sahilmgandhi 18:6a4db94011d3 316
sahilmgandhi 18:6a4db94011d3 317 /** @defgroup IWDG_Exported_Functions_Group3 Peripheral State functions
sahilmgandhi 18:6a4db94011d3 318 * @brief Peripheral State functions.
sahilmgandhi 18:6a4db94011d3 319 *
sahilmgandhi 18:6a4db94011d3 320 @verbatim
sahilmgandhi 18:6a4db94011d3 321 ===============================================================================
sahilmgandhi 18:6a4db94011d3 322 ##### Peripheral State functions #####
sahilmgandhi 18:6a4db94011d3 323 ===============================================================================
sahilmgandhi 18:6a4db94011d3 324 [..]
sahilmgandhi 18:6a4db94011d3 325 This subsection permits to get in run-time the status of the peripheral
sahilmgandhi 18:6a4db94011d3 326 and the data flow.
sahilmgandhi 18:6a4db94011d3 327
sahilmgandhi 18:6a4db94011d3 328 @endverbatim
sahilmgandhi 18:6a4db94011d3 329 * @{
sahilmgandhi 18:6a4db94011d3 330 */
sahilmgandhi 18:6a4db94011d3 331
sahilmgandhi 18:6a4db94011d3 332 /**
sahilmgandhi 18:6a4db94011d3 333 * @brief Returns the IWDG state.
sahilmgandhi 18:6a4db94011d3 334 * @param hiwdg: pointer to a IWDG_HandleTypeDef structure that contains
sahilmgandhi 18:6a4db94011d3 335 * the configuration information for the specified IWDG module.
sahilmgandhi 18:6a4db94011d3 336 * @retval HAL state
sahilmgandhi 18:6a4db94011d3 337 */
sahilmgandhi 18:6a4db94011d3 338 HAL_IWDG_StateTypeDef HAL_IWDG_GetState(IWDG_HandleTypeDef *hiwdg)
sahilmgandhi 18:6a4db94011d3 339 {
sahilmgandhi 18:6a4db94011d3 340 return hiwdg->State;
sahilmgandhi 18:6a4db94011d3 341 }
sahilmgandhi 18:6a4db94011d3 342
sahilmgandhi 18:6a4db94011d3 343 /**
sahilmgandhi 18:6a4db94011d3 344 * @}
sahilmgandhi 18:6a4db94011d3 345 */
sahilmgandhi 18:6a4db94011d3 346
sahilmgandhi 18:6a4db94011d3 347 /**
sahilmgandhi 18:6a4db94011d3 348 * @}
sahilmgandhi 18:6a4db94011d3 349 */
sahilmgandhi 18:6a4db94011d3 350
sahilmgandhi 18:6a4db94011d3 351 #endif /* HAL_IWDG_MODULE_ENABLED */
sahilmgandhi 18:6a4db94011d3 352 /**
sahilmgandhi 18:6a4db94011d3 353 * @}
sahilmgandhi 18:6a4db94011d3 354 */
sahilmgandhi 18:6a4db94011d3 355
sahilmgandhi 18:6a4db94011d3 356 /**
sahilmgandhi 18:6a4db94011d3 357 * @}
sahilmgandhi 18:6a4db94011d3 358 */
sahilmgandhi 18:6a4db94011d3 359
sahilmgandhi 18:6a4db94011d3 360 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/