hc32_ll_wdt.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_wdt.h
  4. * @brief This file contains all the functions prototypes of the WDT driver
  5. * library.
  6. @verbatim
  7. Change Logs:
  8. Date Author Notes
  9. 2022-12-31 CDT First version
  10. @endverbatim
  11. *******************************************************************************
  12. * Copyright (C) 2022, Xiaohua Semiconductor Co., Ltd. All rights reserved.
  13. *
  14. * This software component is licensed by XHSC under BSD 3-Clause license
  15. * (the "License"); You may not use this file except in compliance with the
  16. * License. You may obtain a copy of the License at:
  17. * opensource.org/licenses/BSD-3-Clause
  18. *
  19. *******************************************************************************
  20. */
  21. #ifndef __HC32_LL_WDT_H__
  22. #define __HC32_LL_WDT_H__
  23. /* C binding of definitions if building with C++ compiler */
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. /*******************************************************************************
  29. * Include files
  30. ******************************************************************************/
  31. #include "hc32_ll_def.h"
  32. #include "hc32f4xx.h"
  33. #include "hc32f4xx_conf.h"
  34. /**
  35. * @addtogroup LL_Driver
  36. * @{
  37. */
  38. /**
  39. * @addtogroup LL_WDT
  40. * @{
  41. */
  42. #if (LL_WDT_ENABLE == DDL_ON)
  43. /*******************************************************************************
  44. * Global type definitions ('typedef')
  45. ******************************************************************************/
  46. /**
  47. * @defgroup WDT_Global_Types WDT Global Types
  48. * @{
  49. */
  50. /**
  51. * @brief WDT Init structure definition
  52. */
  53. typedef struct {
  54. uint32_t u32CountPeriod; /*!< Specifies the counting period of WDT.
  55. This parameter can be a value of @ref WDT_Count_Period */
  56. uint32_t u32ClockDiv; /*!< Specifies the clock division factor of WDT.
  57. This parameter can be a value of @ref WDT_Clock_Division */
  58. uint32_t u32RefreshRange; /*!< Specifies the allow refresh range of WDT.
  59. This parameter can be a value of @ref WDT_Refresh_Range */
  60. uint32_t u32LPMCount; /*!< Specifies the count state in Low Power Mode (Sleep Mode).
  61. This parameter can be a value of @ref WDT_LPM_Count */
  62. uint32_t u32ExceptionType; /*!< Specifies the type of exception response for WDT.
  63. This parameter can be a value of @ref WDT_Exception_Type */
  64. } stc_wdt_init_t;
  65. /**
  66. * @}
  67. */
  68. /*******************************************************************************
  69. * Global pre-processor symbols/macros ('#define')
  70. ******************************************************************************/
  71. /**
  72. * @defgroup WDT_Global_Macros WDT Global Macros
  73. * @{
  74. */
  75. /**
  76. * @defgroup WDT_Count_Period WDT Count Period
  77. * @{
  78. */
  79. #define WDT_CNT_PERIOD256 (0UL) /*!< 256 clock cycle */
  80. #define WDT_CNT_PERIOD4096 (WDT_CR_PERI_0) /*!< 4096 clock cycle */
  81. #define WDT_CNT_PERIOD16384 (WDT_CR_PERI_1) /*!< 16384 clock cycle */
  82. #define WDT_CNT_PERIOD65536 (WDT_CR_PERI) /*!< 65536 clock cycle */
  83. /**
  84. * @}
  85. */
  86. /**
  87. * @defgroup WDT_Clock_Division WDT Clock Division
  88. * @{
  89. */
  90. #define WDT_CLK_DIV4 (0x02UL << WDT_CR_CKS_POS) /*!< PLCKx/4 */
  91. #define WDT_CLK_DIV64 (0x06UL << WDT_CR_CKS_POS) /*!< PLCKx/64 */
  92. #define WDT_CLK_DIV128 (0x07UL << WDT_CR_CKS_POS) /*!< PLCKx/128 */
  93. #define WDT_CLK_DIV256 (0x08UL << WDT_CR_CKS_POS) /*!< PLCKx/256 */
  94. #define WDT_CLK_DIV512 (0x09UL << WDT_CR_CKS_POS) /*!< PLCKx/512 */
  95. #define WDT_CLK_DIV1024 (0x0AUL << WDT_CR_CKS_POS) /*!< PLCKx/1024 */
  96. #define WDT_CLK_DIV2048 (0x0BUL << WDT_CR_CKS_POS) /*!< PLCKx/2048 */
  97. #define WDT_CLK_DIV8192 (0x0DUL << WDT_CR_CKS_POS) /*!< PLCKx/8192 */
  98. /**
  99. * @}
  100. */
  101. /**
  102. * @defgroup WDT_Refresh_Range WDT Refresh Range
  103. * @{
  104. */
  105. #define WDT_RANGE_0TO25PCT (0x01UL << WDT_CR_WDPT_POS) /*!< 0%~25% */
  106. #define WDT_RANGE_25TO50PCT (0x02UL << WDT_CR_WDPT_POS) /*!< 25%~50% */
  107. #define WDT_RANGE_0TO50PCT (0x03UL << WDT_CR_WDPT_POS) /*!< 0%~50% */
  108. #define WDT_RANGE_50TO75PCT (0x04UL << WDT_CR_WDPT_POS) /*!< 50%~75% */
  109. #define WDT_RANGE_0TO25PCT_50TO75PCT (0x05UL << WDT_CR_WDPT_POS) /*!< 0%~25% & 50%~75% */
  110. #define WDT_RANGE_25TO75PCT (0x06UL << WDT_CR_WDPT_POS) /*!< 25%~75% */
  111. #define WDT_RANGE_0TO75PCT (0x07UL << WDT_CR_WDPT_POS) /*!< 0%~75% */
  112. #define WDT_RANGE_75TO100PCT (0x08UL << WDT_CR_WDPT_POS) /*!< 75%~100% */
  113. #define WDT_RANGE_0TO25PCT_75TO100PCT (0x09UL << WDT_CR_WDPT_POS) /*!< 0%~25% & 75%~100% */
  114. #define WDT_RANGE_25TO50PCT_75TO100PCT (0x0AUL << WDT_CR_WDPT_POS) /*!< 25%~50% & 75%~100% */
  115. #define WDT_RANGE_0TO50PCT_75TO100PCT (0x0BUL << WDT_CR_WDPT_POS) /*!< 0%~50% & 75%~100% */
  116. #define WDT_RANGE_50TO100PCT (0x0CUL << WDT_CR_WDPT_POS) /*!< 50%~100% */
  117. #define WDT_RANGE_0TO25PCT_50TO100PCT (0x0DUL << WDT_CR_WDPT_POS) /*!< 0%~25% & 50%~100% */
  118. #define WDT_RANGE_25TO100PCT (0x0EUL << WDT_CR_WDPT_POS) /*!< 25%~100% */
  119. #define WDT_RANGE_0TO100PCT (0x0FUL << WDT_CR_WDPT_POS) /*!< 0%~100% */
  120. /**
  121. * @}
  122. */
  123. /**
  124. * @defgroup WDT_LPM_Count WDT Low Power Mode Count
  125. * @brief Counting control of WDT in sleep mode.
  126. * @{
  127. */
  128. #define WDT_LPM_CNT_CONTINUE (0UL) /*!< Continue counting in sleep mode */
  129. #define WDT_LPM_CNT_STOP (WDT_CR_SLPOFF) /*!< Stop counting in sleep mode */
  130. /**
  131. * @}
  132. */
  133. /**
  134. * @defgroup WDT_Exception_Type WDT Exception Type
  135. * @brief Specifies the exception response when a refresh error or count overflow occurs.
  136. * @{
  137. */
  138. #define WDT_EXP_TYPE_INT (0UL) /*!< WDT trigger interrupt */
  139. #define WDT_EXP_TYPE_RST (WDT_CR_ITS) /*!< WDT trigger reset */
  140. /**
  141. * @}
  142. */
  143. /**
  144. * @defgroup WDT_Flag WDT Flag
  145. * @{
  146. */
  147. #define WDT_FLAG_UDF (WDT_SR_UDF) /*!< Count underflow flag */
  148. #define WDT_FLAG_REFRESH (WDT_SR_REF) /*!< Refresh error flag */
  149. #define WDT_FLAG_ALL (WDT_SR_UDF | WDT_SR_REF)
  150. /**
  151. * @}
  152. */
  153. /**
  154. * @}
  155. */
  156. /*******************************************************************************
  157. * Global variable definitions ('extern')
  158. ******************************************************************************/
  159. /*******************************************************************************
  160. Global function prototypes (definition in C source)
  161. ******************************************************************************/
  162. /**
  163. * @addtogroup WDT_Global_Functions
  164. * @{
  165. */
  166. /**
  167. * @brief Get WDT count value.
  168. * @param None
  169. * @retval uint16_t Count value
  170. */
  171. __STATIC_INLINE uint16_t WDT_GetCountValue(void)
  172. {
  173. return (uint16_t)(READ_REG32(CM_WDT->SR) & WDT_SR_CNT);
  174. }
  175. /* Initialization and configuration functions */
  176. int32_t WDT_Init(const stc_wdt_init_t *pstcWdtInit);
  177. void WDT_FeedDog(void);
  178. uint16_t WDT_GetCountValue(void);
  179. /* Flags management functions */
  180. en_flag_status_t WDT_GetStatus(uint32_t u32Flag);
  181. int32_t WDT_ClearStatus(uint32_t u32Flag);
  182. /**
  183. * @}
  184. */
  185. #endif /* LL_WDT_ENABLE */
  186. /**
  187. * @}
  188. */
  189. /**
  190. * @}
  191. */
  192. #ifdef __cplusplus
  193. }
  194. #endif
  195. #endif /* __HC32_LL_WDT_H__ */
  196. /*******************************************************************************
  197. * EOF (not truncated)
  198. ******************************************************************************/