stm32l4xx_hal_iwdg.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_iwdg.h
  4. * @author MCD Application Team
  5. * @brief Header file of IWDG HAL 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_HAL_IWDG_H
  37. #define __STM32L4xx_HAL_IWDG_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l4xx_hal_def.h"
  43. /** @addtogroup STM32L4xx_HAL_Driver
  44. * @{
  45. */
  46. /** @defgroup IWDG IWDG
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup IWDG_Exported_Types IWDG Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief IWDG Init structure definition
  55. */
  56. typedef struct
  57. {
  58. uint32_t Prescaler; /*!< Select the prescaler of the IWDG.
  59. This parameter can be a value of @ref IWDG_Prescaler */
  60. uint32_t Reload; /*!< Specifies the IWDG down-counter reload value.
  61. This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
  62. uint32_t Window; /*!< Specifies the window value to be compared to the down-counter.
  63. This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
  64. } IWDG_InitTypeDef;
  65. /**
  66. * @brief IWDG Handle Structure definition
  67. */
  68. typedef struct
  69. {
  70. IWDG_TypeDef *Instance; /*!< Register base address */
  71. IWDG_InitTypeDef Init; /*!< IWDG required parameters */
  72. }IWDG_HandleTypeDef;
  73. /**
  74. * @}
  75. */
  76. /* Exported constants --------------------------------------------------------*/
  77. /** @defgroup IWDG_Exported_Constants IWDG Exported Constants
  78. * @{
  79. */
  80. /** @defgroup IWDG_Prescaler IWDG Prescaler
  81. * @{
  82. */
  83. #define IWDG_PRESCALER_4 0x00000000u /*!< IWDG prescaler set to 4 */
  84. #define IWDG_PRESCALER_8 IWDG_PR_PR_0 /*!< IWDG prescaler set to 8 */
  85. #define IWDG_PRESCALER_16 IWDG_PR_PR_1 /*!< IWDG prescaler set to 16 */
  86. #define IWDG_PRESCALER_32 (IWDG_PR_PR_1 | IWDG_PR_PR_0) /*!< IWDG prescaler set to 32 */
  87. #define IWDG_PRESCALER_64 IWDG_PR_PR_2 /*!< IWDG prescaler set to 64 */
  88. #define IWDG_PRESCALER_128 (IWDG_PR_PR_2 | IWDG_PR_PR_0) /*!< IWDG prescaler set to 128 */
  89. #define IWDG_PRESCALER_256 (IWDG_PR_PR_2 | IWDG_PR_PR_1) /*!< IWDG prescaler set to 256 */
  90. /**
  91. * @}
  92. */
  93. /** @defgroup IWDG_Window_option IWDG Window option
  94. * @{
  95. */
  96. #define IWDG_WINDOW_DISABLE IWDG_WINR_WIN
  97. /**
  98. * @}
  99. */
  100. /**
  101. * @}
  102. */
  103. /* Exported macros -----------------------------------------------------------*/
  104. /** @defgroup IWDG_Exported_Macros IWDG Exported Macros
  105. * @{
  106. */
  107. /**
  108. * @brief Enable the IWDG peripheral.
  109. * @param __HANDLE__ IWDG handle
  110. * @retval None
  111. */
  112. #define __HAL_IWDG_START(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_ENABLE)
  113. /**
  114. * @brief Reload IWDG counter with value defined in the reload register
  115. * (write access to IWDG_PR, IWDG_RLR & IWDG_WINR registers disabled).
  116. * @param __HANDLE__ IWDG handle
  117. * @retval None
  118. */
  119. #define __HAL_IWDG_RELOAD_COUNTER(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_RELOAD)
  120. /**
  121. * @}
  122. */
  123. /* Exported functions --------------------------------------------------------*/
  124. /** @defgroup IWDG_Exported_Functions IWDG Exported Functions
  125. * @{
  126. */
  127. /** @defgroup IWDG_Exported_Functions_Group1 Initialization and Start functions
  128. * @{
  129. */
  130. /* Initialization/Start functions ********************************************/
  131. HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg);
  132. /**
  133. * @}
  134. */
  135. /** @defgroup IWDG_Exported_Functions_Group2 IO operation functions
  136. * @{
  137. */
  138. /* I/O operation functions ****************************************************/
  139. HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg);
  140. /**
  141. * @}
  142. */
  143. /**
  144. * @}
  145. */
  146. /* Private constants ---------------------------------------------------------*/
  147. /** @defgroup IWDG_Private_Constants IWDG Private Constants
  148. * @{
  149. */
  150. /**
  151. * @brief IWDG Key Register BitMask
  152. */
  153. #define IWDG_KEY_RELOAD 0x0000AAAAu /*!< IWDG Reload Counter Enable */
  154. #define IWDG_KEY_ENABLE 0x0000CCCCu /*!< IWDG Peripheral Enable */
  155. #define IWDG_KEY_WRITE_ACCESS_ENABLE 0x00005555u /*!< IWDG KR Write Access Enable */
  156. #define IWDG_KEY_WRITE_ACCESS_DISABLE 0x00000000u /*!< IWDG KR Write Access Disable */
  157. /**
  158. * @}
  159. */
  160. /* Private macros ------------------------------------------------------------*/
  161. /** @defgroup IWDG_Private_Macros IWDG Private Macros
  162. * @{
  163. */
  164. /**
  165. * @brief Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers.
  166. * @param __HANDLE__ IWDG handle
  167. * @retval None
  168. */
  169. #define IWDG_ENABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_ENABLE)
  170. /**
  171. * @brief Disable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers.
  172. * @param __HANDLE__ IWDG handle
  173. * @retval None
  174. */
  175. #define IWDG_DISABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_DISABLE)
  176. /**
  177. * @brief Check IWDG prescaler value.
  178. * @param __PRESCALER__ IWDG prescaler value
  179. * @retval None
  180. */
  181. #define IS_IWDG_PRESCALER(__PRESCALER__) (((__PRESCALER__) == IWDG_PRESCALER_4) || \
  182. ((__PRESCALER__) == IWDG_PRESCALER_8) || \
  183. ((__PRESCALER__) == IWDG_PRESCALER_16) || \
  184. ((__PRESCALER__) == IWDG_PRESCALER_32) || \
  185. ((__PRESCALER__) == IWDG_PRESCALER_64) || \
  186. ((__PRESCALER__) == IWDG_PRESCALER_128)|| \
  187. ((__PRESCALER__) == IWDG_PRESCALER_256))
  188. /**
  189. * @brief Check IWDG reload value.
  190. * @param __RELOAD__ IWDG reload value
  191. * @retval None
  192. */
  193. #define IS_IWDG_RELOAD(__RELOAD__) ((__RELOAD__) <= IWDG_RLR_RL)
  194. /**
  195. * @brief Check IWDG window value.
  196. * @param __WINDOW__ IWDG window value
  197. * @retval None
  198. */
  199. #define IS_IWDG_WINDOW(__WINDOW__) ((__WINDOW__) <= IWDG_WINR_WIN)
  200. /**
  201. * @}
  202. */
  203. /**
  204. * @}
  205. */
  206. /**
  207. * @}
  208. */
  209. #ifdef __cplusplus
  210. }
  211. #endif
  212. #endif /* __STM32L4xx_HAL_IWDG_H */
  213. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/