STM8L15x Standard Peripherals Drivers: stm8l15x_wwdg.c Source File

STM8L15x/16x Standard Peripherals Drivers

STM8L15x Standard Peripherals Drivers

stm8l15x_wwdg.c

Go to the documentation of this file.
00001 /**
00002   ********************************************************************************
00003   * @file    stm8l15x_wwdg.c
00004   * @author  MCD Application Team
00005   * @version V1.5.0
00006   * @date    13-May-2011
00007   * @brief   This file provides firmware functions to manage the following 
00008   *          functionalities of the Window watchdog (WWDG) peripheral:           
00009   *           - Refresh window and Counter configuration
00010   *           - WWDG activation
00011   *           - Couter and software reset management
00012   *             
00013   *  @verbatim
00014   *    
00015   *          ===================================================================
00016   *                                     WWDG features
00017   *          ===================================================================
00018   *                                        
00019   *          Once enabled the WWDG generates a system reset on expiry of a programmed
00020   *          time period, unless the program refreshes the counter (downcounter) 
00021   *          before to reach 0x3F value (i.e. a reset is generated when the counter
00022   *          value rolls over from 0x40 to 0x3F). 
00023   *          An MCU reset is also generated if the counter value is refreshed
00024   *          before the counter has reached the refresh window value. This 
00025   *          implies that the counter must be refreshed in a limited window.
00026   *            
00027   *          Once enabled the WWDG cannot be disabled except by a system reset.
00028   *          
00029   *          If the WWDG is activated and the watchdog reset on halt option is 
00030   *          selected (Option byte), then the HALT instruction will generate a reset.                               
00031   *          
00032   *          WWDGF flag in RST_SR register can be used to inform when a WWDG
00033   *          reset occurs.
00034   *            
00035   *          WWDG timeout = (WWDG counter clock) * 12288 * (T[5:0] + 1)
00036   *                      
00037   *          Min-max timeout value @16 MHz(PCLK1): ~0.768 ms / ~49.152 ms
00038   *                            
00039   *          ===================================================================
00040   *                                 How to use this driver
00041   *          =================================================================== 
00042   *          1. Configure the WWDG refresh window using WWDG_SetWindowValue() function
00043   *            
00044   *          2. Set the WWDG counter value and start it using WWDG_Enable() function.
00045   *             When the WWDG is enabled the counter value should be configured to 
00046   *             a value greater than 0x40 to prevent generating an immediate reset.     
00047   *            
00048   *          3. Then the application program must refresh the WWDG counter at regular
00049   *             intervals during normal operation to prevent an MCU reset, using
00050   *             WWDG_SetCounter() function. This operation must occur only when
00051   *             the counter value is lower than the refresh window value, 
00052   *             programmed using WWDG_SetWindowValue().         
00053   *
00054   *  @endverbatim  
00055   *                             
00056   ******************************************************************************
00057   * @attention
00058   *
00059   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00060   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00061   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00062   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00063   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00064   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00065   *
00066   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
00067   ******************************************************************************  
00068   */
00069 
00070 /* Includes ------------------------------------------------------------------*/
00071 #include "stm8l15x_wwdg.h"
00072 
00073 /** @addtogroup STM8L15x_StdPeriph_Driver
00074   * @{
00075   */
00076 /** @defgroup WWDG 
00077   * @brief WWDG driver modules
00078   * @{
00079   */
00080   
00081 /* Private typedef -----------------------------------------------------------*/
00082 /* Private define ------------------------------------------------------------*/
00083 #define BIT_MASK          ((uint8_t)0x7F)
00084 /* Private macro -------------------------------------------------------------*/
00085 /* Private variables ---------------------------------------------------------*/
00086 /* Private function prototypes -----------------------------------------------*/
00087 /* Private functions ---------------------------------------------------------*/
00088 
00089 /** @defgroup WWDG_Private_Functions
00090   * @{
00091   */
00092   
00093 /** @defgroup WWDG_Group1 Refresh window and Counter configuration functions
00094  *  @brief   Refresh window and Counter configuration functions 
00095  *
00096 @verbatim   
00097  ===============================================================================
00098               Refresh window and Counter configuration functions
00099  ===============================================================================  
00100 
00101 @endverbatim
00102   * @{
00103   */
00104   
00105 /**
00106   * @brief  Initializes the WWDG peripheral.
00107   *         This function set Window Register = WindowValue, Counter Register
00108   *         according to Counter and \b ENABLE \b WWDG
00109   * @param  Counter : WWDG counter value
00110   * @param  WindowValue : specifies the WWDG Window Register, range is 0x00 to 0x7F.
00111   * @retval None
00112   */
00113 void WWDG_Init(uint8_t Counter, uint8_t WindowValue)
00114 {
00115   /* Check the parameters */
00116   assert_param(IS_WWDG_WINDOW_LIMIT_VALUE(WindowValue));
00117   
00118   WWDG->WR = WWDG_WR_RESET_VALUE;
00119   WWDG->CR = (uint8_t)(WWDG_CR_WDGA | Counter);
00120   WWDG->WR = (uint8_t)((uint8_t)BIT_MASK & (uint8_t) WindowValue);
00121 }
00122 
00123 /**
00124   * @brief  Sets the WWDG window value.
00125   * @param  WindowValue: specifies the window value to be compared to the downcounter.
00126   *         This parameter value must be lower than 0x80.
00127   * @retval None
00128   */
00129 void WWDG_SetWindowValue(uint8_t WindowValue)
00130 {
00131   __IO uint8_t tmpreg = 0;
00132 
00133   /* Check the parameters */
00134   assert_param(IS_WWDG_WINDOW_LIMIT_VALUE(WindowValue));
00135 
00136   /* Set W[6:0] bits according to WindowValue value */
00137   tmpreg |= (uint8_t) (WindowValue & (uint8_t) BIT_MASK);
00138 
00139   /* Store the new value */
00140   WWDG->WR = tmpreg;
00141 }
00142 
00143 /**
00144   * @brief  Sets the WWDG counter value.
00145   * @param  Counter: specifies the watchdog counter value.
00146   *   This parameter must be a number between 0x40 and 0x7F (to prevent generating
00147   *   an immediate reset) 
00148   * @retval None
00149   */
00150 void WWDG_SetCounter(uint8_t Counter)
00151 {
00152   /* Check the parameters */
00153   assert_param(IS_WWDG_COUNTER_VALUE(Counter));
00154 
00155   /* Write to T[6:0] bits to configure the counter value, no need to do
00156      a read-modify-write; writing a 0 to WDGA bit does nothing */
00157   WWDG->CR = (uint8_t)(Counter & (uint8_t)BIT_MASK);
00158 }
00159 /**
00160   * @}
00161   */
00162 
00163 /** @defgroup WWDG_Group2 WWDG activation function 
00164  *  @brief   WWDG activation function  
00165  *
00166 @verbatim   
00167  ===============================================================================
00168                           WWDG activation function 
00169  ===============================================================================  
00170 
00171 @endverbatim
00172   * @{
00173   */
00174   
00175 /**
00176   * @brief  Enables WWDG and load the counter value.
00177   * @param  Counter: specifies the watchdog counter value.
00178   *         This parameter must be a number between 0x40 and 0x7F.
00179   * @retval None
00180   */
00181 void WWDG_Enable(uint8_t Counter)
00182 {
00183   /* Check the parameters */
00184   assert_param(IS_WWDG_COUNTER_VALUE(Counter));
00185   WWDG->CR = (uint8_t)(WWDG_CR_WDGA | Counter);
00186 }
00187 
00188 /**
00189   * @}
00190   */
00191 
00192 /** @defgroup WWDG_Group3 WWDG counter and software reset management 
00193  *  @brief   WWDG counter and software reset management
00194  *
00195 @verbatim   
00196  ===============================================================================
00197                    WWDG counter and software reset management 
00198  ===============================================================================  
00199 
00200 @endverbatim
00201   * @{
00202   */
00203 /**
00204   * @brief Gets the WWDG Counter Value.
00205   *        This value could be used to check if WWDG is in the window, where
00206   *        refresh is allowed.
00207   * @param  None
00208   * @retval WWDG Counter Value
00209   */
00210 uint8_t WWDG_GetCounter(void)
00211 {
00212   return(WWDG->CR);
00213 }
00214 
00215 /**
00216   * @brief Generates immediate WWDG RESET.
00217   * @param  None
00218   * @retval None
00219   */
00220 void WWDG_SWReset(void)
00221 {
00222   WWDG->CR = WWDG_CR_WDGA; /* Activate WWDG, with clearing T6 */
00223 }
00224 
00225 /**
00226   * @}
00227   */
00228 
00229 /**
00230   * @}
00231   */
00232   
00233 /**
00234   * @}
00235   */
00236 
00237 /**
00238   * @}
00239   */
00240 
00241 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
STM8S Firmware Library: Overview

 

 

 

For complete documentation on STM8L15x 8-bit microcontrollers platform visit www.st.com