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.
 
 
 

249 lines
8.8 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_iwdg.h
  4. * @author MCD Application Team
  5. * @version V1.1.0
  6. * @date 19-June-2014
  7. * @brief Header file of IWDG HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2014 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 __STM32F4xx_HAL_IWDG_H
  39. #define __STM32F4xx_HAL_IWDG_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f4xx_hal_def.h"
  45. /** @addtogroup STM32F4xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup IWDG
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /**
  53. * @brief IWDG HAL State Structure definition
  54. */
  55. typedef enum
  56. {
  57. HAL_IWDG_STATE_RESET = 0x00, /*!< IWDG not yet initialized or disabled */
  58. HAL_IWDG_STATE_READY = 0x01, /*!< IWDG initialized and ready for use */
  59. HAL_IWDG_STATE_BUSY = 0x02, /*!< IWDG internal process is ongoing */
  60. HAL_IWDG_STATE_TIMEOUT = 0x03, /*!< IWDG timeout state */
  61. HAL_IWDG_STATE_ERROR = 0x04 /*!< IWDG error state */
  62. }HAL_IWDG_StateTypeDef;
  63. /**
  64. * @brief IWDG Init structure definition
  65. */
  66. typedef struct
  67. {
  68. uint32_t Prescaler; /*!< Select the prescaler of the IWDG.
  69. This parameter can be a value of @ref IWDG_Prescaler */
  70. uint32_t Reload; /*!< Specifies the IWDG down-counter reload value.
  71. This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
  72. }IWDG_InitTypeDef;
  73. /**
  74. * @brief IWDG handle Structure definition
  75. */
  76. typedef struct
  77. {
  78. IWDG_TypeDef *Instance; /*!< Register base address */
  79. IWDG_InitTypeDef Init; /*!< IWDG required parameters */
  80. HAL_LockTypeDef Lock; /*!< IWDG locking object */
  81. __IO HAL_IWDG_StateTypeDef State; /*!< IWDG communication state */
  82. }IWDG_HandleTypeDef;
  83. /* Exported constants --------------------------------------------------------*/
  84. /** @defgroup IWDG_Exported_Constants
  85. * @{
  86. */
  87. /** @defgroup IWDG_Registers_BitMask
  88. * @{
  89. */
  90. /* --- KR Register ---*/
  91. /* KR register bit mask */
  92. #define KR_KEY_RELOAD ((uint32_t)0xAAAA) /*!< IWDG reload counter enable */
  93. #define KR_KEY_ENABLE ((uint32_t)0xCCCC) /*!< IWDG peripheral enable */
  94. #define KR_KEY_EWA ((uint32_t)0x5555) /*!< IWDG KR write Access enable */
  95. #define KR_KEY_DWA ((uint32_t)0x0000) /*!< IWDG KR write Access disable */
  96. #define IS_IWDG_KR(__KR__) (((__KR__) == KR_KEY_RELOAD) || \
  97. ((__KR__) == KR_KEY_ENABLE))|| \
  98. ((__KR__) == KR_KEY_EWA)) || \
  99. ((__KR__) == KR_KEY_DWA))
  100. /**
  101. * @}
  102. */
  103. /** @defgroup IWDG_Flag_definition
  104. * @{
  105. */
  106. #define IWDG_FLAG_PVU ((uint32_t)0x0001) /*!< Watchdog counter prescaler value update flag */
  107. #define IWDG_FLAG_RVU ((uint32_t)0x0002) /*!< Watchdog counter reload value update flag */
  108. #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || \
  109. ((FLAG) == IWDG_FLAG_RVU))
  110. /**
  111. * @}
  112. */
  113. /** @defgroup IWDG_Prescaler
  114. * @{
  115. */
  116. #define IWDG_PRESCALER_4 ((uint8_t)0x00) /*!< IWDG prescaler set to 4 */
  117. #define IWDG_PRESCALER_8 ((uint8_t)(IWDG_PR_PR_0)) /*!< IWDG prescaler set to 8 */
  118. #define IWDG_PRESCALER_16 ((uint8_t)(IWDG_PR_PR_1)) /*!< IWDG prescaler set to 16 */
  119. #define IWDG_PRESCALER_32 ((uint8_t)(IWDG_PR_PR_1 | IWDG_PR_PR_0)) /*!< IWDG prescaler set to 32 */
  120. #define IWDG_PRESCALER_64 ((uint8_t)(IWDG_PR_PR_2)) /*!< IWDG prescaler set to 64 */
  121. #define IWDG_PRESCALER_128 ((uint8_t)(IWDG_PR_PR_2 | IWDG_PR_PR_0)) /*!< IWDG prescaler set to 128 */
  122. #define IWDG_PRESCALER_256 ((uint8_t)(IWDG_PR_PR_2 | IWDG_PR_PR_1)) /*!< IWDG prescaler set to 256 */
  123. #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_PRESCALER_4) || \
  124. ((PRESCALER) == IWDG_PRESCALER_8) || \
  125. ((PRESCALER) == IWDG_PRESCALER_16) || \
  126. ((PRESCALER) == IWDG_PRESCALER_32) || \
  127. ((PRESCALER) == IWDG_PRESCALER_64) || \
  128. ((PRESCALER) == IWDG_PRESCALER_128)|| \
  129. ((PRESCALER) == IWDG_PRESCALER_256))
  130. /**
  131. * @}
  132. */
  133. /** @defgroup IWDG_Reload_Value
  134. * @{
  135. */
  136. #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF)
  137. /**
  138. * @}
  139. */
  140. /**
  141. * @}
  142. */
  143. /* Exported macro ------------------------------------------------------------*/
  144. /** @brief Reset IWDG handle state
  145. * @param __HANDLE__: IWDG handle
  146. * @retval None
  147. */
  148. #define __HAL_IWDG_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_IWDG_STATE_RESET)
  149. /**
  150. * @brief Enables the IWDG peripheral.
  151. * @param __HANDLE__: IWDG handle
  152. * @retval None
  153. */
  154. #define __HAL_IWDG_START(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, KR_KEY_ENABLE)
  155. /**
  156. * @brief Reloads IWDG counter with value defined in the reload register
  157. * (write access to IWDG_PR and IWDG_RLR registers disabled).
  158. * @param __HANDLE__: IWDG handle
  159. * @retval None
  160. */
  161. #define __HAL_IWDG_RELOAD_COUNTER(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, KR_KEY_RELOAD)
  162. /**
  163. * @brief Enables write access to IWDG_PR and IWDG_RLR registers.
  164. * @param __HANDLE__: IWDG handle
  165. * @retval None
  166. */
  167. #define __HAL_IWDG_ENABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, KR_KEY_EWA)
  168. /**
  169. * @brief Disables write access to IWDG_PR and IWDG_RLR registers.
  170. * @param __HANDLE__: IWDG handle
  171. * @retval None
  172. */
  173. #define __HAL_IWDG_DISABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, KR_KEY_DWA)
  174. /**
  175. * @brief Gets the selected IWDG's flag status.
  176. * @param __HANDLE__: IWDG handle
  177. * @param __FLAG__: specifies the flag to check.
  178. * This parameter can be one of the following values:
  179. * @arg IWDG_FLAG_PVU: Watchdog counter reload value update flag
  180. * @arg IWDG_FLAG_RVU: Watchdog counter prescaler value flag
  181. * @retval The new state of __FLAG__ (TRUE or FALSE).
  182. */
  183. #define __HAL_IWDG_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
  184. /* Exported functions --------------------------------------------------------*/
  185. /* Initialization/de-initialization functions ********************************/
  186. HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg);
  187. void HAL_IWDG_MspInit(IWDG_HandleTypeDef *hiwdg);
  188. /* I/O operation functions ****************************************************/
  189. HAL_StatusTypeDef HAL_IWDG_Start(IWDG_HandleTypeDef *hiwdg);
  190. HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg);
  191. /* Peripheral State functions ************************************************/
  192. HAL_IWDG_StateTypeDef HAL_IWDG_GetState(IWDG_HandleTypeDef *hiwdg);
  193. /**
  194. * @}
  195. */
  196. /**
  197. * @}
  198. */
  199. #ifdef __cplusplus
  200. }
  201. #endif
  202. #endif /* __STM32F4xx_HAL_IWDG_H */
  203. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/