1 /** 2 ****************************************************************************** 3 * @file stm32c0xx_hal_wwdg.h 4 * @author MCD Application Team 5 * @brief Header file of WWDG HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2022 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef STM32C0xx_HAL_WWDG_H 21 #define STM32C0xx_HAL_WWDG_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32c0xx_hal_def.h" 29 30 /** @addtogroup STM32C0xx_HAL_Driver 31 * @{ 32 */ 33 34 /** @addtogroup WWDG 35 * @{ 36 */ 37 38 /* Exported types ------------------------------------------------------------*/ 39 40 /** @defgroup WWDG_Exported_Types WWDG Exported Types 41 * @{ 42 */ 43 44 /** 45 * @brief WWDG Init structure definition 46 */ 47 typedef struct 48 { 49 uint32_t Prescaler; /*!< Specifies the prescaler value of the WWDG. 50 This parameter can be a value of @ref WWDG_Prescaler */ 51 52 uint32_t Window; /*!< Specifies the WWDG window value to be compared to the downcounter. 53 This parameter must be a number Min_Data = 0x40 and Max_Data = 0x7F */ 54 55 uint32_t Counter; /*!< Specifies the WWDG free-running downcounter value. 56 This parameter must be a number between Min_Data = 0x40 and Max_Data = 0x7F */ 57 58 uint32_t EWIMode ; /*!< Specifies if WWDG Early Wakeup Interrupt is enable or not. 59 This parameter can be a value of @ref WWDG_EWI_Mode */ 60 61 } WWDG_InitTypeDef; 62 63 /** 64 * @brief WWDG handle Structure definition 65 */ 66 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1) 67 typedef struct __WWDG_HandleTypeDef 68 #else 69 typedef struct 70 #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */ 71 { 72 WWDG_TypeDef *Instance; /*!< Register base address */ 73 74 WWDG_InitTypeDef Init; /*!< WWDG required parameters */ 75 76 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1) 77 void (* EwiCallback)(struct __WWDG_HandleTypeDef *hwwdg); /*!< WWDG Early WakeUp Interrupt callback */ 78 79 void (* MspInitCallback)(struct __WWDG_HandleTypeDef *hwwdg); /*!< WWDG Msp Init callback */ 80 #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */ 81 } WWDG_HandleTypeDef; 82 83 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1) 84 /** 85 * @brief HAL WWDG common Callback ID enumeration definition 86 */ 87 typedef enum 88 { 89 HAL_WWDG_EWI_CB_ID = 0x00U, /*!< WWDG EWI callback ID */ 90 HAL_WWDG_MSPINIT_CB_ID = 0x01U, /*!< WWDG MspInit callback ID */ 91 } HAL_WWDG_CallbackIDTypeDef; 92 93 /** 94 * @brief HAL WWDG Callback pointer definition 95 */ 96 typedef void (*pWWDG_CallbackTypeDef)(WWDG_HandleTypeDef *hppp); /*!< pointer to a WWDG common callback functions */ 97 98 #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */ 99 /** 100 * @} 101 */ 102 103 /* Exported constants --------------------------------------------------------*/ 104 105 /** @defgroup WWDG_Exported_Constants WWDG Exported Constants 106 * @{ 107 */ 108 109 /** @defgroup WWDG_Interrupt_definition WWDG Interrupt definition 110 * @{ 111 */ 112 #define WWDG_IT_EWI WWDG_CFR_EWI /*!< Early wakeup interrupt */ 113 /** 114 * @} 115 */ 116 117 /** @defgroup WWDG_Flag_definition WWDG Flag definition 118 * @brief WWDG Flag definition 119 * @{ 120 */ 121 #define WWDG_FLAG_EWIF WWDG_SR_EWIF /*!< Early wakeup interrupt flag */ 122 /** 123 * @} 124 */ 125 126 /** @defgroup WWDG_Prescaler WWDG Prescaler 127 * @{ 128 */ 129 #define WWDG_PRESCALER_1 0x00000000u /*!< WWDG counter clock = (PCLK1/4096)/1 */ 130 #define WWDG_PRESCALER_2 WWDG_CFR_WDGTB_0 /*!< WWDG counter clock = (PCLK1/4096)/2 */ 131 #define WWDG_PRESCALER_4 WWDG_CFR_WDGTB_1 /*!< WWDG counter clock = (PCLK1/4096)/4 */ 132 #define WWDG_PRESCALER_8 (WWDG_CFR_WDGTB_1 | WWDG_CFR_WDGTB_0) /*!< WWDG counter clock = (PCLK1/4096)/8 */ 133 #define WWDG_PRESCALER_16 WWDG_CFR_WDGTB_2 /*!< WWDG counter clock = (PCLK1/4096)/16 */ 134 #define WWDG_PRESCALER_32 (WWDG_CFR_WDGTB_2 | WWDG_CFR_WDGTB_0) /*!< WWDG counter clock = (PCLK1/4096)/32 */ 135 #define WWDG_PRESCALER_64 (WWDG_CFR_WDGTB_2 | WWDG_CFR_WDGTB_1) /*!< WWDG counter clock = (PCLK1/4096)/64 */ 136 #define WWDG_PRESCALER_128 WWDG_CFR_WDGTB /*!< WWDG counter clock = (PCLK1/4096)/128 */ 137 /** 138 * @} 139 */ 140 141 /** @defgroup WWDG_EWI_Mode WWDG Early Wakeup Interrupt Mode 142 * @{ 143 */ 144 #define WWDG_EWI_DISABLE 0x00000000u /*!< EWI Disable */ 145 #define WWDG_EWI_ENABLE WWDG_CFR_EWI /*!< EWI Enable */ 146 /** 147 * @} 148 */ 149 150 /** 151 * @} 152 */ 153 154 /* Private macros ------------------------------------------------------------*/ 155 156 /** @defgroup WWDG_Private_Macros WWDG Private Macros 157 * @{ 158 */ 159 #define IS_WWDG_PRESCALER(__PRESCALER__) (((__PRESCALER__) == WWDG_PRESCALER_1) || \ 160 ((__PRESCALER__) == WWDG_PRESCALER_2) || \ 161 ((__PRESCALER__) == WWDG_PRESCALER_4) || \ 162 ((__PRESCALER__) == WWDG_PRESCALER_8) || \ 163 ((__PRESCALER__) == WWDG_PRESCALER_16) || \ 164 ((__PRESCALER__) == WWDG_PRESCALER_32) || \ 165 ((__PRESCALER__) == WWDG_PRESCALER_64) || \ 166 ((__PRESCALER__) == WWDG_PRESCALER_128)) 167 168 #define IS_WWDG_WINDOW(__WINDOW__) (((__WINDOW__) >= WWDG_CFR_W_6) && ((__WINDOW__) <= WWDG_CFR_W)) 169 170 #define IS_WWDG_COUNTER(__COUNTER__) (((__COUNTER__) >= WWDG_CR_T_6) && ((__COUNTER__) <= WWDG_CR_T)) 171 172 #define IS_WWDG_EWI_MODE(__MODE__) (((__MODE__) == WWDG_EWI_ENABLE) || \ 173 ((__MODE__) == WWDG_EWI_DISABLE)) 174 /** 175 * @} 176 */ 177 178 179 /* Exported macros ------------------------------------------------------------*/ 180 181 /** @defgroup WWDG_Exported_Macros WWDG Exported Macros 182 * @{ 183 */ 184 185 /** 186 * @brief Enable the WWDG peripheral. 187 * @param __HANDLE__ WWDG handle 188 * @retval None 189 */ 190 #define __HAL_WWDG_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR, WWDG_CR_WDGA) 191 192 /** 193 * @brief Enable the WWDG early wakeup interrupt. 194 * @param __HANDLE__ WWDG handle 195 * @param __INTERRUPT__ specifies the interrupt to enable. 196 * This parameter can be one of the following values: 197 * @arg WWDG_IT_EWI: Early wakeup interrupt 198 * @note Once enabled this interrupt cannot be disabled except by a system reset. 199 * @retval None 200 */ 201 #define __HAL_WWDG_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CFR, (__INTERRUPT__)) 202 203 /** 204 * @brief Check whether the selected WWDG interrupt has occurred or not. 205 * @param __HANDLE__ WWDG handle 206 * @param __INTERRUPT__ specifies the it to check. 207 * This parameter can be one of the following values: 208 * @arg WWDG_FLAG_EWIF: Early wakeup interrupt IT 209 * @retval The new state of WWDG_FLAG (SET or RESET). 210 */ 211 #define __HAL_WWDG_GET_IT(__HANDLE__, __INTERRUPT__) __HAL_WWDG_GET_FLAG((__HANDLE__),(__INTERRUPT__)) 212 213 /** @brief Clear the WWDG interrupt pending bits. 214 * bits to clear the selected interrupt pending bits. 215 * @param __HANDLE__ WWDG handle 216 * @param __INTERRUPT__ specifies the interrupt pending bit to clear. 217 * This parameter can be one of the following values: 218 * @arg WWDG_FLAG_EWIF: Early wakeup interrupt flag 219 */ 220 #define __HAL_WWDG_CLEAR_IT(__HANDLE__, __INTERRUPT__) __HAL_WWDG_CLEAR_FLAG((__HANDLE__), (__INTERRUPT__)) 221 222 /** 223 * @brief Check whether the specified WWDG flag is set or not. 224 * @param __HANDLE__ WWDG handle 225 * @param __FLAG__ specifies the flag to check. 226 * This parameter can be one of the following values: 227 * @arg WWDG_FLAG_EWIF: Early wakeup interrupt flag 228 * @retval The new state of WWDG_FLAG (SET or RESET). 229 */ 230 #define __HAL_WWDG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) 231 232 /** 233 * @brief Clear the WWDG's pending flags. 234 * @param __HANDLE__ WWDG handle 235 * @param __FLAG__ specifies the flag to clear. 236 * This parameter can be one of the following values: 237 * @arg WWDG_FLAG_EWIF: Early wakeup interrupt flag 238 * @retval None 239 */ 240 #define __HAL_WWDG_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__)) 241 242 /** @brief Check whether the specified WWDG interrupt source is enabled or not. 243 * @param __HANDLE__ WWDG Handle. 244 * @param __INTERRUPT__ specifies the WWDG interrupt source to check. 245 * This parameter can be one of the following values: 246 * @arg WWDG_IT_EWI: Early Wakeup Interrupt 247 * @retval state of __INTERRUPT__ (TRUE or FALSE). 248 */ 249 #define __HAL_WWDG_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CFR\ 250 & (__INTERRUPT__)) == (__INTERRUPT__)) 251 252 /** 253 * @} 254 */ 255 256 /* Exported functions --------------------------------------------------------*/ 257 258 /** @addtogroup WWDG_Exported_Functions 259 * @{ 260 */ 261 262 /** @addtogroup WWDG_Exported_Functions_Group1 263 * @{ 264 */ 265 /* Initialization/de-initialization functions **********************************/ 266 HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg); 267 void HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg); 268 /* Callbacks Register/UnRegister functions ***********************************/ 269 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1) 270 HAL_StatusTypeDef HAL_WWDG_RegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID, 271 pWWDG_CallbackTypeDef pCallback); 272 HAL_StatusTypeDef HAL_WWDG_UnRegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID); 273 #endif /* USE_HAL_WWDG_REGISTER_CALLBACKS */ 274 275 /** 276 * @} 277 */ 278 279 /** @addtogroup WWDG_Exported_Functions_Group2 280 * @{ 281 */ 282 /* I/O operation functions ******************************************************/ 283 HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg); 284 void HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg); 285 void HAL_WWDG_EarlyWakeupCallback(WWDG_HandleTypeDef *hwwdg); 286 /** 287 * @} 288 */ 289 290 /** 291 * @} 292 */ 293 294 /** 295 * @} 296 */ 297 298 /** 299 * @} 300 */ 301 302 #ifdef __cplusplus 303 } 304 #endif 305 306 #endif /* STM32C0xx_HAL_WWDG_H */ 307 308