You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stm32l1xx_ll_wwdg.h 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_ll_wwdg.h
  4. * @author MCD Application Team
  5. * @brief Header file of WWDG LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32L1xx_LL_WWDG_H
  21. #define STM32L1xx_LL_WWDG_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l1xx.h"
  27. /** @addtogroup STM32L1xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (WWDG)
  31. /** @defgroup WWDG_LL WWDG
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. /* Exported types ------------------------------------------------------------*/
  39. /* Exported constants --------------------------------------------------------*/
  40. /** @defgroup WWDG_LL_Exported_Constants WWDG Exported Constants
  41. * @{
  42. */
  43. /** @defgroup WWDG_LL_EC_IT IT Defines
  44. * @brief IT defines which can be used with LL_WWDG_ReadReg and LL_WWDG_WriteReg functions
  45. * @{
  46. */
  47. #define LL_WWDG_CFR_EWI WWDG_CFR_EWI
  48. /**
  49. * @}
  50. */
  51. /** @defgroup WWDG_LL_EC_PRESCALER PRESCALER
  52. * @{
  53. */
  54. #define LL_WWDG_PRESCALER_1 0x00000000u /*!< WWDG counter clock = (PCLK1/4096)/1 */
  55. #define LL_WWDG_PRESCALER_2 WWDG_CFR_WDGTB_0 /*!< WWDG counter clock = (PCLK1/4096)/2 */
  56. #define LL_WWDG_PRESCALER_4 WWDG_CFR_WDGTB_1 /*!< WWDG counter clock = (PCLK1/4096)/4 */
  57. #define LL_WWDG_PRESCALER_8 (WWDG_CFR_WDGTB_0 | WWDG_CFR_WDGTB_1) /*!< WWDG counter clock = (PCLK1/4096)/8 */
  58. /**
  59. * @}
  60. */
  61. /**
  62. * @}
  63. */
  64. /* Exported macro ------------------------------------------------------------*/
  65. /** @defgroup WWDG_LL_Exported_Macros WWDG Exported Macros
  66. * @{
  67. */
  68. /** @defgroup WWDG_LL_EM_WRITE_READ Common Write and read registers macros
  69. * @{
  70. */
  71. /**
  72. * @brief Write a value in WWDG register
  73. * @param __INSTANCE__ WWDG Instance
  74. * @param __REG__ Register to be written
  75. * @param __VALUE__ Value to be written in the register
  76. * @retval None
  77. */
  78. #define LL_WWDG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  79. /**
  80. * @brief Read a value in WWDG register
  81. * @param __INSTANCE__ WWDG Instance
  82. * @param __REG__ Register to be read
  83. * @retval Register value
  84. */
  85. #define LL_WWDG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  86. /**
  87. * @}
  88. */
  89. /**
  90. * @}
  91. */
  92. /* Exported functions --------------------------------------------------------*/
  93. /** @defgroup WWDG_LL_Exported_Functions WWDG Exported Functions
  94. * @{
  95. */
  96. /** @defgroup WWDG_LL_EF_Configuration Configuration
  97. * @{
  98. */
  99. /**
  100. * @brief Enable Window Watchdog. The watchdog is always disabled after a reset.
  101. * @note It is enabled by setting the WDGA bit in the WWDG_CR register,
  102. * then it cannot be disabled again except by a reset.
  103. * This bit is set by software and only cleared by hardware after a reset.
  104. * When WDGA = 1, the watchdog can generate a reset.
  105. * @rmtoll CR WDGA LL_WWDG_Enable
  106. * @param WWDGx WWDG Instance
  107. * @retval None
  108. */
  109. __STATIC_INLINE void LL_WWDG_Enable(WWDG_TypeDef *WWDGx)
  110. {
  111. SET_BIT(WWDGx->CR, WWDG_CR_WDGA);
  112. }
  113. /**
  114. * @brief Checks if Window Watchdog is enabled
  115. * @rmtoll CR WDGA LL_WWDG_IsEnabled
  116. * @param WWDGx WWDG Instance
  117. * @retval State of bit (1 or 0).
  118. */
  119. __STATIC_INLINE uint32_t LL_WWDG_IsEnabled(WWDG_TypeDef *WWDGx)
  120. {
  121. return ((READ_BIT(WWDGx->CR, WWDG_CR_WDGA) == (WWDG_CR_WDGA)) ? 1UL : 0UL);
  122. }
  123. /**
  124. * @brief Set the Watchdog counter value to provided value (7-bits T[6:0])
  125. * @note When writing to the WWDG_CR register, always write 1 in the MSB b6 to avoid generating an immediate reset
  126. * This counter is decremented every (4096 x 2expWDGTB) PCLK cycles
  127. * A reset is produced when it rolls over from 0x40 to 0x3F (bit T6 becomes cleared)
  128. * Setting the counter lower then 0x40 causes an immediate reset (if WWDG enabled)
  129. * @rmtoll CR T LL_WWDG_SetCounter
  130. * @param WWDGx WWDG Instance
  131. * @param Counter 0..0x7F (7 bit counter value)
  132. * @retval None
  133. */
  134. __STATIC_INLINE void LL_WWDG_SetCounter(WWDG_TypeDef *WWDGx, uint32_t Counter)
  135. {
  136. MODIFY_REG(WWDGx->CR, WWDG_CR_T, Counter);
  137. }
  138. /**
  139. * @brief Return current Watchdog Counter Value (7 bits counter value)
  140. * @rmtoll CR T LL_WWDG_GetCounter
  141. * @param WWDGx WWDG Instance
  142. * @retval 7 bit Watchdog Counter value
  143. */
  144. __STATIC_INLINE uint32_t LL_WWDG_GetCounter(WWDG_TypeDef *WWDGx)
  145. {
  146. return (READ_BIT(WWDGx->CR, WWDG_CR_T));
  147. }
  148. /**
  149. * @brief Set the time base of the prescaler (WDGTB).
  150. * @note Prescaler is used to apply ratio on PCLK clock, so that Watchdog counter
  151. * is decremented every (4096 x 2expWDGTB) PCLK cycles
  152. * @rmtoll CFR WDGTB LL_WWDG_SetPrescaler
  153. * @param WWDGx WWDG Instance
  154. * @param Prescaler This parameter can be one of the following values:
  155. * @arg @ref LL_WWDG_PRESCALER_1
  156. * @arg @ref LL_WWDG_PRESCALER_2
  157. * @arg @ref LL_WWDG_PRESCALER_4
  158. * @arg @ref LL_WWDG_PRESCALER_8
  159. * @retval None
  160. */
  161. __STATIC_INLINE void LL_WWDG_SetPrescaler(WWDG_TypeDef *WWDGx, uint32_t Prescaler)
  162. {
  163. MODIFY_REG(WWDGx->CFR, WWDG_CFR_WDGTB, Prescaler);
  164. }
  165. /**
  166. * @brief Return current Watchdog Prescaler Value
  167. * @rmtoll CFR WDGTB LL_WWDG_GetPrescaler
  168. * @param WWDGx WWDG Instance
  169. * @retval Returned value can be one of the following values:
  170. * @arg @ref LL_WWDG_PRESCALER_1
  171. * @arg @ref LL_WWDG_PRESCALER_2
  172. * @arg @ref LL_WWDG_PRESCALER_4
  173. * @arg @ref LL_WWDG_PRESCALER_8
  174. */
  175. __STATIC_INLINE uint32_t LL_WWDG_GetPrescaler(WWDG_TypeDef *WWDGx)
  176. {
  177. return (READ_BIT(WWDGx->CFR, WWDG_CFR_WDGTB));
  178. }
  179. /**
  180. * @brief Set the Watchdog Window value to be compared to the downcounter (7-bits W[6:0]).
  181. * @note This window value defines when write in the WWDG_CR register
  182. * to program Watchdog counter is allowed.
  183. * Watchdog counter value update must occur only when the counter value
  184. * is lower than the Watchdog window register value.
  185. * Otherwise, a MCU reset is generated if the 7-bit Watchdog counter value
  186. * (in the control register) is refreshed before the downcounter has reached
  187. * the watchdog window register value.
  188. * Physically is possible to set the Window lower then 0x40 but it is not recommended.
  189. * To generate an immediate reset, it is possible to set the Counter lower than 0x40.
  190. * @rmtoll CFR W LL_WWDG_SetWindow
  191. * @param WWDGx WWDG Instance
  192. * @param Window 0x00..0x7F (7 bit Window value)
  193. * @retval None
  194. */
  195. __STATIC_INLINE void LL_WWDG_SetWindow(WWDG_TypeDef *WWDGx, uint32_t Window)
  196. {
  197. MODIFY_REG(WWDGx->CFR, WWDG_CFR_W, Window);
  198. }
  199. /**
  200. * @brief Return current Watchdog Window Value (7 bits value)
  201. * @rmtoll CFR W LL_WWDG_GetWindow
  202. * @param WWDGx WWDG Instance
  203. * @retval 7 bit Watchdog Window value
  204. */
  205. __STATIC_INLINE uint32_t LL_WWDG_GetWindow(WWDG_TypeDef *WWDGx)
  206. {
  207. return (READ_BIT(WWDGx->CFR, WWDG_CFR_W));
  208. }
  209. /**
  210. * @}
  211. */
  212. /** @defgroup WWDG_LL_EF_FLAG_Management FLAG_Management
  213. * @{
  214. */
  215. /**
  216. * @brief Indicates if the WWDG Early Wakeup Interrupt Flag is set or not.
  217. * @note This bit is set by hardware when the counter has reached the value 0x40.
  218. * It must be cleared by software by writing 0.
  219. * A write of 1 has no effect. This bit is also set if the interrupt is not enabled.
  220. * @rmtoll SR EWIF LL_WWDG_IsActiveFlag_EWKUP
  221. * @param WWDGx WWDG Instance
  222. * @retval State of bit (1 or 0).
  223. */
  224. __STATIC_INLINE uint32_t LL_WWDG_IsActiveFlag_EWKUP(WWDG_TypeDef *WWDGx)
  225. {
  226. return ((READ_BIT(WWDGx->SR, WWDG_SR_EWIF) == (WWDG_SR_EWIF)) ? 1UL : 0UL);
  227. }
  228. /**
  229. * @brief Clear WWDG Early Wakeup Interrupt Flag (EWIF)
  230. * @rmtoll SR EWIF LL_WWDG_ClearFlag_EWKUP
  231. * @param WWDGx WWDG Instance
  232. * @retval None
  233. */
  234. __STATIC_INLINE void LL_WWDG_ClearFlag_EWKUP(WWDG_TypeDef *WWDGx)
  235. {
  236. WRITE_REG(WWDGx->SR, ~WWDG_SR_EWIF);
  237. }
  238. /**
  239. * @}
  240. */
  241. /** @defgroup WWDG_LL_EF_IT_Management IT_Management
  242. * @{
  243. */
  244. /**
  245. * @brief Enable the Early Wakeup Interrupt.
  246. * @note When set, an interrupt occurs whenever the counter reaches value 0x40.
  247. * This interrupt is only cleared by hardware after a reset
  248. * @rmtoll CFR EWI LL_WWDG_EnableIT_EWKUP
  249. * @param WWDGx WWDG Instance
  250. * @retval None
  251. */
  252. __STATIC_INLINE void LL_WWDG_EnableIT_EWKUP(WWDG_TypeDef *WWDGx)
  253. {
  254. SET_BIT(WWDGx->CFR, WWDG_CFR_EWI);
  255. }
  256. /**
  257. * @brief Check if Early Wakeup Interrupt is enabled
  258. * @rmtoll CFR EWI LL_WWDG_IsEnabledIT_EWKUP
  259. * @param WWDGx WWDG Instance
  260. * @retval State of bit (1 or 0).
  261. */
  262. __STATIC_INLINE uint32_t LL_WWDG_IsEnabledIT_EWKUP(WWDG_TypeDef *WWDGx)
  263. {
  264. return ((READ_BIT(WWDGx->CFR, WWDG_CFR_EWI) == (WWDG_CFR_EWI)) ? 1UL : 0UL);
  265. }
  266. /**
  267. * @}
  268. */
  269. /**
  270. * @}
  271. */
  272. /**
  273. * @}
  274. */
  275. #endif /* WWDG */
  276. /**
  277. * @}
  278. */
  279. #ifdef __cplusplus
  280. }
  281. #endif
  282. #endif /* __STM32L1xx_LL_WWDG_H */
  283. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/