123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- #include "stm32f4xx_wwdg.h"
- #include "stm32f4xx_rcc.h"
- #define WWDG_OFFSET (WWDG_BASE - PERIPH_BASE)
- #define CFR_OFFSET (WWDG_OFFSET + 0x04)
- #define EWI_BitNumber 0x09
- #define CFR_EWI_BB (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4))
- #define CFR_WDGTB_MASK ((uint32_t)0xFFFFFE7F)
- #define CFR_W_MASK ((uint32_t)0xFFFFFF80)
- #define BIT_MASK ((uint8_t)0x7F)
- void WWDG_DeInit(void)
- {
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE);
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
- }
- void WWDG_SetPrescaler(uint32_t WWDG_Prescaler)
- {
- uint32_t tmpreg = 0;
-
- assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler));
-
- tmpreg = WWDG->CFR & CFR_WDGTB_MASK;
-
- tmpreg |= WWDG_Prescaler;
-
- WWDG->CFR = tmpreg;
- }
- void WWDG_SetWindowValue(uint8_t WindowValue)
- {
- __IO uint32_t tmpreg = 0;
-
- assert_param(IS_WWDG_WINDOW_VALUE(WindowValue));
-
- tmpreg = WWDG->CFR & CFR_W_MASK;
-
- tmpreg |= WindowValue & (uint32_t) BIT_MASK;
-
- WWDG->CFR = tmpreg;
- }
- void WWDG_EnableIT(void)
- {
- *(__IO uint32_t *) CFR_EWI_BB = (uint32_t)ENABLE;
- }
- void WWDG_SetCounter(uint8_t Counter)
- {
-
- assert_param(IS_WWDG_COUNTER(Counter));
-
- WWDG->CR = Counter & BIT_MASK;
- }
- void WWDG_Enable(uint8_t Counter)
- {
-
- assert_param(IS_WWDG_COUNTER(Counter));
- WWDG->CR = WWDG_CR_WDGA | Counter;
- }
- FlagStatus WWDG_GetFlagStatus(void)
- {
- FlagStatus bitstatus = RESET;
-
- if ((WWDG->SR) != (uint32_t)RESET)
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
- }
- void WWDG_ClearFlag(void)
- {
- WWDG->SR = (uint32_t)RESET;
- }
|