py32f002b_hal_iwdg.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /**
  2. ******************************************************************************
  3. * @file py32f002b_hal_iwdg.h
  4. * @author MCU Application Team
  5. * @brief Header file of IWDG HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. /* Define to prevent recursive inclusion -------------------------------------*/
  31. #ifndef __PY32F002B_HAL_IWDG_H
  32. #define __PY32F002B_HAL_IWDG_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f002b_hal_def.h"
  38. /** @addtogroup PY32F002B_HAL_Driver
  39. * @{
  40. */
  41. /** @addtogroup IWDG
  42. * @{
  43. */
  44. /* Exported types ------------------------------------------------------------*/
  45. /** @defgroup IWDG_Exported_Types IWDG Exported Types
  46. * @{
  47. */
  48. /**
  49. * @brief IWDG Init structure definition
  50. */
  51. typedef struct
  52. {
  53. uint32_t Prescaler; /*!< Select the prescaler of the IWDG.
  54. This parameter can be a value of @ref IWDG_Prescaler */
  55. uint32_t Reload; /*!< Specifies the IWDG down-counter reload value.
  56. This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
  57. } IWDG_InitTypeDef;
  58. /**
  59. * @brief IWDG Handle Structure definition
  60. */
  61. typedef struct
  62. {
  63. IWDG_TypeDef *Instance; /*!< Register base address */
  64. IWDG_InitTypeDef Init; /*!< IWDG required parameters */
  65. } IWDG_HandleTypeDef;
  66. /**
  67. * @}
  68. */
  69. /* Exported constants --------------------------------------------------------*/
  70. /** @defgroup IWDG_Exported_Constants IWDG Exported Constants
  71. * @{
  72. */
  73. /** @defgroup IWDG_Prescaler IWDG Prescaler
  74. * @{
  75. */
  76. #define IWDG_PRESCALER_4 0x00000000U /*!< IWDG prescaler set to 4 */
  77. #define IWDG_PRESCALER_8 IWDG_PR_PR_0 /*!< IWDG prescaler set to 8 */
  78. #define IWDG_PRESCALER_16 IWDG_PR_PR_1 /*!< IWDG prescaler set to 16 */
  79. #define IWDG_PRESCALER_32 (IWDG_PR_PR_1 | IWDG_PR_PR_0) /*!< IWDG prescaler set to 32 */
  80. #define IWDG_PRESCALER_64 IWDG_PR_PR_2 /*!< IWDG prescaler set to 64 */
  81. #define IWDG_PRESCALER_128 (IWDG_PR_PR_2 | IWDG_PR_PR_0) /*!< IWDG prescaler set to 128 */
  82. #define IWDG_PRESCALER_256 (IWDG_PR_PR_2 | IWDG_PR_PR_1) /*!< IWDG prescaler set to 256 */
  83. /**
  84. * @}
  85. */
  86. /**
  87. * @}
  88. */
  89. /* Exported macros -----------------------------------------------------------*/
  90. /** @defgroup IWDG_Exported_Macros IWDG Exported Macros
  91. * @{
  92. */
  93. /**
  94. * @brief Enable the IWDG peripheral.
  95. * @param __HANDLE__ IWDG handle
  96. * @retval None
  97. */
  98. #define __HAL_IWDG_START(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_ENABLE)
  99. /**
  100. * @brief Reload IWDG counter with value defined in the reload register
  101. * (write access to IWDG_PR & IWDG_RLR registers disabled).
  102. * @param __HANDLE__ IWDG handle
  103. * @retval None
  104. */
  105. #define __HAL_IWDG_RELOAD_COUNTER(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_RELOAD)
  106. /**
  107. * @}
  108. */
  109. /* Exported functions --------------------------------------------------------*/
  110. /** @defgroup IWDG_Exported_Functions IWDG Exported Functions
  111. * @{
  112. */
  113. /** @defgroup IWDG_Exported_Functions_Group1 Initialization and Start functions
  114. * @{
  115. */
  116. /* Initialization/Start functions ********************************************/
  117. HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg);
  118. /**
  119. * @}
  120. */
  121. /** @defgroup IWDG_Exported_Functions_Group2 IO operation functions
  122. * @{
  123. */
  124. /* I/O operation functions ****************************************************/
  125. HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg);
  126. /**
  127. * @}
  128. */
  129. /**
  130. * @}
  131. */
  132. /* Private constants ---------------------------------------------------------*/
  133. /** @defgroup IWDG_Private_Constants IWDG Private Constants
  134. * @{
  135. */
  136. /**
  137. * @brief IWDG Key Register BitMask
  138. */
  139. #define IWDG_KEY_RELOAD 0x0000AAAAU /*!< IWDG Reload Counter Enable */
  140. #define IWDG_KEY_ENABLE 0x0000CCCCU /*!< IWDG Peripheral Enable */
  141. #define IWDG_KEY_WRITE_ACCESS_ENABLE 0x00005555U /*!< IWDG KR Write Access Enable */
  142. #define IWDG_KEY_WRITE_ACCESS_DISABLE 0x00000000U /*!< IWDG KR Write Access Disable */
  143. /**
  144. * @}
  145. */
  146. /* Private macros ------------------------------------------------------------*/
  147. /** @defgroup IWDG_Private_Macros IWDG Private Macros
  148. * @{
  149. */
  150. /**
  151. * @brief Enable write access to IWDG_PR and IWDG_RLR registers.
  152. * @param __HANDLE__ IWDG handle
  153. * @retval None
  154. */
  155. #define IWDG_ENABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_ENABLE)
  156. /**
  157. * @brief Disable write access to IWDG_PR and IWDG_RLR registers.
  158. * @param __HANDLE__ IWDG handle
  159. * @retval None
  160. */
  161. #define IWDG_DISABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_DISABLE)
  162. /**
  163. * @brief Check IWDG prescaler value.
  164. * @param __PRESCALER__ IWDG prescaler value
  165. * @retval None
  166. */
  167. #define IS_IWDG_PRESCALER(__PRESCALER__) (((__PRESCALER__) == IWDG_PRESCALER_4) || \
  168. ((__PRESCALER__) == IWDG_PRESCALER_8) || \
  169. ((__PRESCALER__) == IWDG_PRESCALER_16) || \
  170. ((__PRESCALER__) == IWDG_PRESCALER_32) || \
  171. ((__PRESCALER__) == IWDG_PRESCALER_64) || \
  172. ((__PRESCALER__) == IWDG_PRESCALER_128)|| \
  173. ((__PRESCALER__) == IWDG_PRESCALER_256))
  174. /**
  175. * @brief Check IWDG reload value.
  176. * @param __RELOAD__ IWDG reload value
  177. * @retval None
  178. */
  179. #define IS_IWDG_RELOAD(__RELOAD__) ((__RELOAD__) <= IWDG_RLR_RL)
  180. /**
  181. * @}
  182. */
  183. /**
  184. * @}
  185. */
  186. /**
  187. * @}
  188. */
  189. #ifdef __cplusplus
  190. }
  191. #endif
  192. #endif /* __PY32F002B_HAL_IWDG_H */
  193. /************************ (C) COPYRIGHT Puya *****END OF FILE****/