1 /**
2   ******************************************************************************
3   * @file    stm32l1xx_hal_wwdg.h
4   * @author  MCD Application Team
5   * @version V1.2.0
6   * @date    01-July-2016
7   * @brief   Header file of WWDG HAL module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
12   *
13   * Redistribution and use in source and binary forms, with or without modification,
14   * are permitted provided that the following conditions are met:
15   *   1. Redistributions of source code must retain the above copyright notice,
16   *      this list of conditions and the following disclaimer.
17   *   2. Redistributions in binary form must reproduce the above copyright notice,
18   *      this list of conditions and the following disclaimer in the documentation
19   *      and/or other materials provided with the distribution.
20   *   3. Neither the name of STMicroelectronics nor the names of its contributors
21   *      may be used to endorse or promote products derived from this software
22   *      without specific prior written permission.
23   *
24   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34   *
35   ******************************************************************************
36   */
37 
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32L1xx_HAL_WWDG_H
40 #define __STM32L1xx_HAL_WWDG_H
41 
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45 
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32l1xx_hal_def.h"
48 
49 /** @addtogroup STM32L1xx_HAL_Driver
50   * @{
51   */
52 
53 /** @addtogroup WWDG
54   * @{
55   */
56 
57 /* Exported types ------------------------------------------------------------*/
58 
59 /** @defgroup WWDG_Exported_Types WWDG Exported Types
60   * @{
61   */
62 
63 /**
64   * @brief  WWDG Init structure definition
65   */
66 typedef struct
67 {
68   uint32_t Prescaler;     /*!< Specifies the prescaler value of the WWDG.
69                                This parameter can be a value of @ref WWDG_Prescaler */
70 
71   uint32_t Window;        /*!< Specifies the WWDG window value to be compared to the downcounter.
72                                This parameter must be a number Min_Data = 0x40 and Max_Data = 0x7F */
73 
74   uint32_t Counter;       /*!< Specifies the WWDG free-running downcounter  value.
75                                This parameter must be a number between Min_Data = 0x40 and Max_Data = 0x7F */
76 
77   uint32_t EWIMode ;      /*!< Specifies if WWDG Early Wakeup Interupt is enable or not.
78                                This parameter can be a value of @ref WWDG_EWI_Mode */
79 
80 }WWDG_InitTypeDef;
81 
82 /**
83   * @brief  WWDG handle Structure definition
84   */
85 typedef struct
86 {
87   WWDG_TypeDef                 *Instance;  /*!< Register base address    */
88 
89   WWDG_InitTypeDef             Init;       /*!< WWDG required parameters */
90 
91 }WWDG_HandleTypeDef;
92 /**
93   * @}
94   */
95 
96 /* Exported constants --------------------------------------------------------*/
97 
98 /** @defgroup WWDG_Exported_Constants WWDG Exported Constants
99   * @{
100   */
101 
102 /** @defgroup WWDG_Interrupt_definition WWDG Interrupt definition
103   * @{
104   */
105 #define WWDG_IT_EWI                         WWDG_CFR_EWI  /*!< Early wakeup interrupt */
106 
107 /**
108   * @}
109   */
110 
111 /** @defgroup WWDG_Flag_definition WWDG Flag definition
112   * @brief WWDG Flag definition
113   * @{
114   */
115 #define WWDG_FLAG_EWIF                      WWDG_SR_EWIF  /*!< Early wakeup interrupt flag */
116 
117 /**
118   * @}
119   */
120 
121 /** @defgroup WWDG_Prescaler WWDG Prescaler
122   * @{
123   */
124 #define WWDG_PRESCALER_1                    0x00000000u       /*!< WWDG counter clock = (PCLK1/4096)/1 */
125 #define WWDG_PRESCALER_2                    WWDG_CFR_WDGTB_0  /*!< WWDG counter clock = (PCLK1/4096)/2 */
126 #define WWDG_PRESCALER_4                    WWDG_CFR_WDGTB_1  /*!< WWDG counter clock = (PCLK1/4096)/4 */
127 #define WWDG_PRESCALER_8                    WWDG_CFR_WDGTB    /*!< WWDG counter clock = (PCLK1/4096)/8 */
128 /**
129   * @}
130   */
131 
132 /** @defgroup WWDG_EWI_Mode WWDG Early Wakeup Interrupt Mode
133   * @{
134   */
135 #define WWDG_EWI_DISABLE                    0x00000000u       /*!< EWI Disable */
136 #define WWDG_EWI_ENABLE                     WWDG_CFR_EWI      /*!< EWI Enable */
137 /**
138   * @}
139   */
140 
141 /**
142   * @}
143   */
144 
145 /* Private macros ------------------------------------------------------------*/
146 
147 /** @defgroup WWDG_Private_Macros WWDG Private Macros
148   * @{
149   */
150 #define IS_WWDG_PRESCALER(__PRESCALER__)    (((__PRESCALER__) == WWDG_PRESCALER_1) || \
151                                              ((__PRESCALER__) == WWDG_PRESCALER_2) || \
152                                              ((__PRESCALER__) == WWDG_PRESCALER_4) || \
153                                              ((__PRESCALER__) == WWDG_PRESCALER_8))
154 
155 #define IS_WWDG_WINDOW(__WINDOW__)          (((__WINDOW__) >= WWDG_CFR_W_6) && ((__WINDOW__) <= WWDG_CFR_W))
156 
157 #define IS_WWDG_COUNTER(__COUNTER__)        (((__COUNTER__) >= WWDG_CR_T_6) && ((__COUNTER__) <= WWDG_CR_T))
158 
159 #define IS_WWDG_EWI_MODE(__MODE__)          (((__MODE__) == WWDG_EWI_ENABLE) || \
160                                              ((__MODE__) == WWDG_EWI_DISABLE))
161 /**
162   * @}
163   */
164 
165 
166 /* Exported macros ------------------------------------------------------------*/
167 
168 /** @defgroup WWDG_Exported_Macros WWDG Exported Macros
169   * @{
170   */
171 
172 /**
173   * @brief  Enable the WWDG peripheral.
174   * @param  __HANDLE__  WWDG handle
175   * @retval None
176   */
177 #define __HAL_WWDG_ENABLE(__HANDLE__)                         SET_BIT((__HANDLE__)->Instance->CR, WWDG_CR_WDGA)
178 
179 /**
180   * @brief  Enable the WWDG early wakeup interrupt.
181   * @param  __HANDLE__: WWDG handle
182   * @param  __INTERRUPT__  specifies the interrupt to enable.
183   *         This parameter can be one of the following values:
184   *            @arg WWDG_IT_EWI: Early wakeup interrupt
185   * @note   Once enabled this interrupt cannot be disabled except by a system reset.
186   * @retval None
187   */
188 #define __HAL_WWDG_ENABLE_IT(__HANDLE__, __INTERRUPT__)       SET_BIT((__HANDLE__)->Instance->CFR, (__INTERRUPT__))
189 
190 /**
191   * @brief  Check whether the selected WWDG interrupt has occurred or not.
192   * @param  __HANDLE__  WWDG handle
193   * @param  __INTERRUPT__  specifies the it to check.
194   *        This parameter can be one of the following values:
195   *            @arg WWDG_FLAG_EWIF: Early wakeup interrupt IT
196   * @retval The new state of WWDG_FLAG (SET or RESET).
197   */
198 #define __HAL_WWDG_GET_IT(__HANDLE__, __INTERRUPT__)        __HAL_WWDG_GET_FLAG((__HANDLE__),(__INTERRUPT__))
199 
200 /** @brief  Clear the WWDG interrupt pending bits.
201   *         bits to clear the selected interrupt pending bits.
202   * @param  __HANDLE__  WWDG handle
203   * @param  __INTERRUPT__  specifies the interrupt pending bit to clear.
204   *         This parameter can be one of the following values:
205   *            @arg WWDG_FLAG_EWIF: Early wakeup interrupt flag
206   */
207 #define __HAL_WWDG_CLEAR_IT(__HANDLE__, __INTERRUPT__)      __HAL_WWDG_CLEAR_FLAG((__HANDLE__), (__INTERRUPT__))
208 
209 /**
210   * @brief  Check whether the specified WWDG flag is set or not.
211   * @param  __HANDLE__  WWDG handle
212   * @param  __FLAG__  specifies the flag to check.
213   *         This parameter can be one of the following values:
214   *            @arg WWDG_FLAG_EWIF: Early wakeup interrupt flag
215   * @retval The new state of WWDG_FLAG (SET or RESET).
216   */
217 #define __HAL_WWDG_GET_FLAG(__HANDLE__, __FLAG__)           (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
218 
219 /**
220   * @brief  Clear the WWDG's pending flags.
221   * @param  __HANDLE__  WWDG handle
222   * @param  __FLAG__  specifies the flag to clear.
223   *         This parameter can be one of the following values:
224   *            @arg WWDG_FLAG_EWIF: Early wakeup interrupt flag
225   * @retval None
226   */
227 #define __HAL_WWDG_CLEAR_FLAG(__HANDLE__, __FLAG__)         ((__HANDLE__)->Instance->SR = ~(__FLAG__))
228 
229 /** @brief  Check whether the specified WWDG interrupt source is enabled or not.
230   * @param  __HANDLE__  WWDG Handle.
231   * @param  __INTERRUPT__  specifies the WWDG interrupt source to check.
232   *         This parameter can be one of the following values:
233   *            @arg WWDG_IT_EWI: Early Wakeup Interrupt
234   * @retval state of __INTERRUPT__ (TRUE or FALSE).
235   */
236 #define __HAL_WWDG_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CFR & (__INTERRUPT__)) == (__INTERRUPT__))
237 
238 /**
239   * @}
240   */
241 
242 /* Exported functions --------------------------------------------------------*/
243 
244 /** @addtogroup WWDG_Exported_Functions
245   * @{
246   */
247 
248 /** @addtogroup WWDG_Exported_Functions_Group1
249   * @{
250   */
251 /* Initialization/de-initialization functions  **********************************/
252 HAL_StatusTypeDef     HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg);
253 void                  HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg);
254 /**
255   * @}
256   */
257 
258 /** @addtogroup WWDG_Exported_Functions_Group2
259   * @{
260   */
261 /* I/O operation functions ******************************************************/
262 HAL_StatusTypeDef     HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg);
263 void                  HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg);
264 void                  HAL_WWDG_EarlyWakeupCallback(WWDG_HandleTypeDef* hwwdg);
265 /**
266   * @}
267   */
268 
269 /**
270   * @}
271   */
272 
273 /**
274   * @}
275   */
276 
277 /**
278   * @}
279   */
280 
281 #ifdef __cplusplus
282 }
283 #endif
284 
285 #endif /* __STM32L1xx_HAL_WWDG_H */
286 
287 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
288