1 ////////////////////////////////////////////////////////////////////////////////
2 /// @file     hal_wwdg.c
3 /// @author   AE TEAM
4 /// @brief    THIS FILE PROVIDES ALL THE WWDG FIRMWARE FUNCTIONS.
5 ////////////////////////////////////////////////////////////////////////////////
6 /// @attention
7 ///
8 /// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
9 /// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
10 /// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
11 /// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
12 /// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
13 /// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
14 ///
15 /// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
16 ////////////////////////////////////////////////////////////////////////////////
17 
18 // Define to prevent recursive inclusion
19 #define _HAL_WWDG_C_
20 
21 // Files includes
22 #include "hal_wwdg.h"
23 #include "hal_rcc.h"
24 
25 ////////////////////////////////////////////////////////////////////////////////
26 /// @addtogroup MM32_Hardware_Abstract_Layer
27 /// @{
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// @addtogroup WWDG_HAL
31 /// @{
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// @addtogroup WWDG_Exported_Functions
35 /// @{
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// @brief  Deinitializes the WWDG peripheral registers to their default reset
39 /// values.
40 /// @param  None.
41 /// @retval None.
42 ////////////////////////////////////////////////////////////////////////////////
WWDG_DeInit()43 void WWDG_DeInit()
44 {
45     exRCC_APB1PeriphReset(RCC_APB1RSTR_WWDG);
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// @brief  Sets the WWDG Prescaler.
50 /// @param  WWDG_Prescaler: specifies the WWDG Prescaler.
51 ///         This parameter can be one of the following values:
52 ///             @arg WWDG_Prescaler_1: WWDG counter clock = APB1CLK / 4096 / 1
53 ///             @arg WWDG_Prescaler_2: WWDG counter clock = APB1CLK / 4096 / 2
54 ///             @arg WWDG_Prescaler_4: WWDG counter clock = APB1CLK / 4096 / 4
55 ///             @arg WWDG_Prescaler_8: WWDG counter clock = APB1CLK / 4096 / 8
56 /// @retval None.
57 ////////////////////////////////////////////////////////////////////////////////
WWDG_SetPrescaler(u32 prescaler)58 void WWDG_SetPrescaler(u32 prescaler)
59 {
60     WWDG->CFGR = (WWDG->CFGR & ~WWDG_CFGR_WDGTB) | prescaler;
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// @brief  Sets the WWDG window value.
65 /// @param  WindowValue: specifies the window value to be compared to the
66 /// downcounter.
67 ///          This parameter value must be lower than 0x80.
68 /// @retval None.
69 ////////////////////////////////////////////////////////////////////////////////
WWDG_SetWindowValue(u8 window_value)70 void WWDG_SetWindowValue(u8 window_value)
71 {
72     WWDG->CFGR = (WWDG->CFGR & ~WWDG_CFGR_WINDOW) | (window_value & WWDG_CFGR_WINDOW);
73 }
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 /// @brief  Enables the WWDG Early Wakeup interrupt(EWI).
77 /// @note   Once enabled this interrupt cannot be disabled except by a system
78 /// reset.
79 /// @param  None.
80 /// @retval None.
81 ////////////////////////////////////////////////////////////////////////////////
WWDG_EnableIT()82 void WWDG_EnableIT()
83 {
84     WWDG->CFGR |= WWDG_CFGR_EWI;
85 }
86 
87 ////////////////////////////////////////////////////////////////////////////////
88 /// @brief  Sets the WWDG counter value.
89 /// @param  Counter: specifies the watchdog counter value.
90 ///         This parameter must be a number between 0x40 and 0x7F (to prevent
91 ///         generating an immediate reset).
92 /// @retval None.
93 ////////////////////////////////////////////////////////////////////////////////
WWDG_SetCounter(u8 count)94 void WWDG_SetCounter(u8 count)
95 {
96     WWDG->CR = count & WWDG_CFGR_WINDOW;
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// @brief  Enables WWDG and load the counter value.
101 /// @param  Counter: specifies the watchdog counter value.
102 ///         This parameter must be a number between 0x40 and 0x7F (to prevent
103 ///         generating an immediate reset).
104 /// @retval None.
105 ////////////////////////////////////////////////////////////////////////////////
WWDG_GetCounter()106 u32 WWDG_GetCounter()
107 {
108     return WWDG->CR & WWDG_CR_CNT;
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// @brief  Enables WWDG and load the counter value.
113 /// @param  Counter: specifies the watchdog counter value.
114 ///         This parameter must be a number between 0x40 and 0x7F (to prevent
115 ///         generating an immediate reset).
116 /// @retval None.
117 ////////////////////////////////////////////////////////////////////////////////
WWDG_Enable(u8 count)118 void WWDG_Enable(u8 count)
119 {
120     WWDG->CR = WWDG_CR_WDGA | count;
121 }
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// @brief  Checks whether the Early Wakeup interrupt flag is set or not.
125 /// @param  None.
126 /// @retval The new state of the Early Wakeup interrupt flag (SET or RESET).
127 ////////////////////////////////////////////////////////////////////////////////
WWDG_GetFlagStatus()128 FlagStatus WWDG_GetFlagStatus()
129 {
130     return WWDG->SR ? SET : RESET;
131 }
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// @brief  Clears Early Wakeup interrupt flag.
135 /// @param  None.
136 /// @retval None.
137 ////////////////////////////////////////////////////////////////////////////////
WWDG_ClearFlag()138 void WWDG_ClearFlag()
139 {
140     WWDG->SR &= ~WWDG_SR_EWIF;
141 }
142 
143 /// @}
144 
145 /// @}
146 
147 /// @}
148