1 /* hal_wwdg.h */
2 
3 #ifndef __HAL_WWDG_H__
4 #define __HAL_WWDG_H__
5 
6 /*!
7  * @addtogroup WWDG
8  * @{
9  */
10 
11 #include "hal_common.h"
12 
13 /*!
14  * @brief WWDG driver version number.
15  */
16 #define WWDG_DRIVER_VERSION 0u /*!< WWDG_0. */
17 
18 /*!
19  * @brief The lower limit value of WWDG counter.
20  */
21 #define WWDG_LOWER_LIMIT 0x40u /*!< If WWDG counter Below this value, WWDG will generate a reset request. */
22 
23 /*!
24  * @addtogroup WWDG_INT
25  * @brief WWDG_STATUS mask codes
26  * @{
27  */
28 #define WWDG_INT_ALMOST_TIMEOUT WWDG_CFGR_EWI_MASK /*!< WWDG interrupt: Almost timeout. */
29 /*!
30  * @}
31  */
32 
33 /*!
34  * @addtogroup WWDG_STATUS
35  * @brief WWDG_STATUS mask codes
36  * @{
37  */
38 #define WWDG_STATUS_ALMOST_TIMEOUT WWDG_SR_EWIF_MASK /*!< WWDG status: Almost timeout. */
39 /*!
40  * @}
41  */
42 
43 /*!
44  * @brief WWDG prescaler type.
45  *
46  * Select the prescaler of WWDG counter clock.
47  */
48 typedef enum
49 {
50     WWDG_Prescaler_1 = 0u, /*!< WWDG Prescaler 1. */
51     WWDG_Prescaler_2 = 1u, /*!< WWDG Prescaler 2. */
52     WWDG_Prescaler_4 = 2u, /*!< WWDG Prescaler 4. */
53     WWDG_Prescaler_8 = 3u, /*!< WWDG Prescaler 8. */
54 } WWDG_Prescaler_Type;
55 
56 /*!
57  * @brief This type of structure instance is used to keep the settings when calling the @ref WWDG_Init() to initialize the USB module.
58  */
59 typedef struct
60 {
61     WWDG_Prescaler_Type Prescaler;  /*!< Specify the WWDG counter prescaler. */
62     uint32_t            UpperLimit; /*!< Specify the upperLimit, WWDG will generate a reset request if reload WWDG counter before the counter value greater than UpperLimit. */
63 } WWDG_Init_Type;
64 
65 /*!
66  * @brief Initialize the WWDG module.
67  *
68  * @param WWDGx WWDG instance.
69  * @param init Pointer to the initialization structure. See to @ref WWDG_Init_Type.
70  * @return None.
71  */
72 void WWDG_Init(WWDG_Type * WWDGx, WWDG_Init_Type * init);
73 
74 /*!
75  * @brief Start counting.
76  *
77  * If the counter is started, it cannot be stoped unless reset MCU.
78  *
79  * @param WWDGx WWDG instance.
80  * @return None.
81  */
82 void WWDG_Start(WWDG_Type * WWDGx);
83 
84 /*!
85  * @brief Reolad WWDG counter (Feed dog).
86  *
87  * Reload WWDG counter to ensure that the counter value greater than WWDG_LOWER_LIMIT_VALUE and prevent generate a reset request.
88  *
89  * @param WWDGx WWDG instance.
90  * @param value The value of reload WWDG counter, the value ranges from 0x40 to 0x7f.
91  * @return None.
92  */
93 void WWDG_Reload(WWDG_Type * WWDGx, uint32_t value);
94 
95 /*!
96  * @brief Enable interrupts of the WWDG module.
97  *
98  * @param WWDGx WWDG instance.
99  * @param interrupts Interrupt code masks. See to @ref WWDG_INT.
100  * @param enable 'true' to enable the indicated interrupts, 'false' has no effect.
101  * @return None.
102  */
103 void WWDG_EnableInterrupts(WWDG_Type * WWDGx, uint32_t interrupts, bool enable);
104 
105 /*!
106  * @brief Get the status flags of the WWDG module.
107  *
108  * @param WWDGx WWDG instance.
109  * @return status flags. See to @ref WWDG_STATUS.
110  */
111 uint32_t WWDG_GetStatus(WWDG_Type * WWDGx);
112 
113 /*!
114  * @brief Clear the status flags of the WWDG module.
115  *
116  * @param WWDGx WWDG instance.
117  * @param status status flags. See to @ref WWDG_STATUS.
118  * @return None.
119  */
120 void WWDG_ClearStatus(WWDG_Type * WWDGx, uint32_t status);
121 
122 /*!
123  *@}
124  */
125 
126 #endif /* __HAL_WWDG_H__. */
127 
128 /* EOF. */
129