stm32l4xx_ll_iwdg.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_iwdg.h
  4. * @author MCD Application Team
  5. * @brief Header file of IWDG LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32L4xx_LL_IWDG_H
  37. #define __STM32L4xx_LL_IWDG_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l4xx.h"
  43. /** @addtogroup STM32L4xx_LL_Driver
  44. * @{
  45. */
  46. #if defined(IWDG)
  47. /** @defgroup IWDG_LL IWDG
  48. * @{
  49. */
  50. /* Private types -------------------------------------------------------------*/
  51. /* Private variables ---------------------------------------------------------*/
  52. /* Private constants ---------------------------------------------------------*/
  53. /** @defgroup IWDG_LL_Private_Constants IWDG Private Constants
  54. * @{
  55. */
  56. #define LL_IWDG_KEY_RELOAD 0x0000AAAAU /*!< IWDG Reload Counter Enable */
  57. #define LL_IWDG_KEY_ENABLE 0x0000CCCCU /*!< IWDG Peripheral Enable */
  58. #define LL_IWDG_KEY_WR_ACCESS_ENABLE 0x00005555U /*!< IWDG KR Write Access Enable */
  59. #define LL_IWDG_KEY_WR_ACCESS_DISABLE 0x00000000U /*!< IWDG KR Write Access Disable */
  60. /**
  61. * @}
  62. */
  63. /* Private macros ------------------------------------------------------------*/
  64. /* Exported types ------------------------------------------------------------*/
  65. /* Exported constants --------------------------------------------------------*/
  66. /** @defgroup IWDG_LL_Exported_Constants IWDG Exported Constants
  67. * @{
  68. */
  69. /** @defgroup IWDG_LL_EC_GET_FLAG Get Flags Defines
  70. * @brief Flags defines which can be used with LL_IWDG_ReadReg function
  71. * @{
  72. */
  73. #define LL_IWDG_SR_PVU IWDG_SR_PVU /*!< Watchdog prescaler value update */
  74. #define LL_IWDG_SR_RVU IWDG_SR_RVU /*!< Watchdog counter reload value update */
  75. #define LL_IWDG_SR_WVU IWDG_SR_WVU /*!< Watchdog counter window value update */
  76. /**
  77. * @}
  78. */
  79. /** @defgroup IWDG_LL_EC_PRESCALER Prescaler Divider
  80. * @{
  81. */
  82. #define LL_IWDG_PRESCALER_4 0x00000000U /*!< Divider by 4 */
  83. #define LL_IWDG_PRESCALER_8 (IWDG_PR_PR_0) /*!< Divider by 8 */
  84. #define LL_IWDG_PRESCALER_16 (IWDG_PR_PR_1) /*!< Divider by 16 */
  85. #define LL_IWDG_PRESCALER_32 (IWDG_PR_PR_1 | IWDG_PR_PR_0) /*!< Divider by 32 */
  86. #define LL_IWDG_PRESCALER_64 (IWDG_PR_PR_2) /*!< Divider by 64 */
  87. #define LL_IWDG_PRESCALER_128 (IWDG_PR_PR_2 | IWDG_PR_PR_0) /*!< Divider by 128 */
  88. #define LL_IWDG_PRESCALER_256 (IWDG_PR_PR_2 | IWDG_PR_PR_1) /*!< Divider by 256 */
  89. /**
  90. * @}
  91. */
  92. /**
  93. * @}
  94. */
  95. /* Exported macro ------------------------------------------------------------*/
  96. /** @defgroup IWDG_LL_Exported_Macros IWDG Exported Macros
  97. * @{
  98. */
  99. /** @defgroup IWDG_LL_EM_WRITE_READ Common Write and read registers Macros
  100. * @{
  101. */
  102. /**
  103. * @brief Write a value in IWDG register
  104. * @param __INSTANCE__ IWDG Instance
  105. * @param __REG__ Register to be written
  106. * @param __VALUE__ Value to be written in the register
  107. * @retval None
  108. */
  109. #define LL_IWDG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  110. /**
  111. * @brief Read a value in IWDG register
  112. * @param __INSTANCE__ IWDG Instance
  113. * @param __REG__ Register to be read
  114. * @retval Register value
  115. */
  116. #define LL_IWDG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  117. /**
  118. * @}
  119. */
  120. /**
  121. * @}
  122. */
  123. /* Exported functions --------------------------------------------------------*/
  124. /** @defgroup IWDG_LL_Exported_Functions IWDG Exported Functions
  125. * @{
  126. */
  127. /** @defgroup IWDG_LL_EF_Configuration Configuration
  128. * @{
  129. */
  130. /**
  131. * @brief Start the Independent Watchdog
  132. * @note Except if the hardware watchdog option is selected
  133. * @rmtoll KR KEY LL_IWDG_Enable
  134. * @param IWDGx IWDG Instance
  135. * @retval None
  136. */
  137. __STATIC_INLINE void LL_IWDG_Enable(IWDG_TypeDef *IWDGx)
  138. {
  139. WRITE_REG(IWDG->KR, LL_IWDG_KEY_ENABLE);
  140. }
  141. /**
  142. * @brief Reloads IWDG counter with value defined in the reload register
  143. * @rmtoll KR KEY LL_IWDG_ReloadCounter
  144. * @param IWDGx IWDG Instance
  145. * @retval None
  146. */
  147. __STATIC_INLINE void LL_IWDG_ReloadCounter(IWDG_TypeDef *IWDGx)
  148. {
  149. WRITE_REG(IWDG->KR, LL_IWDG_KEY_RELOAD);
  150. }
  151. /**
  152. * @brief Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers
  153. * @rmtoll KR KEY LL_IWDG_EnableWriteAccess
  154. * @param IWDGx IWDG Instance
  155. * @retval None
  156. */
  157. __STATIC_INLINE void LL_IWDG_EnableWriteAccess(IWDG_TypeDef *IWDGx)
  158. {
  159. WRITE_REG(IWDG->KR, LL_IWDG_KEY_WR_ACCESS_ENABLE);
  160. }
  161. /**
  162. * @brief Disable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers
  163. * @rmtoll KR KEY LL_IWDG_DisableWriteAccess
  164. * @param IWDGx IWDG Instance
  165. * @retval None
  166. */
  167. __STATIC_INLINE void LL_IWDG_DisableWriteAccess(IWDG_TypeDef *IWDGx)
  168. {
  169. WRITE_REG(IWDG->KR, LL_IWDG_KEY_WR_ACCESS_DISABLE);
  170. }
  171. /**
  172. * @brief Select the prescaler of the IWDG
  173. * @rmtoll PR PR LL_IWDG_SetPrescaler
  174. * @param IWDGx IWDG Instance
  175. * @param Prescaler This parameter can be one of the following values:
  176. * @arg @ref LL_IWDG_PRESCALER_4
  177. * @arg @ref LL_IWDG_PRESCALER_8
  178. * @arg @ref LL_IWDG_PRESCALER_16
  179. * @arg @ref LL_IWDG_PRESCALER_32
  180. * @arg @ref LL_IWDG_PRESCALER_64
  181. * @arg @ref LL_IWDG_PRESCALER_128
  182. * @arg @ref LL_IWDG_PRESCALER_256
  183. * @retval None
  184. */
  185. __STATIC_INLINE void LL_IWDG_SetPrescaler(IWDG_TypeDef *IWDGx, uint32_t Prescaler)
  186. {
  187. WRITE_REG(IWDGx->PR, IWDG_PR_PR & Prescaler);
  188. }
  189. /**
  190. * @brief Get the selected prescaler of the IWDG
  191. * @rmtoll PR PR LL_IWDG_GetPrescaler
  192. * @param IWDGx IWDG Instance
  193. * @retval Returned value can be one of the following values:
  194. * @arg @ref LL_IWDG_PRESCALER_4
  195. * @arg @ref LL_IWDG_PRESCALER_8
  196. * @arg @ref LL_IWDG_PRESCALER_16
  197. * @arg @ref LL_IWDG_PRESCALER_32
  198. * @arg @ref LL_IWDG_PRESCALER_64
  199. * @arg @ref LL_IWDG_PRESCALER_128
  200. * @arg @ref LL_IWDG_PRESCALER_256
  201. */
  202. __STATIC_INLINE uint32_t LL_IWDG_GetPrescaler(IWDG_TypeDef *IWDGx)
  203. {
  204. return (uint32_t)(READ_REG(IWDGx->PR));
  205. }
  206. /**
  207. * @brief Specify the IWDG down-counter reload value
  208. * @rmtoll RLR RL LL_IWDG_SetReloadCounter
  209. * @param IWDGx IWDG Instance
  210. * @param Counter Value between Min_Data=0 and Max_Data=0x0FFF
  211. * @retval None
  212. */
  213. __STATIC_INLINE void LL_IWDG_SetReloadCounter(IWDG_TypeDef *IWDGx, uint32_t Counter)
  214. {
  215. WRITE_REG(IWDGx->RLR, IWDG_RLR_RL & Counter);
  216. }
  217. /**
  218. * @brief Get the specified IWDG down-counter reload value
  219. * @rmtoll RLR RL LL_IWDG_GetReloadCounter
  220. * @param IWDGx IWDG Instance
  221. * @retval Value between Min_Data=0 and Max_Data=0x0FFF
  222. */
  223. __STATIC_INLINE uint32_t LL_IWDG_GetReloadCounter(IWDG_TypeDef *IWDGx)
  224. {
  225. return (uint32_t)(READ_REG(IWDGx->RLR));
  226. }
  227. /**
  228. * @brief Specify high limit of the window value to be compared to the down-counter.
  229. * @rmtoll WINR WIN LL_IWDG_SetWindow
  230. * @param IWDGx IWDG Instance
  231. * @param Window Value between Min_Data=0 and Max_Data=0x0FFF
  232. * @retval None
  233. */
  234. __STATIC_INLINE void LL_IWDG_SetWindow(IWDG_TypeDef *IWDGx, uint32_t Window)
  235. {
  236. WRITE_REG(IWDGx->WINR, IWDG_WINR_WIN & Window);
  237. }
  238. /**
  239. * @brief Get the high limit of the window value specified.
  240. * @rmtoll WINR WIN LL_IWDG_GetWindow
  241. * @param IWDGx IWDG Instance
  242. * @retval Value between Min_Data=0 and Max_Data=0x0FFF
  243. */
  244. __STATIC_INLINE uint32_t LL_IWDG_GetWindow(IWDG_TypeDef *IWDGx)
  245. {
  246. return (uint32_t)(READ_REG(IWDGx->WINR));
  247. }
  248. /**
  249. * @}
  250. */
  251. /** @defgroup IWDG_LL_EF_FLAG_Management FLAG_Management
  252. * @{
  253. */
  254. /**
  255. * @brief Check if flag Prescaler Value Update is set or not
  256. * @rmtoll SR PVU LL_IWDG_IsActiveFlag_PVU
  257. * @param IWDGx IWDG Instance
  258. * @retval State of bit (1 or 0).
  259. */
  260. __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_PVU(IWDG_TypeDef *IWDGx)
  261. {
  262. return (READ_BIT(IWDGx->SR, IWDG_SR_PVU) == (IWDG_SR_PVU));
  263. }
  264. /**
  265. * @brief Check if flag Reload Value Update is set or not
  266. * @rmtoll SR RVU LL_IWDG_IsActiveFlag_RVU
  267. * @param IWDGx IWDG Instance
  268. * @retval State of bit (1 or 0).
  269. */
  270. __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_RVU(IWDG_TypeDef *IWDGx)
  271. {
  272. return (READ_BIT(IWDGx->SR, IWDG_SR_RVU) == (IWDG_SR_RVU));
  273. }
  274. /**
  275. * @brief Check if flag Window Value Update is set or not
  276. * @rmtoll SR WVU LL_IWDG_IsActiveFlag_WVU
  277. * @param IWDGx IWDG Instance
  278. * @retval State of bit (1 or 0).
  279. */
  280. __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_WVU(IWDG_TypeDef *IWDGx)
  281. {
  282. return (READ_BIT(IWDGx->SR, IWDG_SR_WVU) == (IWDG_SR_WVU));
  283. }
  284. /**
  285. * @brief Check if all flags Prescaler, Reload & Window Value Update are reset or not
  286. * @rmtoll SR PVU LL_IWDG_IsReady\n
  287. * SR WVU LL_IWDG_IsReady\n
  288. * SR RVU LL_IWDG_IsReady
  289. * @param IWDGx IWDG Instance
  290. * @retval State of bits (1 or 0).
  291. */
  292. __STATIC_INLINE uint32_t LL_IWDG_IsReady(IWDG_TypeDef *IWDGx)
  293. {
  294. return (READ_BIT(IWDGx->SR, IWDG_SR_PVU | IWDG_SR_RVU | IWDG_SR_WVU) == 0U);
  295. }
  296. /**
  297. * @}
  298. */
  299. /**
  300. * @}
  301. */
  302. /**
  303. * @}
  304. */
  305. #endif /* IWDG) */
  306. /**
  307. * @}
  308. */
  309. #ifdef __cplusplus
  310. }
  311. #endif
  312. #endif /* __STM32L4xx_LL_IWDG_H */
  313. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/