shao ziyang / mbed-dev

Dependents:   SensorTileTest

Fork of mbed-dev by mbed official

Committer:
bogdanm
Date:
Thu Oct 01 15:25:22 2015 +0300
Revision:
0:9b334a45a8ff
Child:
113:b3775bf36a83
Initial commit on mbed-dev

Replaces mbed-src (now inactive)

Who changed what in which revision?

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