stm32f7xx_hal_iwdg.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_iwdg.h
  4. * @author MCD Application Team
  5. * @version V1.0.1
  6. * @date 25-June-2015
  7. * @brief Header file of IWDG HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F7xx_HAL_IWDG_H
  39. #define __STM32F7xx_HAL_IWDG_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. /** @addtogroup STM32F7xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup IWDG
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup IWDG_Exported_Types IWDG Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief IWDG HAL State Structure definition
  57. */
  58. typedef enum
  59. {
  60. HAL_IWDG_STATE_RESET = 0x00, /*!< IWDG not yet initialized or disabled */
  61. HAL_IWDG_STATE_READY = 0x01, /*!< IWDG initialized and ready for use */
  62. HAL_IWDG_STATE_BUSY = 0x02, /*!< IWDG internal process is ongoing */
  63. HAL_IWDG_STATE_TIMEOUT = 0x03, /*!< IWDG timeout state */
  64. HAL_IWDG_STATE_ERROR = 0x04 /*!< IWDG error state */
  65. }HAL_IWDG_StateTypeDef;
  66. /**
  67. * @brief IWDG Init structure definition
  68. */
  69. typedef struct
  70. {
  71. uint32_t Prescaler; /*!< Select the prescaler of the IWDG.
  72. This parameter can be a value of @ref IWDG_Prescaler */
  73. uint32_t Reload; /*!< Specifies the IWDG down-counter reload value.
  74. This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
  75. uint32_t Window; /*!< Specifies the window value to be compared to the down-counter.
  76. This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
  77. } IWDG_InitTypeDef;
  78. /**
  79. * @brief IWDG Handle Structure definition
  80. */
  81. typedef struct
  82. {
  83. IWDG_TypeDef *Instance; /*!< Register base address */
  84. IWDG_InitTypeDef Init; /*!< IWDG required parameters */
  85. HAL_LockTypeDef Lock; /*!< IWDG Locking object */
  86. __IO HAL_IWDG_StateTypeDef State; /*!< IWDG communication state */
  87. }IWDG_HandleTypeDef;
  88. /**
  89. * @}
  90. */
  91. /* Exported constants --------------------------------------------------------*/
  92. /** @defgroup IWDG_Exported_Constants IWDG Exported Constants
  93. * @{
  94. */
  95. /** @defgroup IWDG_Prescaler IWDG Prescaler
  96. * @{
  97. */
  98. #define IWDG_PRESCALER_4 ((uint8_t)0x00) /*!< IWDG prescaler set to 4 */
  99. #define IWDG_PRESCALER_8 ((uint8_t)(IWDG_PR_PR_0)) /*!< IWDG prescaler set to 8 */
  100. #define IWDG_PRESCALER_16 ((uint8_t)(IWDG_PR_PR_1)) /*!< IWDG prescaler set to 16 */
  101. #define IWDG_PRESCALER_32 ((uint8_t)(IWDG_PR_PR_1 | IWDG_PR_PR_0)) /*!< IWDG prescaler set to 32 */
  102. #define IWDG_PRESCALER_64 ((uint8_t)(IWDG_PR_PR_2)) /*!< IWDG prescaler set to 64 */
  103. #define IWDG_PRESCALER_128 ((uint8_t)(IWDG_PR_PR_2 | IWDG_PR_PR_0)) /*!< IWDG prescaler set to 128 */
  104. #define IWDG_PRESCALER_256 ((uint8_t)(IWDG_PR_PR_2 | IWDG_PR_PR_1)) /*!< IWDG prescaler set to 256 */
  105. /**
  106. * @}
  107. */
  108. /** @defgroup IWDG_Window IWDG Window
  109. * @{
  110. */
  111. #define IWDG_WINDOW_DISABLE ((uint32_t)0x00000FFF)
  112. /**
  113. * @}
  114. */
  115. /**
  116. * @}
  117. */
  118. /* Exported macros -----------------------------------------------------------*/
  119. /** @defgroup IWDG_Exported_Macros IWDG Exported Macros
  120. * @{
  121. */
  122. /** @brief Reset IWDG handle state
  123. * @param __HANDLE__: IWDG handle.
  124. * @retval None
  125. */
  126. #define __HAL_IWDG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_IWDG_STATE_RESET)
  127. /**
  128. * @brief Enables the IWDG peripheral.
  129. * @param __HANDLE__: IWDG handle
  130. * @retval None
  131. */
  132. #define __HAL_IWDG_START(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_ENABLE)
  133. /**
  134. * @brief Reloads IWDG counter with value defined in the reload register
  135. * (write access to IWDG_PR and IWDG_RLR registers disabled).
  136. * @param __HANDLE__: IWDG handle
  137. * @retval None
  138. */
  139. #define __HAL_IWDG_RELOAD_COUNTER(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_RELOAD)
  140. /**
  141. * @brief Gets the selected IWDG's flag status.
  142. * @param __HANDLE__: IWDG handle
  143. * @param __FLAG__: specifies the flag to check.
  144. * This parameter can be one of the following values:
  145. * @arg IWDG_FLAG_PVU: Watchdog counter reload value update flag
  146. * @arg IWDG_FLAG_RVU: Watchdog counter prescaler value flag
  147. * @arg IWDG_FLAG_WVU: Watchdog counter window value flag
  148. * @retval The new state of __FLAG__ (TRUE or FALSE) .
  149. */
  150. #define __HAL_IWDG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
  151. /**
  152. * @}
  153. */
  154. /* Exported functions --------------------------------------------------------*/
  155. /** @addtogroup IWDG_Exported_Functions
  156. * @{
  157. */
  158. /** @addtogroup IWDG_Exported_Functions_Group1
  159. * @{
  160. */
  161. /* Initialization/de-initialization functions ********************************/
  162. HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg);
  163. void HAL_IWDG_MspInit(IWDG_HandleTypeDef *hiwdg);
  164. /**
  165. * @}
  166. */
  167. /** @addtogroup IWDG_Exported_Functions_Group2
  168. * @{
  169. */
  170. /* I/O operation functions ****************************************************/
  171. HAL_StatusTypeDef HAL_IWDG_Start(IWDG_HandleTypeDef *hiwdg);
  172. HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg);
  173. /**
  174. * @}
  175. */
  176. /** @addtogroup IWDG_Exported_Functions_Group3
  177. * @{
  178. */
  179. /* Peripheral State functions ************************************************/
  180. HAL_IWDG_StateTypeDef HAL_IWDG_GetState(IWDG_HandleTypeDef *hiwdg);
  181. /**
  182. * @}
  183. */
  184. /**
  185. * @}
  186. */
  187. /* Private constants ---------------------------------------------------------*/
  188. /** @addtogroup IWDG_Private_Defines
  189. * @{
  190. */
  191. /**
  192. * @brief IWDG Key Register BitMask
  193. */
  194. #define IWDG_KEY_RELOAD ((uint32_t)0x0000AAAA) /*!< IWDG Reload Counter Enable */
  195. #define IWDG_KEY_ENABLE ((uint32_t)0x0000CCCC) /*!< IWDG Peripheral Enable */
  196. #define IWDG_KEY_WRITE_ACCESS_ENABLE ((uint32_t)0x00005555) /*!< IWDG KR Write Access Enable */
  197. #define IWDG_KEY_WRITE_ACCESS_DISABLE ((uint32_t)0x00000000) /*!< IWDG KR Write Access Disable */
  198. /**
  199. * @brief IWDG Flag definition
  200. */
  201. #define IWDG_FLAG_PVU ((uint32_t)IWDG_SR_PVU) /*!< Watchdog counter prescaler value update flag */
  202. #define IWDG_FLAG_RVU ((uint32_t)IWDG_SR_RVU) /*!< Watchdog counter reload value update flag */
  203. #define IWDG_FLAG_WVU ((uint32_t)IWDG_SR_WVU) /*!< Watchdog counter window value update flag */
  204. /**
  205. * @}
  206. */
  207. /* Private macros ------------------------------------------------------------*/
  208. /** @defgroup IWDG_Private_Macro IWDG Private Macros
  209. * @{
  210. */
  211. /**
  212. * @brief Enables write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers.
  213. * @param __HANDLE__: IWDG handle
  214. * @retval None
  215. */
  216. #define IWDG_ENABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_ENABLE)
  217. /**
  218. * @brief Disables write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers.
  219. * @param __HANDLE__: IWDG handle
  220. * @retval None
  221. */
  222. #define IWDG_DISABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_DISABLE)
  223. /**
  224. * @brief Check IWDG prescaler value.
  225. * @param __PRESCALER__: IWDG prescaler value
  226. * @retval None
  227. */
  228. #define IS_IWDG_PRESCALER(__PRESCALER__) (((__PRESCALER__) == IWDG_PRESCALER_4) || \
  229. ((__PRESCALER__) == IWDG_PRESCALER_8) || \
  230. ((__PRESCALER__) == IWDG_PRESCALER_16) || \
  231. ((__PRESCALER__) == IWDG_PRESCALER_32) || \
  232. ((__PRESCALER__) == IWDG_PRESCALER_64) || \
  233. ((__PRESCALER__) == IWDG_PRESCALER_128)|| \
  234. ((__PRESCALER__) == IWDG_PRESCALER_256))
  235. /**
  236. * @brief Check IWDG reload value.
  237. * @param __RELOAD__: IWDG reload value
  238. * @retval None
  239. */
  240. #define IS_IWDG_RELOAD(__RELOAD__) ((__RELOAD__) <= 0xFFF)
  241. /**
  242. * @brief Check IWDG window value.
  243. * @param __WINDOW__: IWDG window value
  244. * @retval None
  245. */
  246. #define IS_IWDG_WINDOW(__WINDOW__) ((__WINDOW__) <= 0xFFF)
  247. /**
  248. * @}
  249. */
  250. /**
  251. * @}
  252. */
  253. /**
  254. * @}
  255. */
  256. #ifdef __cplusplus
  257. }
  258. #endif
  259. #endif /* __STM32F7xx_HAL_IWDG_H */
  260. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/