1 /* hal_wwdg.h */
2 #include "hal_wwdg.h"
3 
WWDG_Init(WWDG_Type * WWDGx,WWDG_Init_Type * init)4 void WWDG_Init(WWDG_Type * WWDGx, WWDG_Init_Type * init)
5 {
6     if (NULL != init)
7     {
8         WWDGx->CFGR = WWDG_CFGR_WDGTB(init->Prescaler)
9                     | WWDG_CFGR_W(init->UpperLimit);
10     }
11 }
12 
WWDG_Start(WWDG_Type * WWDGx)13 void WWDG_Start(WWDG_Type * WWDGx)
14 {
15     WWDGx->CR |=  WWDG_CR_WDGA_MASK;
16 }
17 
WWDG_Reload(WWDG_Type * WWDGx,uint32_t value)18 void WWDG_Reload(WWDG_Type * WWDGx, uint32_t value)
19 {
20     if (value > WWDG_LOWER_LIMIT)
21     {
22         WWDGx->CR = (WWDGx->CR & ~WWDG_CR_T_MASK) | WWDG_CR_T(value);
23     }
24 }
25 
WWDG_EnableInterrupts(WWDG_Type * WWDGx,uint32_t interrupts,bool enable)26 void WWDG_EnableInterrupts(WWDG_Type * WWDGx, uint32_t interrupts, bool enable)
27 {
28     if ( (true == enable) && (WWDG_INT_ALMOST_TIMEOUT == interrupts) )
29     {
30         WWDGx->CFGR |= WWDG_CFGR_EWI_MASK;
31     }
32     else
33     {
34         /* if WWDG_INT_ALMOST_TIMEOUT interrupt is enabled, only MCU reset can close it. */
35     }
36 }
37 
38 
WWDG_GetStatus(WWDG_Type * WWDGx)39 uint32_t WWDG_GetStatus(WWDG_Type * WWDGx)
40 {
41     return WWDGx->SR;
42 }
43 
WWDG_ClearStatus(WWDG_Type * WWDGx,uint32_t status)44 void WWDG_ClearStatus(WWDG_Type * WWDGx, uint32_t status)
45 {
46     WWDGx->SR &= ~status;
47 }
48 
49 
50 /* EOF. */
51