stm32g0xx_ll_wwdg.h 11 KB

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