STM8S/A Standard Peripherals Drivers: stm8s_wwdg.c Source File

STM8S/A

stm8s_wwdg.c
Go to the documentation of this file.
00001 /**
00002   ********************************************************************************
00003   * @file    stm8s_wwdg.c
00004   * @author  MCD Application Team
00005   * @version V2.3.0
00006   * @date    16-June-2017
00007   * @brief   This file contains all the functions for the WWDG peripheral.
00008    ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm8s_wwdg.h"
00030 
00031 /** @addtogroup STM8S_StdPeriph_Driver
00032   * @{
00033   */
00034 /* Private define ------------------------------------------------------------*/
00035 #define BIT_MASK          ((uint8_t)0x7F)
00036 /* Private macro -------------------------------------------------------------*/
00037 /* Private variables ---------------------------------------------------------*/
00038 /* Private function prototypes -----------------------------------------------*/
00039 /* Private functions ---------------------------------------------------------*/
00040 
00041 /** @addtogroup WWDG_Public_Functions
00042   * @{
00043   */
00044 
00045 /**
00046   * @brief  Initializes the WWDG peripheral.
00047   *         This function set Window Register = WindowValue, Counter Register
00048   *         according to Counter and \b ENABLE \b WWDG
00049   * @param  Counter : WWDG counter value
00050   * @param  WindowValue : specifies the WWDG Window Register, range is 0x00 to 0x7F.
00051   * @retval None
00052   */
00053 void WWDG_Init(uint8_t Counter, uint8_t WindowValue)
00054 {
00055   /* Check the parameters */
00056   assert_param(IS_WWDG_WINDOWLIMITVALUE_OK(WindowValue));
00057   
00058   WWDG->WR = WWDG_WR_RESET_VALUE;
00059   WWDG->CR = (uint8_t)((uint8_t)(WWDG_CR_WDGA | WWDG_CR_T6) | (uint8_t)Counter);
00060   WWDG->WR = (uint8_t)((uint8_t)(~WWDG_CR_WDGA) & (uint8_t)(WWDG_CR_T6 | WindowValue));
00061 }
00062 
00063 /**
00064   * @brief  Refreshes the WWDG peripheral.
00065   * @param  Counter :  WWDG Counter Value
00066   *         This parameter must be a number between 0x40 and 0x7F.
00067   * @retval None
00068   */
00069 void WWDG_SetCounter(uint8_t Counter)
00070 {
00071   /* Check the parameters */
00072   assert_param(IS_WWDG_COUNTERVALUE_OK(Counter));
00073   
00074   /* Write to T[6:0] bits to configure the counter value, no need to do
00075   a read-modify-write; writing a 0 to WDGA bit does nothing */
00076   WWDG->CR = (uint8_t)(Counter & (uint8_t)BIT_MASK);
00077 }
00078 
00079 /**
00080   * @brief Gets the WWDG Counter Value.
00081   *        This value could be used to check if WWDG is in the window, where
00082   *        refresh is allowed.
00083   * @param  None
00084   * @retval WWDG Counter Value
00085   */
00086 uint8_t WWDG_GetCounter(void)
00087 {
00088   return(WWDG->CR);
00089 }
00090 
00091 /**
00092   * @brief  Generates immediate WWDG RESET.
00093   * @param  None
00094   * @retval None
00095   */
00096 void WWDG_SWReset(void)
00097 {
00098   WWDG->CR = WWDG_CR_WDGA; /* Activate WWDG, with clearing T6 */
00099 }
00100 
00101 /**
00102   * @brief  Sets the WWDG window value.
00103   * @param  WindowValue: specifies the window value to be compared to the
00104   *         downcounter.
00105   *         This parameter value must be lower than 0x80.
00106   * @retval None
00107   */
00108 void WWDG_SetWindowValue(uint8_t WindowValue)
00109 {
00110   /* Check the parameters */
00111   assert_param(IS_WWDG_WINDOWLIMITVALUE_OK(WindowValue));
00112   
00113   WWDG->WR = (uint8_t)((uint8_t)(~WWDG_CR_WDGA) & (uint8_t)(WWDG_CR_T6 | WindowValue));
00114 }
00115 
00116 /**
00117   * @}
00118   */
00119   
00120 /**
00121   * @}
00122   */
00123   
00124 
00125 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM8 8-bit Microcontrollers platform visit www.st.com