stm32f10x_wwdg.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f10x_wwdg.c
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   This file provides all the WWDG firmware functions.
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f10x_wwdg.h"
00023 #include "stm32f10x_rcc.h"
00024 
00025 /** @addtogroup STM32F10x_StdPeriph_Driver
00026   * @{
00027   */
00028 
00029 /** @defgroup WWDG 
00030   * @brief WWDG driver modules
00031   * @{
00032   */
00033 
00034 /** @defgroup WWDG_Private_TypesDefinitions
00035   * @{
00036   */
00037 
00038 /**
00039   * @}
00040   */
00041 
00042 /** @defgroup WWDG_Private_Defines
00043   * @{
00044   */
00045 
00046 /* ----------- WWDG registers bit address in the alias region ----------- */
00047 #define WWDG_OFFSET       (WWDG_BASE - PERIPH_BASE)
00048 
00049 /* Alias word address of EWI bit */
00050 #define CFR_OFFSET        (WWDG_OFFSET + 0x04)
00051 #define EWI_BitNumber     0x09
00052 #define CFR_EWI_BB        (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4))
00053 
00054 /* --------------------- WWDG registers bit mask ------------------------ */
00055 
00056 /* CR register bit mask */
00057 #define CR_WDGA_Set       ((uint32_t)0x00000080)
00058 
00059 /* CFR register bit mask */
00060 #define CFR_WDGTB_Mask    ((uint32_t)0xFFFFFE7F)
00061 #define CFR_W_Mask        ((uint32_t)0xFFFFFF80)
00062 #define BIT_Mask          ((uint8_t)0x7F)
00063 
00064 /**
00065   * @}
00066   */
00067 
00068 /** @defgroup WWDG_Private_Macros
00069   * @{
00070   */
00071 
00072 /**
00073   * @}
00074   */
00075 
00076 /** @defgroup WWDG_Private_Variables
00077   * @{
00078   */
00079 
00080 /**
00081   * @}
00082   */
00083 
00084 /** @defgroup WWDG_Private_FunctionPrototypes
00085   * @{
00086   */
00087 
00088 /**
00089   * @}
00090   */
00091 
00092 /** @defgroup WWDG_Private_Functions
00093   * @{
00094   */
00095 
00096 /**
00097   * @brief  Deinitializes the WWDG peripheral registers to their default reset values.
00098   * @param  None
00099   * @retval None
00100   */
00101 void WWDG_DeInit(void)
00102 {
00103   RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE);
00104   RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
00105 }
00106 
00107 /**
00108   * @brief  Sets the WWDG Prescaler.
00109   * @param  WWDG_Prescaler: specifies the WWDG Prescaler.
00110   *   This parameter can be one of the following values:
00111   *     @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1
00112   *     @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2
00113   *     @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4
00114   *     @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8
00115   * @retval None
00116   */
00117 void WWDG_SetPrescaler(uint32_t WWDG_Prescaler)
00118 {
00119   uint32_t tmpreg = 0;
00120   /* Check the parameters */
00121   assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler));
00122   /* Clear WDGTB[1:0] bits */
00123   tmpreg = WWDG->CFR & CFR_WDGTB_Mask;
00124   /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */
00125   tmpreg |= WWDG_Prescaler;
00126   /* Store the new value */
00127   WWDG->CFR = tmpreg;
00128 }
00129 
00130 /**
00131   * @brief  Sets the WWDG window value.
00132   * @param  WindowValue: specifies the window value to be compared to the downcounter.
00133   *   This parameter value must be lower than 0x80.
00134   * @retval None
00135   */
00136 void WWDG_SetWindowValue(uint8_t WindowValue)
00137 {
00138   __IO uint32_t tmpreg = 0;
00139 
00140   /* Check the parameters */
00141   assert_param(IS_WWDG_WINDOW_VALUE(WindowValue));
00142   /* Clear W[6:0] bits */
00143 
00144   tmpreg = WWDG->CFR & CFR_W_Mask;
00145 
00146   /* Set W[6:0] bits according to WindowValue value */
00147   tmpreg |= WindowValue & (uint32_t) BIT_Mask;
00148 
00149   /* Store the new value */
00150   WWDG->CFR = tmpreg;
00151 }
00152 
00153 /**
00154   * @brief  Enables the WWDG Early Wakeup interrupt(EWI).
00155   * @param  None
00156   * @retval None
00157   */
00158 void WWDG_EnableIT(void)
00159 {
00160   *(__IO uint32_t *) CFR_EWI_BB = (uint32_t)ENABLE;
00161 }
00162 
00163 /**
00164   * @brief  Sets the WWDG counter value.
00165   * @param  Counter: specifies the watchdog counter value.
00166   *   This parameter must be a number between 0x40 and 0x7F.
00167   * @retval None
00168   */
00169 void WWDG_SetCounter(uint8_t Counter)
00170 {
00171   /* Check the parameters */
00172   assert_param(IS_WWDG_COUNTER(Counter));
00173   /* Write to T[6:0] bits to configure the counter value, no need to do
00174      a read-modify-write; writing a 0 to WDGA bit does nothing */
00175   WWDG->CR = Counter & BIT_Mask;
00176 }
00177 
00178 /**
00179   * @brief  Enables WWDG and load the counter value.                  
00180   * @param  Counter: specifies the watchdog counter value.
00181   *   This parameter must be a number between 0x40 and 0x7F.
00182   * @retval None
00183   */
00184 void WWDG_Enable(uint8_t Counter)
00185 {
00186   /* Check the parameters */
00187   assert_param(IS_WWDG_COUNTER(Counter));
00188   WWDG->CR = CR_WDGA_Set | Counter;
00189 }
00190 
00191 /**
00192   * @brief  Checks whether the Early Wakeup interrupt flag is set or not.
00193   * @param  None
00194   * @retval The new state of the Early Wakeup interrupt flag (SET or RESET)
00195   */
00196 FlagStatus WWDG_GetFlagStatus(void)
00197 {
00198   return (FlagStatus)(WWDG->SR);
00199 }
00200 
00201 /**
00202   * @brief  Clears Early Wakeup interrupt flag.
00203   * @param  None
00204   * @retval None
00205   */
00206 void WWDG_ClearFlag(void)
00207 {
00208   WWDG->SR = (uint32_t)RESET;
00209 }
00210 
00211 /**
00212   * @}
00213   */
00214 
00215 /**
00216   * @}
00217   */
00218 
00219 /**
00220   * @}
00221   */
00222 
00223 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32