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.
 
 
 

332 lines
11 KiB

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