1 /** 2 ****************************************************************************** 3 * @file HAL_iwdg.c 4 * @author IC Applications Department 5 * @version V0.8 6 * @date 2019_08_02 7 * @brief This file provides all the IWDG 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_iwdg.h" 23 24 //IWDG_BASE 未定义 25 #ifdef 0 26 27 28 /** @addtogroup StdPeriph_Driver 29 * @{ 30 */ 31 32 /** @defgroup IWDG 33 * @brief IWDG driver modules 34 * @{ 35 */ 36 37 /** @defgroup IWDG_Private_TypesDefinitions 38 * @{ 39 */ 40 41 /** 42 * @} 43 */ 44 45 /** @defgroup IWDG_Private_Defines 46 * @{ 47 */ 48 49 /* ---------------------- IWDG registers bit mask ----------------------------*/ 50 51 /* KR register bit mask */ 52 #define KR_KEY_Reload ((uint16_t)0xAAAA) 53 #define KR_KEY_Enable ((uint16_t)0xCCCC) 54 55 /** 56 * @} 57 */ 58 59 /** @defgroup IWDG_Private_Macros 60 * @{ 61 */ 62 63 /** 64 * @} 65 */ 66 67 /** @defgroup IWDG_Private_Variables 68 * @{ 69 */ 70 71 /** 72 * @} 73 */ 74 75 /** @defgroup IWDG_Private_FunctionPrototypes 76 * @{ 77 */ 78 79 /** 80 * @} 81 */ 82 83 /** @defgroup IWDG_Private_Functions 84 * @{ 85 */ 86 87 /** 88 * @brief Enables or disables write access to IWDG_PR and IWDG_RLR 89 * registers. 90 * @param IWDG_WriteAccess: new state of write access to IWDG_PR and 91 * IWDG_RLR registers. 92 * This parameter can be one of the following values: 93 * @arg IWDG_WriteAccess_Enable: Enable write access to 94 * IWDG_PR and IWDG_RLR registers 95 * @arg IWDG_WriteAccess_Disable: Disable write access to 96 * IWDG_PR and IWDG_RLR registers 97 * @retval : None 98 */ 99 void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess) 100 { 101 /* Check the parameters */ 102 assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess)); 103 IWDG->KR = IWDG_WriteAccess; 104 } 105 106 /** 107 * @brief Sets IWDG Prescaler value. 108 * @param IWDG_Prescaler: specifies the IWDG Prescaler value. 109 * This parameter can be one of the following values: 110 * @arg IWDG_Prescaler_4: IWDG prescaler set to 4 111 * @arg IWDG_Prescaler_8: IWDG prescaler set to 8 112 * @arg IWDG_Prescaler_16: IWDG prescaler set to 16 113 * @arg IWDG_Prescaler_32: IWDG prescaler set to 32 114 * @arg IWDG_Prescaler_64: IWDG prescaler set to 64 115 * @arg IWDG_Prescaler_128: IWDG prescaler set to 128 116 * @arg IWDG_Prescaler_256: IWDG prescaler set to 256 117 * @retval : None 118 */ 119 void IWDG_SetPrescaler(uint8_t IWDG_Prescaler) 120 { 121 /* Check the parameters */ 122 assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler)); 123 IWDG->PR = IWDG_Prescaler; 124 } 125 126 /** 127 * @brief Sets IWDG Reload value. 128 * @param Reload: specifies the IWDG Reload value. 129 * This parameter must be a number between 0 and 0x0FFF. 130 * @retval : None 131 */ 132 void IWDG_SetReload(uint16_t Reload) 133 { 134 /* Check the parameters */ 135 assert_param(IS_IWDG_RELOAD(Reload)); 136 IWDG->RLR = Reload; 137 } 138 139 /** 140 * @brief Reloads IWDG counter with value defined in the reload register 141 * (write access to IWDG_PR and IWDG_RLR registers disabled). 142 * @param None 143 * @retval : None 144 */ 145 void IWDG_ReloadCounter(void) 146 { 147 IWDG->KR = KR_KEY_Reload; 148 } 149 150 /** 151 * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers 152 * disabled). 153 * @param None 154 * @retval : None 155 */ 156 void IWDG_Enable(void) 157 { 158 IWDG->KR = KR_KEY_Enable; 159 } 160 161 /** 162 * @brief Checks whether the specified IWDG flag is set or not. 163 * @param IWDG_FLAG: specifies the flag to check. 164 * This parameter can be one of the following values: 165 * @arg IWDG_FLAG_PVU: Prescaler Value Update on going 166 * @arg IWDG_FLAG_RVU: Reload Value Update on going 167 * @retval : The new state of IWDG_FLAG (SET or RESET). 168 */ 169 FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG) 170 { 171 FlagStatus bitstatus = RESET; 172 /* Check the parameters */ 173 assert_param(IS_IWDG_FLAG(IWDG_FLAG)); 174 if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET) 175 { 176 bitstatus = SET; 177 } 178 else 179 { 180 bitstatus = RESET; 181 } 182 /* Return the flag status */ 183 return bitstatus; 184 } 185 186 /** 187 * @} 188 */ 189 190 /** 191 * @} 192 */ 193 194 /** 195 * @} 196 */ 197 #endif // 0 198 /*-------------------------(C) COPYRIGHT 2016 HOLOCENE ----------------------*/ 199