stm32h7xx_ll_iwdg.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_ll_iwdg.h
  4. * @author MCD Application Team
  5. * @brief Header file of IWDG LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 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 STM32H7xx_LL_IWDG_H
  20. #define STM32H7xx_LL_IWDG_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32h7xx.h"
  26. /** @addtogroup STM32H7xx_LL_Driver
  27. * @{
  28. */
  29. #if defined(IWDG1) || defined(IWDG2)
  30. /** @defgroup IWDG_LL IWDG
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private constants ---------------------------------------------------------*/
  36. /** @defgroup IWDG_LL_Private_Constants IWDG Private Constants
  37. * @{
  38. */
  39. #define LL_IWDG_KEY_RELOAD 0x0000AAAAU /*!< IWDG Reload Counter Enable */
  40. #define LL_IWDG_KEY_ENABLE 0x0000CCCCU /*!< IWDG Peripheral Enable */
  41. #define LL_IWDG_KEY_WR_ACCESS_ENABLE 0x00005555U /*!< IWDG KR Write Access Enable */
  42. #define LL_IWDG_KEY_WR_ACCESS_DISABLE 0x00000000U /*!< IWDG KR Write Access Disable */
  43. /**
  44. * @}
  45. */
  46. /* Private macros ------------------------------------------------------------*/
  47. /* Exported types ------------------------------------------------------------*/
  48. /* Exported constants --------------------------------------------------------*/
  49. /** @defgroup IWDG_LL_Exported_Constants IWDG Exported Constants
  50. * @{
  51. */
  52. /** @defgroup IWDG_LL_EC_GET_FLAG Get Flags Defines
  53. * @brief Flags defines which can be used with LL_IWDG_ReadReg function
  54. * @{
  55. */
  56. #define LL_IWDG_SR_PVU IWDG_SR_PVU /*!< Watchdog prescaler value update */
  57. #define LL_IWDG_SR_RVU IWDG_SR_RVU /*!< Watchdog counter reload value update */
  58. #define LL_IWDG_SR_WVU IWDG_SR_WVU /*!< Watchdog counter window value update */
  59. /**
  60. * @}
  61. */
  62. /** @defgroup IWDG_LL_EC_PRESCALER Prescaler Divider
  63. * @{
  64. */
  65. #define LL_IWDG_PRESCALER_4 0x00000000U /*!< Divider by 4 */
  66. #define LL_IWDG_PRESCALER_8 (IWDG_PR_PR_0) /*!< Divider by 8 */
  67. #define LL_IWDG_PRESCALER_16 (IWDG_PR_PR_1) /*!< Divider by 16 */
  68. #define LL_IWDG_PRESCALER_32 (IWDG_PR_PR_1 | IWDG_PR_PR_0) /*!< Divider by 32 */
  69. #define LL_IWDG_PRESCALER_64 (IWDG_PR_PR_2) /*!< Divider by 64 */
  70. #define LL_IWDG_PRESCALER_128 (IWDG_PR_PR_2 | IWDG_PR_PR_0) /*!< Divider by 128 */
  71. #define LL_IWDG_PRESCALER_256 (IWDG_PR_PR_2 | IWDG_PR_PR_1) /*!< Divider by 256 */
  72. /**
  73. * @}
  74. */
  75. /**
  76. * @}
  77. */
  78. /* Exported macro ------------------------------------------------------------*/
  79. /** @defgroup IWDG_LL_Exported_Macros IWDG Exported Macros
  80. * @{
  81. */
  82. /** @defgroup IWDG_LL_EM_WRITE_READ Common Write and read registers Macros
  83. * @{
  84. */
  85. /**
  86. * @brief Write a value in IWDG register
  87. * @param __INSTANCE__ IWDG Instance
  88. * @param __REG__ Register to be written
  89. * @param __VALUE__ Value to be written in the register
  90. * @retval None
  91. */
  92. #define LL_IWDG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  93. /**
  94. * @brief Read a value in IWDG register
  95. * @param __INSTANCE__ IWDG Instance
  96. * @param __REG__ Register to be read
  97. * @retval Register value
  98. */
  99. #define LL_IWDG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  100. /**
  101. * @}
  102. */
  103. /**
  104. * @}
  105. */
  106. /* Exported functions --------------------------------------------------------*/
  107. /** @defgroup IWDG_LL_Exported_Functions IWDG Exported Functions
  108. * @{
  109. */
  110. /** @defgroup IWDG_LL_EF_Configuration Configuration
  111. * @{
  112. */
  113. /**
  114. * @brief Start the Independent Watchdog
  115. * @note Except if the hardware watchdog option is selected
  116. * @rmtoll KR KEY LL_IWDG_Enable
  117. * @param IWDGx IWDG Instance
  118. * @retval None
  119. */
  120. __STATIC_INLINE void LL_IWDG_Enable(IWDG_TypeDef *IWDGx)
  121. {
  122. WRITE_REG(IWDGx->KR, LL_IWDG_KEY_ENABLE);
  123. }
  124. /**
  125. * @brief Reloads IWDG counter with value defined in the reload register
  126. * @rmtoll KR KEY LL_IWDG_ReloadCounter
  127. * @param IWDGx IWDG Instance
  128. * @retval None
  129. */
  130. __STATIC_INLINE void LL_IWDG_ReloadCounter(IWDG_TypeDef *IWDGx)
  131. {
  132. WRITE_REG(IWDGx->KR, LL_IWDG_KEY_RELOAD);
  133. }
  134. /**
  135. * @brief Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers
  136. * @rmtoll KR KEY LL_IWDG_EnableWriteAccess
  137. * @param IWDGx IWDG Instance
  138. * @retval None
  139. */
  140. __STATIC_INLINE void LL_IWDG_EnableWriteAccess(IWDG_TypeDef *IWDGx)
  141. {
  142. WRITE_REG(IWDGx->KR, LL_IWDG_KEY_WR_ACCESS_ENABLE);
  143. }
  144. /**
  145. * @brief Disable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers
  146. * @rmtoll KR KEY LL_IWDG_DisableWriteAccess
  147. * @param IWDGx IWDG Instance
  148. * @retval None
  149. */
  150. __STATIC_INLINE void LL_IWDG_DisableWriteAccess(IWDG_TypeDef *IWDGx)
  151. {
  152. WRITE_REG(IWDGx->KR, LL_IWDG_KEY_WR_ACCESS_DISABLE);
  153. }
  154. /**
  155. * @brief Select the prescaler of the IWDG
  156. * @rmtoll PR PR LL_IWDG_SetPrescaler
  157. * @param IWDGx IWDG Instance
  158. * @param Prescaler This parameter can be one of the following values:
  159. * @arg @ref LL_IWDG_PRESCALER_4
  160. * @arg @ref LL_IWDG_PRESCALER_8
  161. * @arg @ref LL_IWDG_PRESCALER_16
  162. * @arg @ref LL_IWDG_PRESCALER_32
  163. * @arg @ref LL_IWDG_PRESCALER_64
  164. * @arg @ref LL_IWDG_PRESCALER_128
  165. * @arg @ref LL_IWDG_PRESCALER_256
  166. * @retval None
  167. */
  168. __STATIC_INLINE void LL_IWDG_SetPrescaler(IWDG_TypeDef *IWDGx, uint32_t Prescaler)
  169. {
  170. WRITE_REG(IWDGx->PR, IWDG_PR_PR & Prescaler);
  171. }
  172. /**
  173. * @brief Get the selected prescaler of the IWDG
  174. * @rmtoll PR PR LL_IWDG_GetPrescaler
  175. * @param IWDGx IWDG Instance
  176. * @retval Returned value can be one of the following values:
  177. * @arg @ref LL_IWDG_PRESCALER_4
  178. * @arg @ref LL_IWDG_PRESCALER_8
  179. * @arg @ref LL_IWDG_PRESCALER_16
  180. * @arg @ref LL_IWDG_PRESCALER_32
  181. * @arg @ref LL_IWDG_PRESCALER_64
  182. * @arg @ref LL_IWDG_PRESCALER_128
  183. * @arg @ref LL_IWDG_PRESCALER_256
  184. */
  185. __STATIC_INLINE uint32_t LL_IWDG_GetPrescaler(IWDG_TypeDef *IWDGx)
  186. {
  187. return (READ_REG(IWDGx->PR));
  188. }
  189. /**
  190. * @brief Specify the IWDG down-counter reload value
  191. * @rmtoll RLR RL LL_IWDG_SetReloadCounter
  192. * @param IWDGx IWDG Instance
  193. * @param Counter Value between Min_Data=0 and Max_Data=0x0FFF
  194. * @retval None
  195. */
  196. __STATIC_INLINE void LL_IWDG_SetReloadCounter(IWDG_TypeDef *IWDGx, uint32_t Counter)
  197. {
  198. WRITE_REG(IWDGx->RLR, IWDG_RLR_RL & Counter);
  199. }
  200. /**
  201. * @brief Get the specified IWDG down-counter reload value
  202. * @rmtoll RLR RL LL_IWDG_GetReloadCounter
  203. * @param IWDGx IWDG Instance
  204. * @retval Value between Min_Data=0 and Max_Data=0x0FFF
  205. */
  206. __STATIC_INLINE uint32_t LL_IWDG_GetReloadCounter(IWDG_TypeDef *IWDGx)
  207. {
  208. return (READ_REG(IWDGx->RLR));
  209. }
  210. /**
  211. * @brief Specify high limit of the window value to be compared to the down-counter.
  212. * @rmtoll WINR WIN LL_IWDG_SetWindow
  213. * @param IWDGx IWDG Instance
  214. * @param Window Value between Min_Data=0 and Max_Data=0x0FFF
  215. * @retval None
  216. */
  217. __STATIC_INLINE void LL_IWDG_SetWindow(IWDG_TypeDef *IWDGx, uint32_t Window)
  218. {
  219. WRITE_REG(IWDGx->WINR, IWDG_WINR_WIN & Window);
  220. }
  221. /**
  222. * @brief Get the high limit of the window value specified.
  223. * @rmtoll WINR WIN LL_IWDG_GetWindow
  224. * @param IWDGx IWDG Instance
  225. * @retval Value between Min_Data=0 and Max_Data=0x0FFF
  226. */
  227. __STATIC_INLINE uint32_t LL_IWDG_GetWindow(IWDG_TypeDef *IWDGx)
  228. {
  229. return (READ_REG(IWDGx->WINR));
  230. }
  231. /**
  232. * @}
  233. */
  234. /** @defgroup IWDG_LL_EF_FLAG_Management FLAG_Management
  235. * @{
  236. */
  237. /**
  238. * @brief Check if flag Prescaler Value Update is set or not
  239. * @rmtoll SR PVU LL_IWDG_IsActiveFlag_PVU
  240. * @param IWDGx IWDG Instance
  241. * @retval State of bit (1 or 0).
  242. */
  243. __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_PVU(IWDG_TypeDef *IWDGx)
  244. {
  245. return ((READ_BIT(IWDGx->SR, IWDG_SR_PVU) == (IWDG_SR_PVU)) ? 1UL : 0UL);
  246. }
  247. /**
  248. * @brief Check if flag Reload Value Update is set or not
  249. * @rmtoll SR RVU LL_IWDG_IsActiveFlag_RVU
  250. * @param IWDGx IWDG Instance
  251. * @retval State of bit (1 or 0).
  252. */
  253. __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_RVU(IWDG_TypeDef *IWDGx)
  254. {
  255. return ((READ_BIT(IWDGx->SR, IWDG_SR_RVU) == (IWDG_SR_RVU)) ? 1UL : 0UL);
  256. }
  257. /**
  258. * @brief Check if flag Window Value Update is set or not
  259. * @rmtoll SR WVU LL_IWDG_IsActiveFlag_WVU
  260. * @param IWDGx IWDG Instance
  261. * @retval State of bit (1 or 0).
  262. */
  263. __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_WVU(IWDG_TypeDef *IWDGx)
  264. {
  265. return ((READ_BIT(IWDGx->SR, IWDG_SR_WVU) == (IWDG_SR_WVU)) ? 1UL : 0UL);
  266. }
  267. /**
  268. * @brief Check if all flags Prescaler, Reload & Window Value Update are reset or not
  269. * @rmtoll SR PVU LL_IWDG_IsReady\n
  270. * SR RVU LL_IWDG_IsReady\n
  271. * SR WVU LL_IWDG_IsReady
  272. * @param IWDGx IWDG Instance
  273. * @retval State of bits (1 or 0).
  274. */
  275. __STATIC_INLINE uint32_t LL_IWDG_IsReady(IWDG_TypeDef *IWDGx)
  276. {
  277. return ((READ_BIT(IWDGx->SR, IWDG_SR_PVU | IWDG_SR_RVU | IWDG_SR_WVU) == 0U) ? 1UL : 0UL);
  278. }
  279. /**
  280. * @}
  281. */
  282. /**
  283. * @}
  284. */
  285. /**
  286. * @}
  287. */
  288. #endif /* IWDG1 || IWDG2 */
  289. /**
  290. * @}
  291. */
  292. #ifdef __cplusplus
  293. }
  294. #endif
  295. #endif /* STM32H7xx_LL_IWDG_H */