SPKT

Dependents:   WAV

Committer:
phungductung
Date:
Tue Jun 04 21:51:46 2019 +0000
Revision:
0:e87aa4c49e95
libray

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phungductung 0:e87aa4c49e95 1 /**
phungductung 0:e87aa4c49e95 2 ******************************************************************************
phungductung 0:e87aa4c49e95 3 * @file stm32f7xx_hal_wwdg.c
phungductung 0:e87aa4c49e95 4 * @author MCD Application Team
phungductung 0:e87aa4c49e95 5 * @version V1.0.4
phungductung 0:e87aa4c49e95 6 * @date 09-December-2015
phungductung 0:e87aa4c49e95 7 * @brief WWDG HAL module driver.
phungductung 0:e87aa4c49e95 8 * This file provides firmware functions to manage the following
phungductung 0:e87aa4c49e95 9 * functionalities of the Window Watchdog (WWDG) peripheral:
phungductung 0:e87aa4c49e95 10 * + Initialization and de-initialization functions
phungductung 0:e87aa4c49e95 11 * + IO operation functions
phungductung 0:e87aa4c49e95 12 * + Peripheral State functions
phungductung 0:e87aa4c49e95 13 @verbatim
phungductung 0:e87aa4c49e95 14 ==============================================================================
phungductung 0:e87aa4c49e95 15 ##### WWDG specific features #####
phungductung 0:e87aa4c49e95 16 ==============================================================================
phungductung 0:e87aa4c49e95 17 [..]
phungductung 0:e87aa4c49e95 18 Once enabled the WWDG generates a system reset on expiry of a programmed
phungductung 0:e87aa4c49e95 19 time period, unless the program refreshes the counter (down-counter)
phungductung 0:e87aa4c49e95 20 before reaching 0x3F value (i.e. a reset is generated when the counter
phungductung 0:e87aa4c49e95 21 value rolls over from 0x40 to 0x3F).
phungductung 0:e87aa4c49e95 22
phungductung 0:e87aa4c49e95 23 (+) An MCU reset is also generated if the counter value is refreshed
phungductung 0:e87aa4c49e95 24 before the counter has reached the refresh window value. This
phungductung 0:e87aa4c49e95 25 implies that the counter must be refreshed in a limited window.
phungductung 0:e87aa4c49e95 26 (+) Once enabled the WWDG cannot be disabled except by a system reset.
phungductung 0:e87aa4c49e95 27 (+) WWDGRST flag in RCC_CSR register can be used to inform when a WWDG
phungductung 0:e87aa4c49e95 28 reset occurs.
phungductung 0:e87aa4c49e95 29 (+) The WWDG counter input clock is derived from the APB clock divided
phungductung 0:e87aa4c49e95 30 by a programmable prescaler.
phungductung 0:e87aa4c49e95 31 (+) WWDG clock (Hz) = PCLK1 / (4096 * Prescaler)
phungductung 0:e87aa4c49e95 32 (+) WWDG timeout (mS) = 1000 * Counter / WWDG clock
phungductung 0:e87aa4c49e95 33 (+) WWDG Counter refresh is allowed between the following limits :
phungductung 0:e87aa4c49e95 34 (++) min time (mS) = 1000 * (Counter - Window) / WWDG clock
phungductung 0:e87aa4c49e95 35 (++) max time (mS) = 1000 * (Counter - 0x40) / WWDG clock
phungductung 0:e87aa4c49e95 36
phungductung 0:e87aa4c49e95 37 (+) Min-max timeout value at 50 MHz(PCLK1): 81.9 us / 41.9 ms
phungductung 0:e87aa4c49e95 38
phungductung 0:e87aa4c49e95 39
phungductung 0:e87aa4c49e95 40 ##### How to use this driver #####
phungductung 0:e87aa4c49e95 41 ==============================================================================
phungductung 0:e87aa4c49e95 42 [..]
phungductung 0:e87aa4c49e95 43 (+) Enable WWDG APB1 clock using __HAL_RCC_WWDG_CLK_ENABLE().
phungductung 0:e87aa4c49e95 44 (+) Set the WWDG prescaler, refresh window and counter value
phungductung 0:e87aa4c49e95 45 using HAL_WWDG_Init() function.
phungductung 0:e87aa4c49e95 46 (+) Start the WWDG using HAL_WWDG_Start() function.
phungductung 0:e87aa4c49e95 47 When the WWDG is enabled the counter value should be configured to
phungductung 0:e87aa4c49e95 48 a value greater than 0x40 to prevent generating an immediate reset.
phungductung 0:e87aa4c49e95 49 (+) Optionally you can enable the Early Wakeup Interrupt (EWI) which is
phungductung 0:e87aa4c49e95 50 generated when the counter reaches 0x40, and then start the WWDG using
phungductung 0:e87aa4c49e95 51 HAL_WWDG_Start_IT(). At EWI HAL_WWDG_WakeupCallback is executed and user can
phungductung 0:e87aa4c49e95 52 add his own code by customization of function pointer HAL_WWDG_WakeupCallback
phungductung 0:e87aa4c49e95 53 Once enabled, EWI interrupt cannot be disabled except by a system reset.
phungductung 0:e87aa4c49e95 54 (+) Then the application program must refresh the WWDG counter at regular
phungductung 0:e87aa4c49e95 55 intervals during normal operation to prevent an MCU reset, using
phungductung 0:e87aa4c49e95 56 HAL_WWDG_Refresh() function. This operation must occur only when
phungductung 0:e87aa4c49e95 57 the counter is lower than the refresh window value already programmed.
phungductung 0:e87aa4c49e95 58
phungductung 0:e87aa4c49e95 59 *** WWDG HAL driver macros list ***
phungductung 0:e87aa4c49e95 60 ==================================
phungductung 0:e87aa4c49e95 61 [..]
phungductung 0:e87aa4c49e95 62 Below the list of most used macros in WWDG HAL driver.
phungductung 0:e87aa4c49e95 63
phungductung 0:e87aa4c49e95 64 (+) __HAL_WWDG_ENABLE: Enable the WWDG peripheral
phungductung 0:e87aa4c49e95 65 (+) __HAL_WWDG_GET_FLAG: Get the selected WWDG's flag status
phungductung 0:e87aa4c49e95 66 (+) __HAL_WWDG_CLEAR_FLAG: Clear the WWDG's pending flags
phungductung 0:e87aa4c49e95 67 (+) __HAL_WWDG_ENABLE_IT: Enables the WWDG early wake-up interrupt
phungductung 0:e87aa4c49e95 68
phungductung 0:e87aa4c49e95 69 @endverbatim
phungductung 0:e87aa4c49e95 70 ******************************************************************************
phungductung 0:e87aa4c49e95 71 * @attention
phungductung 0:e87aa4c49e95 72 *
phungductung 0:e87aa4c49e95 73 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
phungductung 0:e87aa4c49e95 74 *
phungductung 0:e87aa4c49e95 75 * Redistribution and use in source and binary forms, with or without modification,
phungductung 0:e87aa4c49e95 76 * are permitted provided that the following conditions are met:
phungductung 0:e87aa4c49e95 77 * 1. Redistributions of source code must retain the above copyright notice,
phungductung 0:e87aa4c49e95 78 * this list of conditions and the following disclaimer.
phungductung 0:e87aa4c49e95 79 * 2. Redistributions in binary form must reproduce the above copyright notice,
phungductung 0:e87aa4c49e95 80 * this list of conditions and the following disclaimer in the documentation
phungductung 0:e87aa4c49e95 81 * and/or other materials provided with the distribution.
phungductung 0:e87aa4c49e95 82 * 3. Neither the name of STMicroelectronics nor the names of its contributors
phungductung 0:e87aa4c49e95 83 * may be used to endorse or promote products derived from this software
phungductung 0:e87aa4c49e95 84 * without specific prior written permission.
phungductung 0:e87aa4c49e95 85 *
phungductung 0:e87aa4c49e95 86 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
phungductung 0:e87aa4c49e95 87 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
phungductung 0:e87aa4c49e95 88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
phungductung 0:e87aa4c49e95 89 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
phungductung 0:e87aa4c49e95 90 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
phungductung 0:e87aa4c49e95 91 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
phungductung 0:e87aa4c49e95 92 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
phungductung 0:e87aa4c49e95 93 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
phungductung 0:e87aa4c49e95 94 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
phungductung 0:e87aa4c49e95 95 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
phungductung 0:e87aa4c49e95 96 *
phungductung 0:e87aa4c49e95 97 ******************************************************************************
phungductung 0:e87aa4c49e95 98 */
phungductung 0:e87aa4c49e95 99
phungductung 0:e87aa4c49e95 100 /* Includes ------------------------------------------------------------------*/
phungductung 0:e87aa4c49e95 101 #include "stm32f7xx_hal.h"
phungductung 0:e87aa4c49e95 102
phungductung 0:e87aa4c49e95 103 /** @addtogroup STM32F7xx_HAL_Driver
phungductung 0:e87aa4c49e95 104 * @{
phungductung 0:e87aa4c49e95 105 */
phungductung 0:e87aa4c49e95 106
phungductung 0:e87aa4c49e95 107 /** @defgroup WWDG WWDG
phungductung 0:e87aa4c49e95 108 * @brief WWDG HAL module driver.
phungductung 0:e87aa4c49e95 109 * @{
phungductung 0:e87aa4c49e95 110 */
phungductung 0:e87aa4c49e95 111
phungductung 0:e87aa4c49e95 112 #ifdef HAL_WWDG_MODULE_ENABLED
phungductung 0:e87aa4c49e95 113
phungductung 0:e87aa4c49e95 114 /* Private typedef -----------------------------------------------------------*/
phungductung 0:e87aa4c49e95 115 /* Private define ------------------------------------------------------------*/
phungductung 0:e87aa4c49e95 116 /* Private macro -------------------------------------------------------------*/
phungductung 0:e87aa4c49e95 117 /* Private variables ---------------------------------------------------------*/
phungductung 0:e87aa4c49e95 118 /* Private function prototypes -----------------------------------------------*/
phungductung 0:e87aa4c49e95 119 /* Exported functions --------------------------------------------------------*/
phungductung 0:e87aa4c49e95 120 /** @defgroup WWDG_Exported_Functions WWDG Exported Functions
phungductung 0:e87aa4c49e95 121 * @{
phungductung 0:e87aa4c49e95 122 */
phungductung 0:e87aa4c49e95 123
phungductung 0:e87aa4c49e95 124 /** @defgroup WWDG_Exported_Functions_Group1 Initialization and de-initialization functions
phungductung 0:e87aa4c49e95 125 * @brief Initialization and Configuration functions.
phungductung 0:e87aa4c49e95 126 *
phungductung 0:e87aa4c49e95 127 @verbatim
phungductung 0:e87aa4c49e95 128 ==============================================================================
phungductung 0:e87aa4c49e95 129 ##### Initialization and de-initialization functions #####
phungductung 0:e87aa4c49e95 130 ==============================================================================
phungductung 0:e87aa4c49e95 131 [..]
phungductung 0:e87aa4c49e95 132 This section provides functions allowing to:
phungductung 0:e87aa4c49e95 133 (+) Initialize the WWDG according to the specified parameters
phungductung 0:e87aa4c49e95 134 in the WWDG_InitTypeDef and create the associated handle
phungductung 0:e87aa4c49e95 135 (+) DeInitialize the WWDG peripheral
phungductung 0:e87aa4c49e95 136 (+) Initialize the WWDG MSP
phungductung 0:e87aa4c49e95 137 (+) DeInitialize the WWDG MSP
phungductung 0:e87aa4c49e95 138
phungductung 0:e87aa4c49e95 139 @endverbatim
phungductung 0:e87aa4c49e95 140 * @{
phungductung 0:e87aa4c49e95 141 */
phungductung 0:e87aa4c49e95 142
phungductung 0:e87aa4c49e95 143 /**
phungductung 0:e87aa4c49e95 144 * @brief Initializes the WWDG according to the specified
phungductung 0:e87aa4c49e95 145 * parameters in the WWDG_InitTypeDef and creates the associated handle.
phungductung 0:e87aa4c49e95 146 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
phungductung 0:e87aa4c49e95 147 * the configuration information for the specified WWDG module.
phungductung 0:e87aa4c49e95 148 * @retval HAL status
phungductung 0:e87aa4c49e95 149 */
phungductung 0:e87aa4c49e95 150 HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
phungductung 0:e87aa4c49e95 151 {
phungductung 0:e87aa4c49e95 152 /* Check the WWDG handle allocation */
phungductung 0:e87aa4c49e95 153 if(hwwdg == NULL)
phungductung 0:e87aa4c49e95 154 {
phungductung 0:e87aa4c49e95 155 return HAL_ERROR;
phungductung 0:e87aa4c49e95 156 }
phungductung 0:e87aa4c49e95 157
phungductung 0:e87aa4c49e95 158 /* Check the parameters */
phungductung 0:e87aa4c49e95 159 assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance));
phungductung 0:e87aa4c49e95 160 assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler));
phungductung 0:e87aa4c49e95 161 assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window));
phungductung 0:e87aa4c49e95 162 assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter));
phungductung 0:e87aa4c49e95 163
phungductung 0:e87aa4c49e95 164 if(hwwdg->State == HAL_WWDG_STATE_RESET)
phungductung 0:e87aa4c49e95 165 {
phungductung 0:e87aa4c49e95 166 /* Allocate lock resource and initialize it */
phungductung 0:e87aa4c49e95 167 hwwdg->Lock = HAL_UNLOCKED;
phungductung 0:e87aa4c49e95 168 /* Init the low level hardware */
phungductung 0:e87aa4c49e95 169 HAL_WWDG_MspInit(hwwdg);
phungductung 0:e87aa4c49e95 170 }
phungductung 0:e87aa4c49e95 171
phungductung 0:e87aa4c49e95 172 /* Change WWDG peripheral state */
phungductung 0:e87aa4c49e95 173 hwwdg->State = HAL_WWDG_STATE_BUSY;
phungductung 0:e87aa4c49e95 174
phungductung 0:e87aa4c49e95 175 /* Set WWDG Prescaler and Window */
phungductung 0:e87aa4c49e95 176 MODIFY_REG(hwwdg->Instance->CFR, (WWDG_CFR_WDGTB | WWDG_CFR_W), (hwwdg->Init.Prescaler | hwwdg->Init.Window));
phungductung 0:e87aa4c49e95 177 /* Set WWDG Counter */
phungductung 0:e87aa4c49e95 178 MODIFY_REG(hwwdg->Instance->CR, WWDG_CR_T, hwwdg->Init.Counter);
phungductung 0:e87aa4c49e95 179
phungductung 0:e87aa4c49e95 180 /* Change WWDG peripheral state */
phungductung 0:e87aa4c49e95 181 hwwdg->State = HAL_WWDG_STATE_READY;
phungductung 0:e87aa4c49e95 182
phungductung 0:e87aa4c49e95 183 /* Return function status */
phungductung 0:e87aa4c49e95 184 return HAL_OK;
phungductung 0:e87aa4c49e95 185 }
phungductung 0:e87aa4c49e95 186
phungductung 0:e87aa4c49e95 187 /**
phungductung 0:e87aa4c49e95 188 * @brief DeInitializes the WWDG peripheral.
phungductung 0:e87aa4c49e95 189 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
phungductung 0:e87aa4c49e95 190 * the configuration information for the specified WWDG module.
phungductung 0:e87aa4c49e95 191 * @retval HAL status
phungductung 0:e87aa4c49e95 192 */
phungductung 0:e87aa4c49e95 193 HAL_StatusTypeDef HAL_WWDG_DeInit(WWDG_HandleTypeDef *hwwdg)
phungductung 0:e87aa4c49e95 194 {
phungductung 0:e87aa4c49e95 195 /* Check the WWDG handle allocation */
phungductung 0:e87aa4c49e95 196 if(hwwdg == NULL)
phungductung 0:e87aa4c49e95 197 {
phungductung 0:e87aa4c49e95 198 return HAL_ERROR;
phungductung 0:e87aa4c49e95 199 }
phungductung 0:e87aa4c49e95 200
phungductung 0:e87aa4c49e95 201 /* Check the parameters */
phungductung 0:e87aa4c49e95 202 assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance));
phungductung 0:e87aa4c49e95 203
phungductung 0:e87aa4c49e95 204 /* Change WWDG peripheral state */
phungductung 0:e87aa4c49e95 205 hwwdg->State = HAL_WWDG_STATE_BUSY;
phungductung 0:e87aa4c49e95 206
phungductung 0:e87aa4c49e95 207 /* DeInit the low level hardware */
phungductung 0:e87aa4c49e95 208 HAL_WWDG_MspDeInit(hwwdg);
phungductung 0:e87aa4c49e95 209
phungductung 0:e87aa4c49e95 210 /* Reset WWDG Control register */
phungductung 0:e87aa4c49e95 211 hwwdg->Instance->CR = (uint32_t)0x0000007F;
phungductung 0:e87aa4c49e95 212
phungductung 0:e87aa4c49e95 213 /* Reset WWDG Configuration register */
phungductung 0:e87aa4c49e95 214 hwwdg->Instance->CFR = (uint32_t)0x0000007F;
phungductung 0:e87aa4c49e95 215
phungductung 0:e87aa4c49e95 216 /* Reset WWDG Status register */
phungductung 0:e87aa4c49e95 217 hwwdg->Instance->SR = 0;
phungductung 0:e87aa4c49e95 218
phungductung 0:e87aa4c49e95 219 /* Change WWDG peripheral state */
phungductung 0:e87aa4c49e95 220 hwwdg->State = HAL_WWDG_STATE_RESET;
phungductung 0:e87aa4c49e95 221
phungductung 0:e87aa4c49e95 222 /* Release Lock */
phungductung 0:e87aa4c49e95 223 __HAL_UNLOCK(hwwdg);
phungductung 0:e87aa4c49e95 224
phungductung 0:e87aa4c49e95 225 /* Return function status */
phungductung 0:e87aa4c49e95 226 return HAL_OK;
phungductung 0:e87aa4c49e95 227 }
phungductung 0:e87aa4c49e95 228
phungductung 0:e87aa4c49e95 229 /**
phungductung 0:e87aa4c49e95 230 * @brief Initializes the WWDG MSP.
phungductung 0:e87aa4c49e95 231 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
phungductung 0:e87aa4c49e95 232 * the configuration information for the specified WWDG module.
phungductung 0:e87aa4c49e95 233 * @retval None
phungductung 0:e87aa4c49e95 234 */
phungductung 0:e87aa4c49e95 235 __weak void HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg)
phungductung 0:e87aa4c49e95 236 {
phungductung 0:e87aa4c49e95 237 /* Prevent unused argument(s) compilation warning */
phungductung 0:e87aa4c49e95 238 UNUSED(hwwdg);
phungductung 0:e87aa4c49e95 239
phungductung 0:e87aa4c49e95 240 /* NOTE: This function Should not be modified, when the callback is needed,
phungductung 0:e87aa4c49e95 241 the HAL_WWDG_MspInit could be implemented in the user file
phungductung 0:e87aa4c49e95 242 */
phungductung 0:e87aa4c49e95 243 }
phungductung 0:e87aa4c49e95 244
phungductung 0:e87aa4c49e95 245 /**
phungductung 0:e87aa4c49e95 246 * @brief DeInitializes the WWDG MSP.
phungductung 0:e87aa4c49e95 247 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
phungductung 0:e87aa4c49e95 248 * the configuration information for the specified WWDG module.
phungductung 0:e87aa4c49e95 249 * @retval None
phungductung 0:e87aa4c49e95 250 */
phungductung 0:e87aa4c49e95 251 __weak void HAL_WWDG_MspDeInit(WWDG_HandleTypeDef *hwwdg)
phungductung 0:e87aa4c49e95 252 {
phungductung 0:e87aa4c49e95 253 /* Prevent unused argument(s) compilation warning */
phungductung 0:e87aa4c49e95 254 UNUSED(hwwdg);
phungductung 0:e87aa4c49e95 255
phungductung 0:e87aa4c49e95 256 /* NOTE: This function Should not be modified, when the callback is needed,
phungductung 0:e87aa4c49e95 257 the HAL_WWDG_MspDeInit could be implemented in the user file
phungductung 0:e87aa4c49e95 258 */
phungductung 0:e87aa4c49e95 259 }
phungductung 0:e87aa4c49e95 260
phungductung 0:e87aa4c49e95 261 /**
phungductung 0:e87aa4c49e95 262 * @}
phungductung 0:e87aa4c49e95 263 */
phungductung 0:e87aa4c49e95 264
phungductung 0:e87aa4c49e95 265 /** @defgroup WWDG_Exported_Functions_Group2 IO operation functions
phungductung 0:e87aa4c49e95 266 * @brief IO operation functions
phungductung 0:e87aa4c49e95 267 *
phungductung 0:e87aa4c49e95 268 @verbatim
phungductung 0:e87aa4c49e95 269 ==============================================================================
phungductung 0:e87aa4c49e95 270 ##### IO operation functions #####
phungductung 0:e87aa4c49e95 271 ==============================================================================
phungductung 0:e87aa4c49e95 272 [..]
phungductung 0:e87aa4c49e95 273 This section provides functions allowing to:
phungductung 0:e87aa4c49e95 274 (+) Start the WWDG.
phungductung 0:e87aa4c49e95 275 (+) Refresh the WWDG.
phungductung 0:e87aa4c49e95 276 (+) Handle WWDG interrupt request.
phungductung 0:e87aa4c49e95 277
phungductung 0:e87aa4c49e95 278 @endverbatim
phungductung 0:e87aa4c49e95 279 * @{
phungductung 0:e87aa4c49e95 280 */
phungductung 0:e87aa4c49e95 281
phungductung 0:e87aa4c49e95 282 /**
phungductung 0:e87aa4c49e95 283 * @brief Starts the WWDG.
phungductung 0:e87aa4c49e95 284 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
phungductung 0:e87aa4c49e95 285 * the configuration information for the specified WWDG module.
phungductung 0:e87aa4c49e95 286 * @retval HAL status
phungductung 0:e87aa4c49e95 287 */
phungductung 0:e87aa4c49e95 288 HAL_StatusTypeDef HAL_WWDG_Start(WWDG_HandleTypeDef *hwwdg)
phungductung 0:e87aa4c49e95 289 {
phungductung 0:e87aa4c49e95 290 /* Process Locked */
phungductung 0:e87aa4c49e95 291 __HAL_LOCK(hwwdg);
phungductung 0:e87aa4c49e95 292
phungductung 0:e87aa4c49e95 293 /* Change WWDG peripheral state */
phungductung 0:e87aa4c49e95 294 hwwdg->State = HAL_WWDG_STATE_BUSY;
phungductung 0:e87aa4c49e95 295
phungductung 0:e87aa4c49e95 296 /* Enable the peripheral */
phungductung 0:e87aa4c49e95 297 __HAL_WWDG_ENABLE(hwwdg);
phungductung 0:e87aa4c49e95 298
phungductung 0:e87aa4c49e95 299 /* Change WWDG peripheral state */
phungductung 0:e87aa4c49e95 300 hwwdg->State = HAL_WWDG_STATE_READY;
phungductung 0:e87aa4c49e95 301
phungductung 0:e87aa4c49e95 302 /* Process Unlocked */
phungductung 0:e87aa4c49e95 303 __HAL_UNLOCK(hwwdg);
phungductung 0:e87aa4c49e95 304
phungductung 0:e87aa4c49e95 305 /* Return function status */
phungductung 0:e87aa4c49e95 306 return HAL_OK;
phungductung 0:e87aa4c49e95 307 }
phungductung 0:e87aa4c49e95 308
phungductung 0:e87aa4c49e95 309 /**
phungductung 0:e87aa4c49e95 310 * @brief Starts the WWDG with interrupt enabled.
phungductung 0:e87aa4c49e95 311 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
phungductung 0:e87aa4c49e95 312 * the configuration information for the specified WWDG module.
phungductung 0:e87aa4c49e95 313 * @retval HAL status
phungductung 0:e87aa4c49e95 314 */
phungductung 0:e87aa4c49e95 315 HAL_StatusTypeDef HAL_WWDG_Start_IT(WWDG_HandleTypeDef *hwwdg)
phungductung 0:e87aa4c49e95 316 {
phungductung 0:e87aa4c49e95 317 /* Process Locked */
phungductung 0:e87aa4c49e95 318 __HAL_LOCK(hwwdg);
phungductung 0:e87aa4c49e95 319
phungductung 0:e87aa4c49e95 320 /* Change WWDG peripheral state */
phungductung 0:e87aa4c49e95 321 hwwdg->State = HAL_WWDG_STATE_BUSY;
phungductung 0:e87aa4c49e95 322
phungductung 0:e87aa4c49e95 323 /* Enable the Early Wakeup Interrupt */
phungductung 0:e87aa4c49e95 324 __HAL_WWDG_ENABLE_IT(hwwdg, WWDG_IT_EWI);
phungductung 0:e87aa4c49e95 325
phungductung 0:e87aa4c49e95 326 /* Enable the peripheral */
phungductung 0:e87aa4c49e95 327 __HAL_WWDG_ENABLE(hwwdg);
phungductung 0:e87aa4c49e95 328
phungductung 0:e87aa4c49e95 329 /* Return function status */
phungductung 0:e87aa4c49e95 330 return HAL_OK;
phungductung 0:e87aa4c49e95 331 }
phungductung 0:e87aa4c49e95 332
phungductung 0:e87aa4c49e95 333 /**
phungductung 0:e87aa4c49e95 334 * @brief Refreshes the WWDG.
phungductung 0:e87aa4c49e95 335 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
phungductung 0:e87aa4c49e95 336 * the configuration information for the specified WWDG module.
phungductung 0:e87aa4c49e95 337 * @param Counter: value of counter to put in WWDG counter
phungductung 0:e87aa4c49e95 338 * @retval HAL status
phungductung 0:e87aa4c49e95 339 */
phungductung 0:e87aa4c49e95 340 HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg, uint32_t Counter)
phungductung 0:e87aa4c49e95 341 {
phungductung 0:e87aa4c49e95 342 /* Process Locked */
phungductung 0:e87aa4c49e95 343 __HAL_LOCK(hwwdg);
phungductung 0:e87aa4c49e95 344
phungductung 0:e87aa4c49e95 345 /* Change WWDG peripheral state */
phungductung 0:e87aa4c49e95 346 hwwdg->State = HAL_WWDG_STATE_BUSY;
phungductung 0:e87aa4c49e95 347
phungductung 0:e87aa4c49e95 348 /* Check the parameters */
phungductung 0:e87aa4c49e95 349 assert_param(IS_WWDG_COUNTER(Counter));
phungductung 0:e87aa4c49e95 350
phungductung 0:e87aa4c49e95 351 /* Write to WWDG CR the WWDG Counter value to refresh with */
phungductung 0:e87aa4c49e95 352 MODIFY_REG(hwwdg->Instance->CR, (uint32_t)WWDG_CR_T, Counter);
phungductung 0:e87aa4c49e95 353
phungductung 0:e87aa4c49e95 354 /* Change WWDG peripheral state */
phungductung 0:e87aa4c49e95 355 hwwdg->State = HAL_WWDG_STATE_READY;
phungductung 0:e87aa4c49e95 356
phungductung 0:e87aa4c49e95 357 /* Process Unlocked */
phungductung 0:e87aa4c49e95 358 __HAL_UNLOCK(hwwdg);
phungductung 0:e87aa4c49e95 359
phungductung 0:e87aa4c49e95 360 /* Return function status */
phungductung 0:e87aa4c49e95 361 return HAL_OK;
phungductung 0:e87aa4c49e95 362 }
phungductung 0:e87aa4c49e95 363
phungductung 0:e87aa4c49e95 364 /**
phungductung 0:e87aa4c49e95 365 * @brief Handles WWDG interrupt request.
phungductung 0:e87aa4c49e95 366 * @note The Early Wakeup Interrupt (EWI) can be used if specific safety operations
phungductung 0:e87aa4c49e95 367 * or data logging must be performed before the actual reset is generated.
phungductung 0:e87aa4c49e95 368 * The EWI interrupt is enabled using __HAL_WWDG_ENABLE_IT() macro.
phungductung 0:e87aa4c49e95 369 * When the downcounter reaches the value 0x40, and EWI interrupt is
phungductung 0:e87aa4c49e95 370 * generated and the corresponding Interrupt Service Routine (ISR) can
phungductung 0:e87aa4c49e95 371 * be used to trigger specific actions (such as communications or data
phungductung 0:e87aa4c49e95 372 * logging), before resetting the device.
phungductung 0:e87aa4c49e95 373 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
phungductung 0:e87aa4c49e95 374 * the configuration information for the specified WWDG module.
phungductung 0:e87aa4c49e95 375 * @retval None
phungductung 0:e87aa4c49e95 376 */
phungductung 0:e87aa4c49e95 377 void HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg)
phungductung 0:e87aa4c49e95 378 {
phungductung 0:e87aa4c49e95 379 /* Check if Early Wakeup Interrupt is enable */
phungductung 0:e87aa4c49e95 380 if(__HAL_WWDG_GET_IT_SOURCE(hwwdg, WWDG_IT_EWI) != RESET)
phungductung 0:e87aa4c49e95 381 {
phungductung 0:e87aa4c49e95 382 /* Check if WWDG Early Wakeup Interrupt occurred */
phungductung 0:e87aa4c49e95 383 if(__HAL_WWDG_GET_FLAG(hwwdg, WWDG_FLAG_EWIF) != RESET)
phungductung 0:e87aa4c49e95 384 {
phungductung 0:e87aa4c49e95 385 /* Early Wakeup callback */
phungductung 0:e87aa4c49e95 386 HAL_WWDG_WakeupCallback(hwwdg);
phungductung 0:e87aa4c49e95 387
phungductung 0:e87aa4c49e95 388 /* Change WWDG peripheral state */
phungductung 0:e87aa4c49e95 389 hwwdg->State = HAL_WWDG_STATE_READY;
phungductung 0:e87aa4c49e95 390
phungductung 0:e87aa4c49e95 391 /* Clear the WWDG Early Wakeup flag */
phungductung 0:e87aa4c49e95 392 __HAL_WWDG_CLEAR_FLAG(hwwdg, WWDG_FLAG_EWIF);
phungductung 0:e87aa4c49e95 393
phungductung 0:e87aa4c49e95 394 /* Process Unlocked */
phungductung 0:e87aa4c49e95 395 __HAL_UNLOCK(hwwdg);
phungductung 0:e87aa4c49e95 396 }
phungductung 0:e87aa4c49e95 397 }
phungductung 0:e87aa4c49e95 398 }
phungductung 0:e87aa4c49e95 399
phungductung 0:e87aa4c49e95 400 /**
phungductung 0:e87aa4c49e95 401 * @brief Early Wakeup WWDG callback.
phungductung 0:e87aa4c49e95 402 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
phungductung 0:e87aa4c49e95 403 * the configuration information for the specified WWDG module.
phungductung 0:e87aa4c49e95 404 * @retval None
phungductung 0:e87aa4c49e95 405 */
phungductung 0:e87aa4c49e95 406 __weak void HAL_WWDG_WakeupCallback(WWDG_HandleTypeDef* hwwdg)
phungductung 0:e87aa4c49e95 407 {
phungductung 0:e87aa4c49e95 408 /* Prevent unused argument(s) compilation warning */
phungductung 0:e87aa4c49e95 409 UNUSED(hwwdg);
phungductung 0:e87aa4c49e95 410
phungductung 0:e87aa4c49e95 411 /* NOTE: This function Should not be modified, when the callback is needed,
phungductung 0:e87aa4c49e95 412 the HAL_WWDG_WakeupCallback could be implemented in the user file
phungductung 0:e87aa4c49e95 413 */
phungductung 0:e87aa4c49e95 414 }
phungductung 0:e87aa4c49e95 415
phungductung 0:e87aa4c49e95 416 /**
phungductung 0:e87aa4c49e95 417 * @}
phungductung 0:e87aa4c49e95 418 */
phungductung 0:e87aa4c49e95 419
phungductung 0:e87aa4c49e95 420 /** @defgroup WWDG_Exported_Functions_Group3 Peripheral State functions
phungductung 0:e87aa4c49e95 421 * @brief Peripheral State functions.
phungductung 0:e87aa4c49e95 422 *
phungductung 0:e87aa4c49e95 423 @verbatim
phungductung 0:e87aa4c49e95 424 ==============================================================================
phungductung 0:e87aa4c49e95 425 ##### Peripheral State functions #####
phungductung 0:e87aa4c49e95 426 ==============================================================================
phungductung 0:e87aa4c49e95 427 [..]
phungductung 0:e87aa4c49e95 428 This subsection permits to get in run-time the status of the peripheral
phungductung 0:e87aa4c49e95 429 and the data flow.
phungductung 0:e87aa4c49e95 430
phungductung 0:e87aa4c49e95 431 @endverbatim
phungductung 0:e87aa4c49e95 432 * @{
phungductung 0:e87aa4c49e95 433 */
phungductung 0:e87aa4c49e95 434
phungductung 0:e87aa4c49e95 435 /**
phungductung 0:e87aa4c49e95 436 * @brief Returns the WWDG state.
phungductung 0:e87aa4c49e95 437 * @param hwwdg: pointer to a WWDG_HandleTypeDef structure that contains
phungductung 0:e87aa4c49e95 438 * the configuration information for the specified WWDG module.
phungductung 0:e87aa4c49e95 439 * @retval HAL state
phungductung 0:e87aa4c49e95 440 */
phungductung 0:e87aa4c49e95 441 HAL_WWDG_StateTypeDef HAL_WWDG_GetState(WWDG_HandleTypeDef *hwwdg)
phungductung 0:e87aa4c49e95 442 {
phungductung 0:e87aa4c49e95 443 return hwwdg->State;
phungductung 0:e87aa4c49e95 444 }
phungductung 0:e87aa4c49e95 445
phungductung 0:e87aa4c49e95 446 /**
phungductung 0:e87aa4c49e95 447 * @}
phungductung 0:e87aa4c49e95 448 */
phungductung 0:e87aa4c49e95 449
phungductung 0:e87aa4c49e95 450 /**
phungductung 0:e87aa4c49e95 451 * @}
phungductung 0:e87aa4c49e95 452 */
phungductung 0:e87aa4c49e95 453
phungductung 0:e87aa4c49e95 454 #endif /* HAL_WWDG_MODULE_ENABLED */
phungductung 0:e87aa4c49e95 455 /**
phungductung 0:e87aa4c49e95 456 * @}
phungductung 0:e87aa4c49e95 457 */
phungductung 0:e87aa4c49e95 458
phungductung 0:e87aa4c49e95 459 /**
phungductung 0:e87aa4c49e95 460 * @}
phungductung 0:e87aa4c49e95 461 */
phungductung 0:e87aa4c49e95 462
phungductung 0:e87aa4c49e95 463 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/