hc32f460_wdt.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*******************************************************************************
  2. * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by HDSC under BSD 3-Clause license
  5. * (the "License"); You may not use this file except in compliance with the
  6. * License. You may obtain a copy of the License at:
  7. * opensource.org/licenses/BSD-3-Clause
  8. */
  9. /******************************************************************************/
  10. /** \file hc32f460_wdt.h
  11. **
  12. ** A detailed description is available at
  13. ** @link WdtGroup Watchdog Counter description @endlink
  14. **
  15. ** - 2018-10-18 CDT First version for Device Driver Library of WDT.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_WDT_H__
  19. #define __HC32F460_WDT_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_WDT_ENABLE == DDL_ON)
  26. /* C binding of definitions if building with C++ compiler */
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /**
  32. *******************************************************************************
  33. ** \defgroup WdtGroup WatchDog Counter(WDT)
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. /**
  41. *******************************************************************************
  42. ** \brief WDT count cycle enumeration
  43. ******************************************************************************/
  44. typedef enum en_wdt_count_cycle
  45. {
  46. WdtCountCycle256 = 0u, ///< 256 cycle
  47. WdtCountCycle4096 = 1u, ///< 4096 cycle
  48. WdtCountCycle16384 = 2u, ///< 16384 cycle
  49. WdtCountCycle65536 = 3u, ///< 65536 cycle
  50. } en_wdt_count_cycle_t;
  51. /**
  52. *******************************************************************************
  53. ** \brief WDT count clock division enumeration
  54. ******************************************************************************/
  55. typedef enum en_wdt_clk_div
  56. {
  57. WdtPclk3Div4 = 2u, ///< PCLK3/4
  58. WdtPclk3Div64 = 6u, ///< PCLK3/64
  59. WdtPclk3Div128 = 7u, ///< PCLK3/128
  60. WdtPclk3Div256 = 8u, ///< PCLK3/256
  61. WdtPclk3Div512 = 9u, ///< PCLK3/512
  62. WdtPclk3Div1024 = 10u, ///< PCLK3/1024
  63. WdtPclk3Div2048 = 11u, ///< PCLK3/2048
  64. WdtPclk3Div8192 = 13u, ///< PCLK3/8192
  65. } en_wdt_clk_div_t;
  66. /**
  67. *******************************************************************************
  68. ** \brief WDT allow refresh percent range enumeration
  69. ******************************************************************************/
  70. typedef enum en_wdt_refresh_range
  71. {
  72. WdtRefresh100Pct = 0u, ///< 100%
  73. WdtRefresh0To25Pct = 1u, ///< 0%~25%
  74. WdtRefresh25To50Pct = 2u, ///< 25%~50%
  75. WdtRefresh0To50Pct = 3u, ///< 0%~50%
  76. WdtRefresh50To75Pct = 4u, ///< 50%~75%
  77. WdtRefresh0To25PctAnd50To75Pct = 5u, ///< 0%~25% & 50%~75%
  78. WdtRefresh25To75Pct = 6u, ///< 25%~75%
  79. WdtRefresh0To75Pct = 7u, ///< 0%~75%
  80. WdtRefresh75To100Pct = 8u, ///< 75%~100%
  81. WdtRefresh0To25PctAnd75To100Pct = 9u, ///< 0%~25% & 75%~100%
  82. WdtRefresh25To50PctAnd75To100Pct = 10u, ///< 25%~50% & 75%~100%
  83. WdtRefresh0To50PctAnd75To100Pct = 11u, ///< 0%~50% & 75%~100%
  84. WdtRefresh50To100Pct = 12u, ///< 50%~100%
  85. WdtRefresh0To25PctAnd50To100Pct = 13u, ///< 0%~25% & 50%~100%
  86. WdtRefresh25To100Pct = 14u, ///< 25%~100%
  87. WdtRefresh0To100Pct = 15u, ///< 0%~100%
  88. } en_wdt_refresh_range_t;
  89. /**
  90. *******************************************************************************
  91. ** \brief WDT refresh error or count underflow trigger event type enumeration
  92. ******************************************************************************/
  93. typedef enum en_wdt_event_request_type
  94. {
  95. WdtTriggerInterruptRequest = 0u, ///< Interrupt request
  96. WdtTriggerResetRequest = 1u, ///< Reset request
  97. } en_wdt_event_request_type_t;
  98. /**
  99. *******************************************************************************
  100. ** \brief WDT flag type enumeration
  101. ******************************************************************************/
  102. typedef enum en_wdt_flag_type
  103. {
  104. WdtFlagCountUnderflow = 0u, ///< Count underflow flag
  105. WdtFlagRefreshError = 1u, ///< Refresh error flag
  106. } en_wdt_flag_type_t;
  107. /**
  108. *******************************************************************************
  109. ** \brief WDT init structure definition
  110. ******************************************************************************/
  111. typedef struct stc_wdt_init
  112. {
  113. en_wdt_count_cycle_t enCountCycle; ///< Count cycle
  114. en_wdt_clk_div_t enClkDiv; ///< Count clock division
  115. en_wdt_refresh_range_t enRefreshRange; ///< Allow refresh percent range
  116. en_functional_state_t enSleepModeCountEn; ///< Enable/disable count in the sleep mode
  117. en_wdt_event_request_type_t enRequestType; ///< Refresh error or count underflow trigger event type
  118. } stc_wdt_init_t;
  119. /*******************************************************************************
  120. * Global pre-processor symbols/macros ('#define')
  121. ******************************************************************************/
  122. /*******************************************************************************
  123. * Global variable definitions ('extern')
  124. ******************************************************************************/
  125. /*******************************************************************************
  126. Global function prototypes (definition in C source)
  127. ******************************************************************************/
  128. /* Base functions */
  129. en_result_t WDT_Init(const stc_wdt_init_t *pstcWdtInit);
  130. en_result_t WDT_RefreshCounter(void);
  131. uint16_t WDT_GetCountValue(void);
  132. /* Flags functions */
  133. en_flag_status_t WDT_GetFlag(en_wdt_flag_type_t enFlag);
  134. en_result_t WDT_ClearFlag(en_wdt_flag_type_t enFlag);
  135. //@} // WdtGroup
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif /* DDL_WDT_ENABLE */
  140. #endif /* __HC32F460_WDT_H__ */
  141. /*******************************************************************************
  142. * EOF (not truncated)
  143. ******************************************************************************/