1 /**
2   ******************************************************************************
3   * @file    stm32l0xx_hal_wwdg.h
4   * @author  MCD Application Team
5   * @brief   Header file of WWDG HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32L0xx_HAL_WWDG_H
21 #define STM32L0xx_HAL_WWDG_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32l0xx_hal_def.h"
29 
30 /** @addtogroup STM32L0xx_HAL_Driver
31   * @{
32   */
33 
34 /** @addtogroup WWDG
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 
40 /** @defgroup WWDG_Exported_Types WWDG Exported Types
41   * @{
42   */
43 
44 /**
45   * @brief  WWDG Init structure definition
46   */
47 typedef struct
48 {
49   uint32_t Prescaler;     /*!< Specifies the prescaler value of the WWDG.
50                                This parameter can be a value of @ref WWDG_Prescaler */
51 
52   uint32_t Window;        /*!< Specifies the WWDG window value to be compared to the downcounter.
53                                This parameter must be a number Min_Data = 0x40 and Max_Data = 0x7F */
54 
55   uint32_t Counter;       /*!< Specifies the WWDG free-running downcounter  value.
56                                This parameter must be a number between Min_Data = 0x40 and Max_Data = 0x7F */
57 
58   uint32_t EWIMode ;      /*!< Specifies if WWDG Early Wakeup Interrupt is enable or not.
59                                This parameter can be a value of @ref WWDG_EWI_Mode */
60 
61 } WWDG_InitTypeDef;
62 
63 /**
64   * @brief  WWDG handle Structure definition
65   */
66 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
67 typedef struct __WWDG_HandleTypeDef
68 #else
69 typedef struct
70 #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */
71 {
72   WWDG_TypeDef      *Instance;  /*!< Register base address */
73 
74   WWDG_InitTypeDef  Init;       /*!< WWDG required parameters */
75 
76 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
77   void (* EwiCallback)(struct __WWDG_HandleTypeDef *hwwdg);                  /*!< WWDG Early WakeUp Interrupt callback */
78 
79   void (* MspInitCallback)(struct __WWDG_HandleTypeDef *hwwdg);              /*!< WWDG Msp Init callback */
80 #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */
81 } WWDG_HandleTypeDef;
82 
83 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
84 /**
85   * @brief  HAL WWDG common Callback ID enumeration definition
86   */
87 typedef enum
88 {
89   HAL_WWDG_EWI_CB_ID          = 0x00U,    /*!< WWDG EWI callback ID */
90   HAL_WWDG_MSPINIT_CB_ID      = 0x01U,    /*!< WWDG MspInit callback ID */
91 } HAL_WWDG_CallbackIDTypeDef;
92 
93 /**
94   * @brief  HAL WWDG Callback pointer definition
95   */
96 typedef void (*pWWDG_CallbackTypeDef)(WWDG_HandleTypeDef *hppp);  /*!< pointer to a WWDG common callback functions */
97 
98 #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */
99 /**
100   * @}
101   */
102 
103 /* Exported constants --------------------------------------------------------*/
104 
105 /** @defgroup WWDG_Exported_Constants WWDG Exported Constants
106   * @{
107   */
108 
109 /** @defgroup WWDG_Interrupt_definition WWDG Interrupt definition
110   * @{
111   */
112 #define WWDG_IT_EWI                         WWDG_CFR_EWI  /*!< Early wakeup interrupt */
113 /**
114   * @}
115   */
116 
117 /** @defgroup WWDG_Flag_definition WWDG Flag definition
118   * @brief WWDG Flag definition
119   * @{
120   */
121 #define WWDG_FLAG_EWIF                      WWDG_SR_EWIF  /*!< Early wakeup interrupt flag */
122 /**
123   * @}
124   */
125 
126 /** @defgroup WWDG_Prescaler WWDG Prescaler
127   * @{
128   */
129 #define WWDG_PRESCALER_1                    0x00000000u                              /*!< WWDG counter clock = (PCLK1/4096)/1 */
130 #define WWDG_PRESCALER_2                    WWDG_CFR_WDGTB_0                         /*!< WWDG counter clock = (PCLK1/4096)/2 */
131 #define WWDG_PRESCALER_4                    WWDG_CFR_WDGTB_1                         /*!< WWDG counter clock = (PCLK1/4096)/4 */
132 #define WWDG_PRESCALER_8                    (WWDG_CFR_WDGTB_1 | WWDG_CFR_WDGTB_0)    /*!< WWDG counter clock = (PCLK1/4096)/8 */
133 /**
134   * @}
135   */
136 
137 /** @defgroup WWDG_EWI_Mode WWDG Early Wakeup Interrupt Mode
138   * @{
139   */
140 #define WWDG_EWI_DISABLE                    0x00000000u       /*!< EWI Disable */
141 #define WWDG_EWI_ENABLE                     WWDG_CFR_EWI      /*!< EWI Enable */
142 /**
143   * @}
144   */
145 
146 /**
147   * @}
148   */
149 
150 /* Private macros ------------------------------------------------------------*/
151 
152 /** @defgroup WWDG_Private_Macros WWDG Private Macros
153   * @{
154   */
155 #define IS_WWDG_PRESCALER(__PRESCALER__)    (((__PRESCALER__) == WWDG_PRESCALER_1)  || \
156                                              ((__PRESCALER__) == WWDG_PRESCALER_2)  || \
157                                              ((__PRESCALER__) == WWDG_PRESCALER_4)  || \
158                                              ((__PRESCALER__) == WWDG_PRESCALER_8))
159 
160 #define IS_WWDG_WINDOW(__WINDOW__)          (((__WINDOW__) >= WWDG_CFR_W_6) && ((__WINDOW__) <= WWDG_CFR_W))
161 
162 #define IS_WWDG_COUNTER(__COUNTER__)        (((__COUNTER__) >= WWDG_CR_T_6) && ((__COUNTER__) <= WWDG_CR_T))
163 
164 #define IS_WWDG_EWI_MODE(__MODE__)          (((__MODE__) == WWDG_EWI_ENABLE) || \
165                                              ((__MODE__) == WWDG_EWI_DISABLE))
166 /**
167   * @}
168   */
169 
170 
171 /* Exported macros ------------------------------------------------------------*/
172 
173 /** @defgroup WWDG_Exported_Macros WWDG Exported Macros
174   * @{
175   */
176 
177 /**
178   * @brief  Enable the WWDG peripheral.
179   * @param  __HANDLE__  WWDG handle
180   * @retval None
181   */
182 #define __HAL_WWDG_ENABLE(__HANDLE__)                         SET_BIT((__HANDLE__)->Instance->CR, WWDG_CR_WDGA)
183 
184 /**
185   * @brief  Enable the WWDG early wakeup interrupt.
186   * @param  __HANDLE__     WWDG handle
187   * @param  __INTERRUPT__  specifies the interrupt to enable.
188   *         This parameter can be one of the following values:
189   *            @arg WWDG_IT_EWI: Early wakeup interrupt
190   * @note   Once enabled this interrupt cannot be disabled except by a system reset.
191   * @retval None
192   */
193 #define __HAL_WWDG_ENABLE_IT(__HANDLE__, __INTERRUPT__)       SET_BIT((__HANDLE__)->Instance->CFR, (__INTERRUPT__))
194 
195 /**
196   * @brief  Check whether the selected WWDG interrupt has occurred or not.
197   * @param  __HANDLE__  WWDG handle
198   * @param  __INTERRUPT__  specifies the it to check.
199   *        This parameter can be one of the following values:
200   *            @arg WWDG_FLAG_EWIF: Early wakeup interrupt IT
201   * @retval The new state of WWDG_FLAG (SET or RESET).
202   */
203 #define __HAL_WWDG_GET_IT(__HANDLE__, __INTERRUPT__)        __HAL_WWDG_GET_FLAG((__HANDLE__),(__INTERRUPT__))
204 
205 /** @brief  Clear the WWDG interrupt pending bits.
206   *         bits to clear the selected interrupt pending bits.
207   * @param  __HANDLE__  WWDG handle
208   * @param  __INTERRUPT__  specifies the interrupt pending bit to clear.
209   *         This parameter can be one of the following values:
210   *            @arg WWDG_FLAG_EWIF: Early wakeup interrupt flag
211   */
212 #define __HAL_WWDG_CLEAR_IT(__HANDLE__, __INTERRUPT__)      __HAL_WWDG_CLEAR_FLAG((__HANDLE__), (__INTERRUPT__))
213 
214 /**
215   * @brief  Check whether the specified WWDG flag is set or not.
216   * @param  __HANDLE__  WWDG handle
217   * @param  __FLAG__  specifies the flag to check.
218   *         This parameter can be one of the following values:
219   *            @arg WWDG_FLAG_EWIF: Early wakeup interrupt flag
220   * @retval The new state of WWDG_FLAG (SET or RESET).
221   */
222 #define __HAL_WWDG_GET_FLAG(__HANDLE__, __FLAG__)           (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
223 
224 /**
225   * @brief  Clear the WWDG's pending flags.
226   * @param  __HANDLE__  WWDG handle
227   * @param  __FLAG__  specifies the flag to clear.
228   *         This parameter can be one of the following values:
229   *            @arg WWDG_FLAG_EWIF: Early wakeup interrupt flag
230   * @retval None
231   */
232 #define __HAL_WWDG_CLEAR_FLAG(__HANDLE__, __FLAG__)         ((__HANDLE__)->Instance->SR = ~(__FLAG__))
233 
234 /** @brief  Check whether the specified WWDG interrupt source is enabled or not.
235   * @param  __HANDLE__  WWDG Handle.
236   * @param  __INTERRUPT__  specifies the WWDG interrupt source to check.
237   *         This parameter can be one of the following values:
238   *            @arg WWDG_IT_EWI: Early Wakeup Interrupt
239   * @retval state of __INTERRUPT__ (TRUE or FALSE).
240   */
241 #define __HAL_WWDG_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CFR\
242                                                               & (__INTERRUPT__)) == (__INTERRUPT__))
243 
244 /**
245   * @}
246   */
247 
248 /* Exported functions --------------------------------------------------------*/
249 
250 /** @addtogroup WWDG_Exported_Functions
251   * @{
252   */
253 
254 /** @addtogroup WWDG_Exported_Functions_Group1
255   * @{
256   */
257 /* Initialization/de-initialization functions  **********************************/
258 HAL_StatusTypeDef     HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg);
259 void                  HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg);
260 /* Callbacks Register/UnRegister functions  ***********************************/
261 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
262 HAL_StatusTypeDef     HAL_WWDG_RegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID,
263                                                 pWWDG_CallbackTypeDef pCallback);
264 HAL_StatusTypeDef     HAL_WWDG_UnRegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID);
265 #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */
266 
267 /**
268   * @}
269   */
270 
271 /** @addtogroup WWDG_Exported_Functions_Group2
272   * @{
273   */
274 /* I/O operation functions ******************************************************/
275 HAL_StatusTypeDef     HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg);
276 void                  HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg);
277 void                  HAL_WWDG_EarlyWakeupCallback(WWDG_HandleTypeDef *hwwdg);
278 /**
279   * @}
280   */
281 
282 /**
283   * @}
284   */
285 
286 /**
287   * @}
288   */
289 
290 /**
291   * @}
292   */
293 
294 #ifdef __cplusplus
295 }
296 #endif
297 
298 #endif /* STM32L0xx_HAL_WWDG_H */
299