hc32_ll_ctc.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_ctc.h
  4. * @brief This file contains all the functions prototypes of the Clock Trimming
  5. * Controller(CTC) driver 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_CTC_H__
  22. #define __HC32_LL_CTC_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_CTC
  40. * @{
  41. */
  42. #if (LL_CTC_ENABLE == DDL_ON)
  43. /*******************************************************************************
  44. * Global type definitions ('typedef')
  45. ******************************************************************************/
  46. /**
  47. * @defgroup CTC_Global_Types CTC Global Types
  48. * @{
  49. */
  50. /**
  51. * @brief CTC continuous trim initialization structure definition
  52. */
  53. typedef struct {
  54. uint32_t u32HrcClockDiv; /*!< HRC clock division
  55. This parameter can be a value of @ref CTC_HRC_Clock_Division */
  56. uint32_t u32RefClockFreq; /*!< Reference clock frequency
  57. This parameter should refer user manual recommended values */
  58. uint32_t u32RefClockSrc; /*!< Reference clock source selection
  59. This parameter can be a value of @ref CTC_Continuous_Trim_Reference_Clock_Source */
  60. uint32_t u32RefClockDiv; /*!< Reference clock division
  61. This parameter can be a value of @ref CTC_Reference_Clock_Division */
  62. float32_t f32TolerantErrRate; /*!< CTC tolerance deviation
  63. This parameter can be a value between Min_Data=0.0 and Max_Data=1.0(100%) */
  64. uint8_t u8TrimValue; /*!< CTC TRMVAL value
  65. This parameter can be a value between Min_Data=0 and Max_Data=0x3F */
  66. } stc_ctc_ct_init_t;
  67. /**
  68. * @brief CTC single trim initialization structure definition
  69. */
  70. typedef struct {
  71. uint32_t u32HrcClockDiv; /*!< HRC clock division
  72. This parameter can be a value of @ref CTC_HRC_Clock_Division */
  73. uint32_t u32CtcRefEdge; /*!< CTCREF edge
  74. This parameter can be a value of @ref CTC_Single_Trim_CTCREF_Edge */
  75. float32_t f32CtcRefEdgeTime; /*!< CTCREF edge time(unit:S)
  76. This parameter should refer user actual CTCREF edge time */
  77. float32_t f32TolerantErrRate; /*!< CTC tolerance deviation
  78. This parameter can be a value between Min_Data=0.0 and Max_Data=1.0(100%) */
  79. uint8_t u8TrimValue; /*!< CTC TRMVAL value
  80. This parameter can be a value between Min_Data=0 and Max_Data=0x3F */
  81. } stc_ctc_st_init_t;
  82. /**
  83. * @}
  84. */
  85. /*******************************************************************************
  86. * Global pre-processor symbols/macros ('#define')
  87. ******************************************************************************/
  88. /**
  89. * @defgroup CTC_Global_Macros CTC Global Macros
  90. * @{
  91. */
  92. /**
  93. * @defgroup CTC_Continuous_Trim_Reference_Clock_Source CTC Continuous Trim Reference Clock Source
  94. * @{
  95. */
  96. #define CTC_REF_CLK_SRC_CTCREF (0UL) /*!< Clock source: CTCREF */
  97. #define CTC_REF_CLK_SRC_XTAL (CTC_CR1_REFCKS) /*!< Clock source: XTAL */
  98. #define CTC_REF_CLK_SRC_XTAL32 (CTC_CR1_REFCKS_1) /*!< Clock source: XTAL32 */
  99. /**
  100. * @}
  101. */
  102. /**
  103. * @defgroup CTC_Flag CTC Flag
  104. * @{
  105. */
  106. #define CTC_FLAG_TRIM_OK (CTC_STR_TRIMOK) /*!< Trimming OK flag */
  107. #define CTC_FLAG_TRIM_OVF (CTC_STR_TRMOVF) /*!< Trimming overflow flag */
  108. #define CTC_FLAG_TRIM_UDF (CTC_STR_TRMUDF) /*!< Trimming underflow flag */
  109. #define CTC_FLAG_BUSY (CTC_STR_CTCBSY) /*!< CTC busy flag */
  110. #define CTC_FLAG_ALL (CTC_FLAG_TRIM_OVF | CTC_FLAG_TRIM_UDF | \
  111. CTC_FLAG_TRIM_OK | CTC_FLAG_BUSY)
  112. /**
  113. * @}
  114. */
  115. /**
  116. * @defgroup CTC_Reference_Clock_Division CTC Reference Clock Division
  117. * @{
  118. */
  119. #define CTC_REF_CLK_DIV2 (0UL) /*!< REFCLK/2 */
  120. #define CTC_REF_CLK_DIV4 (1UL) /*!< REFCLK/4 */
  121. #define CTC_REF_CLK_DIV8 (2UL) /*!< REFCLK/8 */
  122. #define CTC_REF_CLK_DIV16 (3UL) /*!< REFCLK/16 */
  123. #define CTC_REF_CLK_DIV64 (4UL) /*!< REFCLK/64 */
  124. #define CTC_REF_CLK_DIV256 (5UL) /*!< REFCLK/256 */
  125. #define CTC_REF_CLK_DIV1024 (6UL) /*!< REFCLK/1024 */
  126. #define CTC_REF_CLK_DIV4096 (7UL) /*!< REFCLK/4096 */
  127. /**
  128. * @}
  129. */
  130. /**
  131. * @defgroup CTC_HRC_Clock_Division CTC HRC Clock Division
  132. * @{
  133. */
  134. #define CTC_HRC_CLK_DIV1 (0UL) /*!< HRCCLK/1 */
  135. #define CTC_HRC_CLK_DIV2 (1UL) /*!< HRCCLK/2 */
  136. #define CTC_HRC_CLK_DIV4 (2UL) /*!< HRCCLK/4 */
  137. #define CTC_HRC_CLK_DIV8 (3UL) /*!< HRCCLK/8 */
  138. #define CTC_HRC_CLK_DIV32 (4UL) /*!< HRCCLK/32 */
  139. #define CTC_HRC_CLK_DIV128 (5UL) /*!< HRCCLK/128 */
  140. #define CTC_HRC_CLK_DIV512 (6UL) /*!< HRCCLK/512 */
  141. #define CTC_HRC_CLK_DIV2048 (7UL) /*!< HRCCLK/2048 */
  142. /**
  143. * @}
  144. */
  145. /**
  146. * @defgroup CTC_Single_Trim_CTCREF_Edge CTC Single Trim CTCREF Edge
  147. * @{
  148. */
  149. #define CTC_CTCREF_RISING_RISING (0UL) /*!< CTC trim between CTCREF rising and CTCREF rising */
  150. #define CTC_CTCREF_RISING_FALLING (CTC_CR1_REFEDG_0) /*!< CTC trim between CTCREF rising and CTCREF failing */
  151. #define CTC_CTCREF_FALLING_RISING (CTC_CR1_REFEDG_1) /*!< CTC trim between CTCREF failing and CTCREF rising */
  152. #define CTC_CTCREF_FALLING_FALLING (CTC_CR1_REFEDG) /*!< CTC trim between CTCREF failing and CTCREF failing */
  153. /**
  154. * @}
  155. */
  156. /**
  157. * @}
  158. */
  159. /*******************************************************************************
  160. * Global variable definitions ('extern')
  161. ******************************************************************************/
  162. /*******************************************************************************
  163. Global function prototypes (definition in C source)
  164. ******************************************************************************/
  165. /**
  166. * @addtogroup CTC_Global_Functions
  167. * @{
  168. */
  169. /**
  170. * @brief Start CTC trimming.
  171. * @param None
  172. * @retval None
  173. */
  174. __STATIC_INLINE void CTC_Start(void)
  175. {
  176. SET_REG32_BIT(CM_CTC->CR1, CTC_CR1_CTCEN);
  177. }
  178. /**
  179. * @brief Stop CTC trimming.
  180. * @param None
  181. * @retval None
  182. */
  183. __STATIC_INLINE void CTC_Stop(void)
  184. {
  185. CLR_REG32_BIT(CM_CTC->CR1, CTC_CR1_CTCEN);
  186. }
  187. int32_t CTC_CT_StructInit(stc_ctc_ct_init_t *pstcCtcInit);
  188. int32_t CTC_CT_Init(const stc_ctc_ct_init_t *pstcCtcInit);
  189. int32_t CTC_ST_StructInit(stc_ctc_st_init_t *pstcCtcInit);
  190. int32_t CTC_ST_Init(const stc_ctc_st_init_t *pstcCtcInit);
  191. int32_t CTC_DeInit(void);
  192. void CTC_IntCmd(en_functional_state_t enNewState);
  193. en_flag_status_t CTC_GetStatus(uint32_t u32Flag);
  194. void CTC_SetTrimValue(uint8_t u8TrimValue);
  195. uint8_t CTC_GetTrimValue(void);
  196. void CTC_SetReloadValue(uint16_t u16ReloadValue);
  197. uint16_t CTC_GetReloadValue(void);
  198. void CTC_SetOffsetValue(uint8_t u8OffsetValue);
  199. uint8_t CTC_GetOffsetValue(void);
  200. uint16_t CTC_GetCountValue(void);
  201. /**
  202. * @}
  203. */
  204. #endif /* LL_CTC_ENABLE */
  205. /**
  206. * @}
  207. */
  208. /**
  209. * @}
  210. */
  211. #ifdef __cplusplus
  212. }
  213. #endif
  214. #endif /* __HC32_LL_CTC_H__ */
  215. /*******************************************************************************
  216. * EOF (not truncated)
  217. ******************************************************************************/