1 /**
2   ******************************************************************************
3   * @file    stm32f7xx_hal_wwdg.h
4   * @author  MCD Application Team
5   * @version V1.0.1
6   * @date    25-June-2015
7   * @brief   Header file of WWDG HAL module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2015 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 __STM32F7xx_HAL_WWDG_H
40 #define __STM32F7xx_HAL_WWDG_H
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f7xx_hal_def.h"
48 
49 /** @addtogroup STM32F7xx_HAL_Driver
50   * @{
51   */
52 
53 /** @addtogroup WWDG
54   * @{
55   */
56 
57 /* Exported types ------------------------------------------------------------*/
58 /** @defgroup WWDG_Exported_Types WWDG Exported Types
59   * @{
60   */
61 
62 /**
63   * @brief  WWDG HAL State Structure definition
64   */
65 typedef enum {
66     HAL_WWDG_STATE_RESET     = 0x00,  /*!< WWDG not yet initialized or disabled */
67     HAL_WWDG_STATE_READY     = 0x01,  /*!< WWDG initialized and ready for use   */
68     HAL_WWDG_STATE_BUSY      = 0x02,  /*!< WWDG internal process is ongoing     */
69     HAL_WWDG_STATE_TIMEOUT   = 0x03,  /*!< WWDG timeout state                   */
70     HAL_WWDG_STATE_ERROR     = 0x04   /*!< WWDG error state                     */
71 } HAL_WWDG_StateTypeDef;
72 
73 /**
74   * @brief  WWDG Init structure definition
75   */
76 typedef struct {
77     uint32_t Prescaler;  /*!< Specifies the prescaler value of the WWDG.
78                             This parameter can be a value of @ref WWDG_Prescaler */
79 
80     uint32_t Window;     /*!< Specifies the WWDG window value to be compared to the downcounter.
81                             This parameter must be a number lower than Max_Data = 0x80 */
82 
83     uint32_t Counter;    /*!< Specifies the WWDG free-running downcounter value.
84                             This parameter must be a number between Min_Data = 0x40 and Max_Data = 0x7F */
85 
86 } WWDG_InitTypeDef;
87 
88 /**
89   * @brief  WWDG handle Structure definition
90   */
91 typedef struct {
92     WWDG_TypeDef                 *Instance;  /*!< Register base address    */
93 
94     WWDG_InitTypeDef             Init;       /*!< WWDG required parameters */
95 
96     HAL_LockTypeDef              Lock;       /*!< WWDG locking object      */
97 
98     __IO HAL_WWDG_StateTypeDef   State;      /*!< WWDG communication state */
99 
100 } WWDG_HandleTypeDef;
101 /**
102   * @}
103   */
104 
105 /* Exported constants --------------------------------------------------------*/
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                 ((uint32_t)0x00000000)  /*!< WWDG counter clock = (PCLK1/4096)/1 */
131 #define WWDG_PRESCALER_2                  WWDG_CFR_WDGTB0  /*!< WWDG counter clock = (PCLK1/4096)/2 */
132 #define WWDG_PRESCALER_4                  WWDG_CFR_WDGTB1  /*!< WWDG counter clock = (PCLK1/4096)/4 */
133 #define WWDG_PRESCALER_8                  WWDG_CFR_WDGTB  /*!< WWDG counter clock = (PCLK1/4096)/8 */
134 /**
135   * @}
136   */
137 
138 /**
139   * @}
140   */
141 
142 /* Exported macro ------------------------------------------------------------*/
143 /** @defgroup WWDG_Exported_Macros WWDG Exported Macros
144   * @{
145   */
146 
147 /** @brief Reset WWDG handle state
148   * @param  __HANDLE__: WWDG handle
149   * @retval None
150   */
151 #define __HAL_WWDG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_WWDG_STATE_RESET)
152 
153 /**
154   * @brief  Enables the WWDG peripheral.
155   * @param  __HANDLE__: WWDG handle
156   * @retval None
157   */
158 #define __HAL_WWDG_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR, WWDG_CR_WDGA)
159 
160 /**
161   * @brief  Disables the WWDG peripheral.
162   * @param  __HANDLE__: WWDG handle
163   * @note   WARNING: This is a dummy macro for HAL code alignment.
164   *         Once enable, WWDG Peripheral cannot be disabled except by a system reset.
165   * @retval None
166   */
167 #define __HAL_WWDG_DISABLE(__HANDLE__)                      /* dummy  macro */
168 
169 /**
170   * @brief  Gets the selected WWDG's it status.
171   * @param  __HANDLE__: WWDG handle
172   * @param  __INTERRUPT__: specifies the it to check.
173   *        This parameter can be one of the following values:
174   *            @arg WWDG_FLAG_EWIF: Early wakeup interrupt IT
175   * @retval The new state of WWDG_FLAG (SET or RESET).
176   */
177 #define __HAL_WWDG_GET_IT(__HANDLE__, __INTERRUPT__)       __HAL_WWDG_GET_FLAG((__HANDLE__),(__INTERRUPT__))
178 
179 /** @brief  Clear the WWDG's interrupt pending bits
180   *         bits to clear the selected interrupt pending bits.
181   * @param  __HANDLE__: WWDG handle
182   * @param  __INTERRUPT__: specifies the interrupt pending bit to clear.
183   *         This parameter can be one of the following values:
184   *            @arg WWDG_FLAG_EWIF: Early wakeup interrupt flag
185   */
186 #define __HAL_WWDG_CLEAR_IT(__HANDLE__, __INTERRUPT__)     __HAL_WWDG_CLEAR_FLAG((__HANDLE__), (__INTERRUPT__))
187 
188 /**
189   * @brief  Enables the WWDG early wakeup interrupt.
190   * @param  __HANDLE__: WWDG handle
191   * @param  __INTERRUPT__: specifies the interrupt to enable.
192   *         This parameter can be one of the following values:
193   *            @arg WWDG_IT_EWI: Early wakeup interrupt
194   * @note   Once enabled this interrupt cannot be disabled except by a system reset.
195   * @retval None
196   */
197 #define __HAL_WWDG_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CFR, (__INTERRUPT__))
198 
199 /**
200   * @brief  Disables the WWDG early wakeup interrupt.
201   * @param  __HANDLE__: WWDG handle
202   * @param  __INTERRUPT__: specifies the interrupt to disable.
203   *         This parameter can be one of the following values:
204   *            @arg WWDG_IT_EWI: Early wakeup interrupt
205   * @note   WARNING: This is a dummy macro for HAL code alignment.
206   *         Once enabled this interrupt cannot be disabled except by a system reset.
207   * @retval None
208   */
209 #define __HAL_WWDG_DISABLE_IT(__HANDLE__, __INTERRUPT__)                   /* dummy  macro */
210 
211 /**
212   * @brief  Gets the selected WWDG's flag status.
213   * @param  __HANDLE__: WWDG handle
214   * @param  __FLAG__: specifies the flag to check.
215   *         This parameter can be one of the following values:
216   *            @arg WWDG_FLAG_EWIF: Early wakeup interrupt flag
217   * @retval The new state of WWDG_FLAG (SET or RESET).
218   */
219 #define __HAL_WWDG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
220 
221 /**
222   * @brief  Clears the WWDG's pending flags.
223   * @param  __HANDLE__: WWDG handle
224   * @param  __FLAG__: specifies the flag to clear.
225   *         This parameter can be one of the following values:
226   *            @arg WWDG_FLAG_EWIF: Early wakeup interrupt flag
227   * @retval None
228   */
229 #define __HAL_WWDG_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = ~(__FLAG__))
230 
231 /** @brief  Checks if the specified WWDG interrupt source is enabled or disabled.
232   * @param  __HANDLE__: WWDG Handle.
233   * @param  __INTERRUPT__: specifies the WWDG interrupt source to check.
234   *          This parameter can be one of the following values:
235   *            @arg WWDG_IT_EWI: Early Wakeup Interrupt
236   * @retval state of __INTERRUPT__ (TRUE or FALSE).
237   */
238 #define __HAL_WWDG_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CFR & (__INTERRUPT__)) == (__INTERRUPT__))
239 
240 /**
241   * @}
242   */
243 
244 /* Exported functions --------------------------------------------------------*/
245 /** @addtogroup WWDG_Exported_Functions
246   * @{
247   */
248 
249 /** @addtogroup WWDG_Exported_Functions_Group1
250   * @{
251   */
252 /* Initialization/de-initialization functions  **********************************/
253 HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg);
254 HAL_StatusTypeDef HAL_WWDG_DeInit(WWDG_HandleTypeDef *hwwdg);
255 void HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg);
256 void HAL_WWDG_MspDeInit(WWDG_HandleTypeDef *hwwdg);
257 void HAL_WWDG_WakeupCallback(WWDG_HandleTypeDef* hwwdg);
258 /**
259   * @}
260   */
261 
262 /** @addtogroup WWDG_Exported_Functions_Group2
263   * @{
264   */
265 /* I/O operation functions ******************************************************/
266 HAL_StatusTypeDef HAL_WWDG_Start(WWDG_HandleTypeDef *hwwdg);
267 HAL_StatusTypeDef HAL_WWDG_Start_IT(WWDG_HandleTypeDef *hwwdg);
268 HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg, uint32_t Counter);
269 void HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg);
270 /**
271   * @}
272   */
273 
274 /** @addtogroup WWDG_Exported_Functions_Group3
275   * @{
276   */
277 /* Peripheral State functions  **************************************************/
278 HAL_WWDG_StateTypeDef HAL_WWDG_GetState(WWDG_HandleTypeDef *hwwdg);
279 /**
280   * @}
281   */
282 
283 /**
284   * @}
285   */
286 
287 /* Private types -------------------------------------------------------------*/
288 /* Private variables ---------------------------------------------------------*/
289 /* Private constants ---------------------------------------------------------*/
290 /** @defgroup WWDG_Private_Constants WWDG Private Constants
291   * @{
292   */
293 
294 /**
295   * @}
296   */
297 
298 /* Private macros ------------------------------------------------------------*/
299 /** @defgroup WWDG_Private_Macros WWDG Private Macros
300   * @{
301   */
302 #define IS_WWDG_PRESCALER(__PRESCALER__) (((__PRESCALER__) == WWDG_PRESCALER_1) || \
303                                           ((__PRESCALER__) == WWDG_PRESCALER_2) || \
304                                           ((__PRESCALER__) == WWDG_PRESCALER_4) || \
305                                           ((__PRESCALER__) == WWDG_PRESCALER_8))
306 #define IS_WWDG_WINDOW(__WINDOW__) ((__WINDOW__) <= 0x7F)
307 #define IS_WWDG_COUNTER(__COUNTER__) (((__COUNTER__) >= 0x40) && ((__COUNTER__) <= 0x7F))
308 /**
309   * @}
310   */
311 
312 /* Private functions ---------------------------------------------------------*/
313 /** @defgroup WWDG_Private_Functions WWDG Private Functions
314   * @{
315   */
316 
317 /**
318   * @}
319   */
320 
321 /**
322   * @}
323   */
324 
325 /**
326   * @}
327   */
328 #ifdef __cplusplus
329 }
330 #endif
331 
332 #endif /* __STM32F7xx_HAL_WWDG_H */
333 
334 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
335