hc32_ll_swdt.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_swdt.h
  4. * @brief This file contains all the functions prototypes of the SWDT 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_SWDT_H__
  22. #define __HC32_LL_SWDT_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_SWDT
  40. * @{
  41. */
  42. #if (LL_SWDT_ENABLE == DDL_ON)
  43. /*******************************************************************************
  44. * Global type definitions ('typedef')
  45. ******************************************************************************/
  46. /**
  47. * @defgroup SWDT_Global_Types SWDT Global Types
  48. * @{
  49. */
  50. /**
  51. * @brief SWDT Init structure definition
  52. */
  53. typedef struct {
  54. uint32_t u32CountPeriod; /*!< Specifies the counting period of SWDT.
  55. This parameter can be a value of @ref SWDT_Count_Period */
  56. uint32_t u32ClockDiv; /*!< Specifies the clock division factor of SWDT.
  57. This parameter can be a value of @ref SWDT_Clock_Division */
  58. uint32_t u32RefreshRange; /*!< Specifies the allow refresh range of SWDT.
  59. This parameter can be a value of @ref SWDT_Refresh_Range */
  60. uint32_t u32LPMCount; /*!< Specifies the count state in Low Power Mode (Sleep/Stop Mode).
  61. This parameter can be a value of @ref SWDT_LPM_Count */
  62. uint32_t u32ExceptionType; /*!< Specifies the type of exception response for SWDT.
  63. This parameter can be a value of @ref SWDT_Exception_Type */
  64. } stc_swdt_init_t;
  65. /**
  66. * @}
  67. */
  68. /*******************************************************************************
  69. * Global pre-processor symbols/macros ('#define')
  70. ******************************************************************************/
  71. /**
  72. * @defgroup SWDT_Global_Macros SWDT Global Macros
  73. * @{
  74. */
  75. /**
  76. * @defgroup SWDT_Count_Period SWDT Count Period
  77. * @{
  78. */
  79. #define SWDT_CNT_PERIOD256 (0UL) /*!< 256 clock cycle */
  80. #define SWDT_CNT_PERIOD4096 (SWDT_CR_PERI_0) /*!< 4096 clock cycle */
  81. #define SWDT_CNT_PERIOD16384 (SWDT_CR_PERI_1) /*!< 16384 clock cycle */
  82. #define SWDT_CNT_PERIOD65536 (SWDT_CR_PERI) /*!< 65536 clock cycle */
  83. /**
  84. * @}
  85. */
  86. /**
  87. * @defgroup SWDT_Clock_Division SWDT Clock Division
  88. * @{
  89. */
  90. #define SWDT_CLK_DIV1 (0UL) /*!< SWDTCLK/1 */
  91. #define SWDT_CLK_DIV16 (0x04UL << SWDT_CR_CKS_POS) /*!< SWDTCLK/16 */
  92. #define SWDT_CLK_DIV32 (0x05UL << SWDT_CR_CKS_POS) /*!< SWDTCLK/32 */
  93. #define SWDT_CLK_DIV64 (0x06UL << SWDT_CR_CKS_POS) /*!< SWDTCLK/64 */
  94. #define SWDT_CLK_DIV128 (0x07UL << SWDT_CR_CKS_POS) /*!< SWDTCLK/128 */
  95. #define SWDT_CLK_DIV256 (0x08UL << SWDT_CR_CKS_POS) /*!< SWDTCLK/256 */
  96. #define SWDT_CLK_DIV2048 (0x0BUL << SWDT_CR_CKS_POS) /*!< SWDTCLK/2048 */
  97. /**
  98. * @}
  99. */
  100. /**
  101. * @defgroup SWDT_Refresh_Range SWDT Refresh Range
  102. * @{
  103. */
  104. #define SWDT_RANGE_0TO25PCT (0x01UL << SWDT_CR_WDPT_POS) /*!< 0%~25% */
  105. #define SWDT_RANGE_25TO50PCT (0x02UL << SWDT_CR_WDPT_POS) /*!< 25%~50% */
  106. #define SWDT_RANGE_0TO50PCT (0x03UL << SWDT_CR_WDPT_POS) /*!< 0%~50% */
  107. #define SWDT_RANGE_50TO75PCT (0x04UL << SWDT_CR_WDPT_POS) /*!< 50%~75% */
  108. #define SWDT_RANGE_0TO25PCT_50TO75PCT (0x05UL << SWDT_CR_WDPT_POS) /*!< 0%~25% & 50%~75% */
  109. #define SWDT_RANGE_25TO75PCT (0x06UL << SWDT_CR_WDPT_POS) /*!< 25%~75% */
  110. #define SWDT_RANGE_0TO75PCT (0x07UL << SWDT_CR_WDPT_POS) /*!< 0%~75% */
  111. #define SWDT_RANGE_75TO100PCT (0x08UL << SWDT_CR_WDPT_POS) /*!< 75%~100% */
  112. #define SWDT_RANGE_0TO25PCT_75TO100PCT (0x09UL << SWDT_CR_WDPT_POS) /*!< 0%~25% & 75%~100% */
  113. #define SWDT_RANGE_25TO50PCT_75TO100PCT (0x0AUL << SWDT_CR_WDPT_POS) /*!< 25%~50% & 75%~100% */
  114. #define SWDT_RANGE_0TO50PCT_75TO100PCT (0x0BUL << SWDT_CR_WDPT_POS) /*!< 0%~50% & 75%~100% */
  115. #define SWDT_RANGE_50TO100PCT (0x0CUL << SWDT_CR_WDPT_POS) /*!< 50%~100% */
  116. #define SWDT_RANGE_0TO25PCT_50TO100PCT (0x0DUL << SWDT_CR_WDPT_POS) /*!< 0%~25% & 50%~100% */
  117. #define SWDT_RANGE_25TO100PCT (0x0EUL << SWDT_CR_WDPT_POS) /*!< 25%~100% */
  118. #define SWDT_RANGE_0TO100PCT (0x0FUL << SWDT_CR_WDPT_POS) /*!< 0%~100% */
  119. /**
  120. * @}
  121. */
  122. /**
  123. * @defgroup SWDT_LPM_Count SWDT Low Power Mode Count
  124. * @brief Counting control of SWDT in sleep/stop mode.
  125. * @{
  126. */
  127. #define SWDT_LPM_CNT_CONTINUE (0UL) /*!< Continue counting in sleep/stop mode */
  128. #define SWDT_LPM_CNT_STOP (SWDT_CR_SLPOFF) /*!< Stop counting in sleep/stop mode */
  129. /**
  130. * @}
  131. */
  132. /**
  133. * @defgroup SWDT_Exception_Type SWDT Exception Type
  134. * @brief Specifies the exception response when a refresh error or count overflow occurs.
  135. * @{
  136. */
  137. #define SWDT_EXP_TYPE_INT (0UL) /*!< SWDT trigger interrupt */
  138. #define SWDT_EXP_TYPE_RST (SWDT_CR_ITS) /*!< SWDT trigger reset */
  139. /**
  140. * @}
  141. */
  142. /**
  143. * @defgroup SWDT_Flag SWDT Flag
  144. * @{
  145. */
  146. #define SWDT_FLAG_UDF (SWDT_SR_UDF) /*!< Count underflow flag */
  147. #define SWDT_FLAG_REFRESH (SWDT_SR_REF) /*!< Refresh error flag */
  148. #define SWDT_FLAG_ALL (SWDT_SR_UDF | SWDT_SR_REF)
  149. /**
  150. * @}
  151. */
  152. /**
  153. * @}
  154. */
  155. /*******************************************************************************
  156. * Global variable definitions ('extern')
  157. ******************************************************************************/
  158. /*******************************************************************************
  159. Global function prototypes (definition in C source)
  160. ******************************************************************************/
  161. /**
  162. * @addtogroup SWDT_Global_Functions
  163. * @{
  164. */
  165. /**
  166. * @brief Get SWDT count value.
  167. * @param None
  168. * @retval uint16_t Count value
  169. */
  170. __STATIC_INLINE uint16_t SWDT_GetCountValue(void)
  171. {
  172. return (uint16_t)(READ_REG32(CM_SWDT->SR) & SWDT_SR_CNT);
  173. }
  174. /* Initialization and configuration functions */
  175. int32_t SWDT_Init(const stc_swdt_init_t *pstcSwdtInit);
  176. void SWDT_FeedDog(void);
  177. uint16_t SWDT_GetCountValue(void);
  178. /* Flags management functions */
  179. en_flag_status_t SWDT_GetStatus(uint32_t u32Flag);
  180. int32_t SWDT_ClearStatus(uint32_t u32Flag);
  181. /**
  182. * @}
  183. */
  184. #endif /* LL_SWDT_ENABLE */
  185. /**
  186. * @}
  187. */
  188. /**
  189. * @}
  190. */
  191. #ifdef __cplusplus
  192. }
  193. #endif
  194. #endif /* __HC32_LL_SWDT_H__ */
  195. /*******************************************************************************
  196. * EOF (not truncated)
  197. ******************************************************************************/