STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_wwdg.c
Go to the documentation of this file.
1 
116 /* Includes ------------------------------------------------------------------*/
117 #include "stm32l4xx_hal.h"
118 
123 #ifdef HAL_WWDG_MODULE_ENABLED
124 
129 /* Private typedef -----------------------------------------------------------*/
130 /* Private define ------------------------------------------------------------*/
131 /* Private macro -------------------------------------------------------------*/
132 /* Private variables ---------------------------------------------------------*/
133 /* Private function prototypes -----------------------------------------------*/
134 /* Exported functions --------------------------------------------------------*/
135 
164 HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
165 {
166  /* Check the WWDG handle allocation */
167  if (hwwdg == NULL)
168  {
169  return HAL_ERROR;
170  }
171 
172  /* Check the parameters */
173  assert_param(IS_WWDG_ALL_INSTANCE(hwwdg->Instance));
174  assert_param(IS_WWDG_PRESCALER(hwwdg->Init.Prescaler));
175  assert_param(IS_WWDG_WINDOW(hwwdg->Init.Window));
176  assert_param(IS_WWDG_COUNTER(hwwdg->Init.Counter));
177  assert_param(IS_WWDG_EWI_MODE(hwwdg->Init.EWIMode));
178 
179 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
180  /* Reset Callback pointers */
181  if(hwwdg->EwiCallback == NULL)
182  {
184  }
185 
186  if(hwwdg->MspInitCallback == NULL)
187  {
189  }
190 
191  /* Init the low level hardware */
192  hwwdg->MspInitCallback(hwwdg);
193 #else
194  /* Init the low level hardware */
195  HAL_WWDG_MspInit(hwwdg);
196 #endif
197 
198  /* Set WWDG Counter */
199  WRITE_REG(hwwdg->Instance->CR, (WWDG_CR_WDGA | hwwdg->Init.Counter));
200 
201  /* Set WWDG Prescaler and Window */
202  WRITE_REG(hwwdg->Instance->CFR, (hwwdg->Init.EWIMode | hwwdg->Init.Prescaler | hwwdg->Init.Window));
203 
204  /* Return function status */
205  return HAL_OK;
206 }
207 
208 
219 {
220  /* Prevent unused argument(s) compilation warning */
221  UNUSED(hwwdg);
222 
223  /* NOTE: This function should not be modified, when the callback is needed,
224  the HAL_WWDG_MspInit could be implemented in the user file
225  */
226 }
227 
228 
229 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
230 
242 {
243  HAL_StatusTypeDef status = HAL_OK;
244 
245  if(pCallback == NULL)
246  {
247  status = HAL_ERROR;
248  }
249  else
250  {
251  switch(CallbackID)
252  {
253  case HAL_WWDG_EWI_CB_ID:
254  hwwdg->EwiCallback = pCallback;
255  break;
256 
258  hwwdg->MspInitCallback = pCallback;
259  break;
260 
261  default:
262  status = HAL_ERROR;
263  break;
264  }
265  }
266 
267  return status;
268 }
269 
270 
282 {
283  HAL_StatusTypeDef status = HAL_OK;
284 
285  switch(CallbackID)
286  {
287  case HAL_WWDG_EWI_CB_ID:
289  break;
290 
293  break;
294 
295  default:
296  status = HAL_ERROR;
297  break;
298  }
299 
300  return status;
301 }
302 #endif
303 
330 HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg)
331 {
332  /* Write to WWDG CR the WWDG Counter value to refresh with */
333  WRITE_REG(hwwdg->Instance->CR, (hwwdg->Init.Counter));
334 
335  /* Return function status */
336  return HAL_OK;
337 }
338 
354 {
355  /* Check if Early Wakeup Interrupt is enable */
356  if (__HAL_WWDG_GET_IT_SOURCE(hwwdg, WWDG_IT_EWI) != RESET)
357  {
358  /* Check if WWDG Early Wakeup Interrupt occurred */
359  if (__HAL_WWDG_GET_FLAG(hwwdg, WWDG_FLAG_EWIF) != RESET)
360  {
361  /* Clear the WWDG Early Wakeup flag */
362  __HAL_WWDG_CLEAR_FLAG(hwwdg, WWDG_FLAG_EWIF);
363 
364 #if (USE_HAL_WWDG_REGISTER_CALLBACKS == 1)
365  /* Early Wakeup registered callback */
366  hwwdg->EwiCallback(hwwdg);
367 #else
368  /* Early Wakeup callback */
370 #endif
371  }
372  }
373 }
374 
375 
383 {
384  /* Prevent unused argument(s) compilation warning */
385  UNUSED(hwwdg);
386 
387  /* NOTE: This function should not be modified, when the callback is needed,
388  the HAL_WWDG_EarlyWakeupCallback could be implemented in the user file
389  */
390 }
391 
400 #endif /* HAL_WWDG_MODULE_ENABLED */
401 
409 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void HAL_WWDG_MspInit(WWDG_HandleTypeDef *hwwdg)
Initialize the WWDG MSP.
void(* MspInitCallback)(struct __WWDG_HandleTypeDef *hwwdg)
This file contains all the functions prototypes for the HAL module driver.
HAL_WWDG_CallbackIDTypeDef
HAL WWDG common Callback ID enumeration definition.
void HAL_WWDG_IRQHandler(WWDG_HandleTypeDef *hwwdg)
Handle WWDG interrupt request.
HAL_StatusTypeDef HAL_WWDG_Init(WWDG_HandleTypeDef *hwwdg)
Initialize the WWDG according to the specified. parameters in the WWDG_InitTypeDef of associated hand...
WWDG_InitTypeDef Init
return HAL_OK
void(* EwiCallback)(struct __WWDG_HandleTypeDef *hwwdg)
void(* pWWDG_CallbackTypeDef)(WWDG_HandleTypeDef *hppp)
HAL WWDG Callback pointer definition.
HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg)
Refresh the WWDG.
void HAL_WWDG_EarlyWakeupCallback(WWDG_HandleTypeDef *hwwdg)
WWDG Early Wakeup callback.
HAL_StatusTypeDef HAL_WWDG_RegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID, pWWDG_CallbackTypeDef pCallback)
Register a User WWDG Callback To be used instead of the weak (surcharged) predefined callback...
HAL_StatusTypeDef HAL_WWDG_UnRegisterCallback(WWDG_HandleTypeDef *hwwdg, HAL_WWDG_CallbackIDTypeDef CallbackID)
Unregister a WWDG Callback WWDG Callback is redirected to the weak (surcharged) predefined callback...
WWDG handle Structure definition.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))