1 /** 2 ****************************************************************************** 3 * @file HAL_wwdg.c 4 * @author IC Applications Department 5 * @version V0.8 6 * @date 2019_08_02 7 * @brief This file provides all the WWDG firmware functions. 8 ****************************************************************************** 9 * @copy 10 * 11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 * TIME. AS A RESULT,HOLOCENE SHALL NOT BE HELD LIABLE FOR ANY 14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 * 18 * <h2><center>© COPYRIGHT 2016 HOLOCENE</center></h2> 19 */ 20 21 /* Includes ------------------------------------------------------------------*/ 22 #include "HAL_wwdg.h" 23 #include "HAL_rcc.h" 24 25 //WWDG_BASE 未定义 26 #ifdef 0 27 28 /** @addtogroup StdPeriph_Driver 29 * @{ 30 */ 31 32 /** @defgroup WWDG 33 * @brief WWDG driver modules 34 * @{ 35 */ 36 37 /** @defgroup WWDG_Private_TypesDefinitions 38 * @{ 39 */ 40 41 /** 42 * @} 43 */ 44 45 /** @defgroup WWDG_Private_Defines 46 * @{ 47 */ 48 49 /* ----------- WWDG registers bit address in the alias region ----------- */ 50 #define WWDG_OFFSET (WWDG_BASE - PERIPH_BASE) 51 52 /* Alias word address of EWI bit */ 53 #define CFR_OFFSET (WWDG_OFFSET + 0x04) 54 #define EWI_BitNumber 0x09 55 #define CFR_EWI_BB (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4)) 56 57 /* --------------------- WWDG registers bit mask ------------------------ */ 58 59 /* CR register bit mask */ 60 #define CR_WDGA_Set ((uint32_t)0x00000080) 61 62 /* CFR register bit mask */ 63 #define CFR_WDGTB_Mask ((uint32_t)0xFFFFFE7F) 64 #define CFR_W_Mask ((uint32_t)0xFFFFFF80) 65 #define BIT_Mask ((uint8_t)0x7F) 66 67 /** 68 * @} 69 */ 70 71 /** @defgroup WWDG_Private_Macros 72 * @{ 73 */ 74 75 /** 76 * @} 77 */ 78 79 /** @defgroup WWDG_Private_Variables 80 * @{ 81 */ 82 83 /** 84 * @} 85 */ 86 87 /** @defgroup WWDG_Private_FunctionPrototypes 88 * @{ 89 */ 90 91 /** 92 * @} 93 */ 94 95 /** @defgroup WWDG_Private_Functions 96 * @{ 97 */ 98 99 /** 100 * @brief Deinitializes the WWDG peripheral registers to their default 101 * reset values. 102 * @param None 103 * @retval : None 104 */ 105 void WWDG_DeInit(void) 106 { 107 RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE); 108 RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE); 109 } 110 111 /** 112 * @brief Sets the WWDG Prescaler. 113 * @param WWDG_Prescaler: specifies the WWDG Prescaler. 114 * This parameter can be one of the following values: 115 * @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1 116 * @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2 117 * @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4 118 * @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8 119 * @retval : None 120 */ 121 void WWDG_SetPrescaler(uint32_t WWDG_Prescaler) 122 { 123 uint32_t tmpreg = 0; 124 /* Check the parameters */ 125 assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler)); 126 /* Clear WDGTB[1:0] bits */ 127 tmpreg = WWDG->CFR & CFR_WDGTB_Mask; 128 /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */ 129 tmpreg |= WWDG_Prescaler; 130 /* Store the new value */ 131 WWDG->CFR = tmpreg; 132 } 133 134 /** 135 * @brief Sets the WWDG window value. 136 * @param WindowValue: specifies the window value to be compared to 137 * the downcounter. 138 * This parameter value must be lower than 0x80. 139 * @retval : None 140 */ 141 void WWDG_SetWindowValue(uint8_t WindowValue) 142 { 143 uint32_t tmpreg = 0; 144 /* Check the parameters */ 145 assert_param(IS_WWDG_WINDOW_VALUE(WindowValue)); 146 /* Clear W[6:0] bits */ 147 tmpreg = WWDG->CFR & CFR_W_Mask; 148 /* Set W[6:0] bits according to WindowValue value */ 149 tmpreg |= WindowValue & BIT_Mask; 150 /* Store the new value */ 151 WWDG->CFR = tmpreg; 152 } 153 154 /** 155 * @brief Enables the WWDG Early Wakeup interrupt(EWI). 156 * @param None 157 * @retval : None 158 */ 159 void WWDG_EnableIT(void) 160 { 161 WWDG->CFR |= (uint32_t)0x200; 162 } 163 164 /** 165 * @brief Sets the WWDG counter value. 166 * @param Counter: specifies the watchdog counter value. 167 * This parameter must be a number between 0x40 and 0x7F. 168 * @retval : None 169 */ 170 void WWDG_SetCounter(uint8_t Counter) 171 { 172 /* Check the parameters */ 173 assert_param(IS_WWDG_COUNTER(Counter)); 174 /* Write to T[6:0] bits to configure the counter value, no need to do 175 a read-modify-write; writing a 0 to WDGA bit does nothing */ 176 WWDG->CR = Counter & BIT_Mask; 177 } 178 179 /** 180 * @brief Enables WWDG and load the counter value. 181 * @param Counter: specifies the watchdog counter value. 182 * This parameter must be a number between 0x40 and 0x7F. 183 * @retval : None 184 */ 185 void WWDG_Enable(uint8_t Counter) 186 { 187 /* Check the parameters */ 188 assert_param(IS_WWDG_COUNTER(Counter)); 189 WWDG->CR = CR_WDGA_Set | Counter; 190 } 191 192 /** 193 * @brief Checks whether the Early Wakeup interrupt flag is set or not. 194 * @param None 195 * @retval : The new state of the Early Wakeup interrupt flag (SET or RESET) 196 */ 197 FlagStatus WWDG_GetFlagStatus(void) 198 { 199 return (FlagStatus)(WWDG->SR); 200 } 201 202 /** 203 * @brief Clears Early Wakeup interrupt flag. 204 * @param None 205 * @retval : None 206 */ 207 void WWDG_ClearFlag(void) 208 { 209 WWDG->SR = (uint32_t)RESET; 210 } 211 212 /** 213 * @} 214 */ 215 216 /** 217 * @} 218 */ 219 220 /** 221 * @} 222 */ 223 #endif // 0 224 /*-------------------------(C) COPYRIGHT 2016 HOLOCENE ----------------------*/ 225