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