STM32F103xB HAL User Manual
stm32f1xx_ll_wwdg.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f1xx_ll_wwdg.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of WWDG LL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00010   * All rights reserved.</center></h2>
00011   *
00012   * This software component is licensed by ST under BSD 3-Clause license,
00013   * the "License"; You may not use this file except in compliance with the
00014   * License. You may obtain a copy of the License at:
00015   *                        opensource.org/licenses/BSD-3-Clause
00016   *
00017   ******************************************************************************
00018   */
00019 
00020 /* Define to prevent recursive inclusion -------------------------------------*/
00021 #ifndef STM32F1xx_LL_WWDG_H
00022 #define STM32F1xx_LL_WWDG_H
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm32f1xx.h"
00030 
00031 /** @addtogroup STM32F1xx_LL_Driver
00032   * @{
00033   */
00034 
00035 #if defined (WWDG)
00036 
00037 /** @defgroup WWDG_LL WWDG
00038   * @{
00039   */
00040 
00041 /* Private types -------------------------------------------------------------*/
00042 /* Private variables ---------------------------------------------------------*/
00043 /* Private constants ---------------------------------------------------------*/
00044 /* Private macros ------------------------------------------------------------*/
00045 /* Exported types ------------------------------------------------------------*/
00046 /* Exported constants --------------------------------------------------------*/
00047 /** @defgroup WWDG_LL_Exported_Constants WWDG Exported Constants
00048   * @{
00049   */
00050 
00051 /** @defgroup WWDG_LL_EC_IT IT Defines
00052   * @brief    IT defines which can be used with LL_WWDG_ReadReg and  LL_WWDG_WriteReg functions
00053   * @{
00054   */
00055 #define LL_WWDG_CFR_EWI                     WWDG_CFR_EWI
00056 /**
00057   * @}
00058   */
00059 
00060 /** @defgroup WWDG_LL_EC_PRESCALER  PRESCALER
00061   * @{
00062   */
00063 #define LL_WWDG_PRESCALER_1                 0x00000000u                                               /*!< WWDG counter clock = (PCLK1/4096)/1 */
00064 #define LL_WWDG_PRESCALER_2                 WWDG_CFR_WDGTB_0                                          /*!< WWDG counter clock = (PCLK1/4096)/2 */
00065 #define LL_WWDG_PRESCALER_4                 WWDG_CFR_WDGTB_1                                          /*!< WWDG counter clock = (PCLK1/4096)/4 */
00066 #define LL_WWDG_PRESCALER_8                 (WWDG_CFR_WDGTB_0 | WWDG_CFR_WDGTB_1)                     /*!< WWDG counter clock = (PCLK1/4096)/8 */
00067 /**
00068   * @}
00069   */
00070 
00071 /**
00072   * @}
00073   */
00074 
00075 /* Exported macro ------------------------------------------------------------*/
00076 /** @defgroup WWDG_LL_Exported_Macros WWDG Exported Macros
00077   * @{
00078   */
00079 /** @defgroup WWDG_LL_EM_WRITE_READ Common Write and read registers macros
00080   * @{
00081   */
00082 /**
00083   * @brief  Write a value in WWDG register
00084   * @param  __INSTANCE__ WWDG Instance
00085   * @param  __REG__ Register to be written
00086   * @param  __VALUE__ Value to be written in the register
00087   * @retval None
00088   */
00089 #define LL_WWDG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
00090 
00091 /**
00092   * @brief  Read a value in WWDG register
00093   * @param  __INSTANCE__ WWDG Instance
00094   * @param  __REG__ Register to be read
00095   * @retval Register value
00096   */
00097 #define LL_WWDG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
00098 /**
00099   * @}
00100   */
00101 
00102 /**
00103   * @}
00104   */
00105 
00106 /* Exported functions --------------------------------------------------------*/
00107 /** @defgroup WWDG_LL_Exported_Functions WWDG Exported Functions
00108   * @{
00109   */
00110 
00111 /** @defgroup WWDG_LL_EF_Configuration Configuration
00112   * @{
00113   */
00114 /**
00115   * @brief  Enable Window Watchdog. The watchdog is always disabled after a reset.
00116   * @note   It is enabled by setting the WDGA bit in the WWDG_CR register,
00117   *         then it cannot be disabled again except by a reset.
00118   *         This bit is set by software and only cleared by hardware after a reset.
00119   *         When WDGA = 1, the watchdog can generate a reset.
00120   * @rmtoll CR           WDGA          LL_WWDG_Enable
00121   * @param  WWDGx WWDG Instance
00122   * @retval None
00123   */
00124 __STATIC_INLINE void LL_WWDG_Enable(WWDG_TypeDef *WWDGx)
00125 {
00126   SET_BIT(WWDGx->CR, WWDG_CR_WDGA);
00127 }
00128 
00129 /**
00130   * @brief  Checks if Window Watchdog is enabled
00131   * @rmtoll CR           WDGA          LL_WWDG_IsEnabled
00132   * @param  WWDGx WWDG Instance
00133   * @retval State of bit (1 or 0).
00134   */
00135 __STATIC_INLINE uint32_t LL_WWDG_IsEnabled(WWDG_TypeDef *WWDGx)
00136 {
00137   return ((READ_BIT(WWDGx->CR, WWDG_CR_WDGA) == (WWDG_CR_WDGA)) ? 1UL : 0UL);
00138 }
00139 
00140 /**
00141   * @brief  Set the Watchdog counter value to provided value (7-bits T[6:0])
00142   * @note   When writing to the WWDG_CR register, always write 1 in the MSB b6 to avoid generating an immediate reset
00143   *         This counter is decremented every (4096 x 2expWDGTB) PCLK cycles
00144   *         A reset is produced when it rolls over from 0x40 to 0x3F (bit T6 becomes cleared)
00145   *         Setting the counter lower then 0x40 causes an immediate reset (if WWDG enabled)
00146   * @rmtoll CR           T             LL_WWDG_SetCounter
00147   * @param  WWDGx WWDG Instance
00148   * @param  Counter 0..0x7F (7 bit counter value)
00149   * @retval None
00150   */
00151 __STATIC_INLINE void LL_WWDG_SetCounter(WWDG_TypeDef *WWDGx, uint32_t Counter)
00152 {
00153   MODIFY_REG(WWDGx->CR, WWDG_CR_T, Counter);
00154 }
00155 
00156 /**
00157   * @brief  Return current Watchdog Counter Value (7 bits counter value)
00158   * @rmtoll CR           T             LL_WWDG_GetCounter
00159   * @param  WWDGx WWDG Instance
00160   * @retval 7 bit Watchdog Counter value
00161   */
00162 __STATIC_INLINE uint32_t LL_WWDG_GetCounter(WWDG_TypeDef *WWDGx)
00163 {
00164   return (READ_BIT(WWDGx->CR, WWDG_CR_T));
00165 }
00166 
00167 /**
00168   * @brief  Set the time base of the prescaler (WDGTB).
00169   * @note   Prescaler is used to apply ratio on PCLK clock, so that Watchdog counter
00170   *         is decremented every (4096 x 2expWDGTB) PCLK cycles
00171   * @rmtoll CFR          WDGTB         LL_WWDG_SetPrescaler
00172   * @param  WWDGx WWDG Instance
00173   * @param  Prescaler This parameter can be one of the following values:
00174   *         @arg @ref LL_WWDG_PRESCALER_1
00175   *         @arg @ref LL_WWDG_PRESCALER_2
00176   *         @arg @ref LL_WWDG_PRESCALER_4
00177   *         @arg @ref LL_WWDG_PRESCALER_8
00178   * @retval None
00179   */
00180 __STATIC_INLINE void LL_WWDG_SetPrescaler(WWDG_TypeDef *WWDGx, uint32_t Prescaler)
00181 {
00182   MODIFY_REG(WWDGx->CFR, WWDG_CFR_WDGTB, Prescaler);
00183 }
00184 
00185 /**
00186   * @brief  Return current Watchdog Prescaler Value
00187   * @rmtoll CFR          WDGTB         LL_WWDG_GetPrescaler
00188   * @param  WWDGx WWDG Instance
00189   * @retval Returned value can be one of the following values:
00190   *         @arg @ref LL_WWDG_PRESCALER_1
00191   *         @arg @ref LL_WWDG_PRESCALER_2
00192   *         @arg @ref LL_WWDG_PRESCALER_4
00193   *         @arg @ref LL_WWDG_PRESCALER_8
00194   */
00195 __STATIC_INLINE uint32_t LL_WWDG_GetPrescaler(WWDG_TypeDef *WWDGx)
00196 {
00197   return (READ_BIT(WWDGx->CFR, WWDG_CFR_WDGTB));
00198 }
00199 
00200 /**
00201   * @brief  Set the Watchdog Window value to be compared to the downcounter (7-bits W[6:0]).
00202   * @note   This window value defines when write in the WWDG_CR register
00203   *         to program Watchdog counter is allowed.
00204   *         Watchdog counter value update must occur only when the counter value
00205   *         is lower than the Watchdog window register value.
00206   *         Otherwise, a MCU reset is generated if the 7-bit Watchdog counter value
00207   *         (in the control register) is refreshed before the downcounter has reached
00208   *         the watchdog window register value.
00209   *         Physically is possible to set the Window lower then 0x40 but it is not recommended.
00210   *         To generate an immediate reset, it is possible to set the Counter lower than 0x40.
00211   * @rmtoll CFR          W             LL_WWDG_SetWindow
00212   * @param  WWDGx WWDG Instance
00213   * @param  Window 0x00..0x7F (7 bit Window value)
00214   * @retval None
00215   */
00216 __STATIC_INLINE void LL_WWDG_SetWindow(WWDG_TypeDef *WWDGx, uint32_t Window)
00217 {
00218   MODIFY_REG(WWDGx->CFR, WWDG_CFR_W, Window);
00219 }
00220 
00221 /**
00222   * @brief  Return current Watchdog Window Value (7 bits value)
00223   * @rmtoll CFR          W             LL_WWDG_GetWindow
00224   * @param  WWDGx WWDG Instance
00225   * @retval 7 bit Watchdog Window value
00226   */
00227 __STATIC_INLINE uint32_t LL_WWDG_GetWindow(WWDG_TypeDef *WWDGx)
00228 {
00229   return (READ_BIT(WWDGx->CFR, WWDG_CFR_W));
00230 }
00231 
00232 /**
00233   * @}
00234   */
00235 
00236 /** @defgroup WWDG_LL_EF_FLAG_Management FLAG_Management
00237   * @{
00238   */
00239 /**
00240   * @brief  Indicates if the WWDG Early Wakeup Interrupt Flag is set or not.
00241   * @note   This bit is set by hardware when the counter has reached the value 0x40.
00242   *         It must be cleared by software by writing 0.
00243   *         A write of 1 has no effect. This bit is also set if the interrupt is not enabled.
00244   * @rmtoll SR           EWIF          LL_WWDG_IsActiveFlag_EWKUP
00245   * @param  WWDGx WWDG Instance
00246   * @retval State of bit (1 or 0).
00247   */
00248 __STATIC_INLINE uint32_t LL_WWDG_IsActiveFlag_EWKUP(WWDG_TypeDef *WWDGx)
00249 {
00250   return ((READ_BIT(WWDGx->SR, WWDG_SR_EWIF) == (WWDG_SR_EWIF)) ? 1UL : 0UL);
00251 }
00252 
00253 /**
00254   * @brief  Clear WWDG Early Wakeup Interrupt Flag (EWIF)
00255   * @rmtoll SR           EWIF          LL_WWDG_ClearFlag_EWKUP
00256   * @param  WWDGx WWDG Instance
00257   * @retval None
00258   */
00259 __STATIC_INLINE void LL_WWDG_ClearFlag_EWKUP(WWDG_TypeDef *WWDGx)
00260 {
00261   WRITE_REG(WWDGx->SR, ~WWDG_SR_EWIF);
00262 }
00263 
00264 /**
00265   * @}
00266   */
00267 
00268 /** @defgroup WWDG_LL_EF_IT_Management IT_Management
00269   * @{
00270   */
00271 /**
00272   * @brief  Enable the Early Wakeup Interrupt.
00273   * @note   When set, an interrupt occurs whenever the counter reaches value 0x40.
00274   *         This interrupt is only cleared by hardware after a reset
00275   * @rmtoll CFR          EWI           LL_WWDG_EnableIT_EWKUP
00276   * @param  WWDGx WWDG Instance
00277   * @retval None
00278   */
00279 __STATIC_INLINE void LL_WWDG_EnableIT_EWKUP(WWDG_TypeDef *WWDGx)
00280 {
00281   SET_BIT(WWDGx->CFR, WWDG_CFR_EWI);
00282 }
00283 
00284 /**
00285   * @brief  Check if Early Wakeup Interrupt is enabled
00286   * @rmtoll CFR          EWI           LL_WWDG_IsEnabledIT_EWKUP
00287   * @param  WWDGx WWDG Instance
00288   * @retval State of bit (1 or 0).
00289   */
00290 __STATIC_INLINE uint32_t LL_WWDG_IsEnabledIT_EWKUP(WWDG_TypeDef *WWDGx)
00291 {
00292   return ((READ_BIT(WWDGx->CFR, WWDG_CFR_EWI) == (WWDG_CFR_EWI)) ? 1UL : 0UL);
00293 }
00294 
00295 /**
00296   * @}
00297   */
00298 
00299 /**
00300   * @}
00301   */
00302 
00303 /**
00304   * @}
00305   */
00306 
00307 #endif /* WWDG */
00308 
00309 /**
00310   * @}
00311   */
00312 
00313 #ifdef __cplusplus
00314 }
00315 #endif
00316 
00317 #endif /* STM32F1xx_LL_WWDG_H */
00318 
00319 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/