STM32F10x Standard Peripherals Library  3.5.0
/opt/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_wwdg.c
Go to the documentation of this file.
00001 
00022 /* Includes ------------------------------------------------------------------*/
00023 #include "stm32f10x_wwdg.h"
00024 #include "stm32f10x_rcc.h"
00025 
00047 /* ----------- WWDG registers bit address in the alias region ----------- */
00048 #define WWDG_OFFSET       (WWDG_BASE - PERIPH_BASE)
00049 
00050 /* Alias word address of EWI bit */
00051 #define CFR_OFFSET        (WWDG_OFFSET + 0x04)
00052 #define EWI_BitNumber     0x09
00053 #define CFR_EWI_BB        (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4))
00054 
00055 /* --------------------- WWDG registers bit mask ------------------------ */
00056 
00057 /* CR register bit mask */
00058 #define CR_WDGA_Set       ((uint32_t)0x00000080)
00059 
00060 /* CFR register bit mask */
00061 #define CFR_WDGTB_Mask    ((uint32_t)0xFFFFFE7F)
00062 #define CFR_W_Mask        ((uint32_t)0xFFFFFF80)
00063 #define BIT_Mask          ((uint8_t)0x7F)
00064 
00102 void WWDG_DeInit(void)
00103 {
00104   RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE);
00105   RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
00106 }
00107 
00118 void WWDG_SetPrescaler(uint32_t WWDG_Prescaler)
00119 {
00120   uint32_t tmpreg = 0;
00121   /* Check the parameters */
00122   assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler));
00123   /* Clear WDGTB[1:0] bits */
00124   tmpreg = WWDG->CFR & CFR_WDGTB_Mask;
00125   /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */
00126   tmpreg |= WWDG_Prescaler;
00127   /* Store the new value */
00128   WWDG->CFR = tmpreg;
00129 }
00130 
00137 void WWDG_SetWindowValue(uint8_t WindowValue)
00138 {
00139   __IO uint32_t tmpreg = 0;
00140 
00141   /* Check the parameters */
00142   assert_param(IS_WWDG_WINDOW_VALUE(WindowValue));
00143   /* Clear W[6:0] bits */
00144 
00145   tmpreg = WWDG->CFR & CFR_W_Mask;
00146 
00147   /* Set W[6:0] bits according to WindowValue value */
00148   tmpreg |= WindowValue & (uint32_t) BIT_Mask;
00149 
00150   /* Store the new value */
00151   WWDG->CFR = tmpreg;
00152 }
00153 
00159 void WWDG_EnableIT(void)
00160 {
00161   *(__IO uint32_t *) CFR_EWI_BB = (uint32_t)ENABLE;
00162 }
00163 
00170 void WWDG_SetCounter(uint8_t Counter)
00171 {
00172   /* Check the parameters */
00173   assert_param(IS_WWDG_COUNTER(Counter));
00174   /* Write to T[6:0] bits to configure the counter value, no need to do
00175      a read-modify-write; writing a 0 to WDGA bit does nothing */
00176   WWDG->CR = Counter & BIT_Mask;
00177 }
00178 
00185 void WWDG_Enable(uint8_t Counter)
00186 {
00187   /* Check the parameters */
00188   assert_param(IS_WWDG_COUNTER(Counter));
00189   WWDG->CR = CR_WDGA_Set | Counter;
00190 }
00191 
00197 FlagStatus WWDG_GetFlagStatus(void)
00198 {
00199   return (FlagStatus)(WWDG->SR);
00200 }
00201 
00207 void WWDG_ClearFlag(void)
00208 {
00209   WWDG->SR = (uint32_t)RESET;
00210 }
00211 
00224 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/