trim.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /******************************************************************************
  2. * Copyright (C) 2021, Xiaohua Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by XHSC 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. /******************************************************************************
  11. * @file trim.h
  12. *
  13. * @brief Header file for TRIM functions
  14. *
  15. * @author MADS Team
  16. *
  17. ******************************************************************************/
  18. #ifndef __TRIM_H__
  19. #define __TRIM_H__
  20. /*****************************************************************************
  21. * Include files
  22. *****************************************************************************/
  23. #include "ddl.h"
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. /**
  29. ******************************************************************************
  30. ** \defgroup TrimGroup Clock Trimming (TRIM)
  31. **
  32. ******************************************************************************/
  33. //@{
  34. /******************************************************************************
  35. ** Global pre-processor symbols/macros ('#define')
  36. ******************************************************************************/
  37. /******************************************************************************
  38. * Global type definitions
  39. ******************************************************************************/
  40. /**
  41. ******************************************************************************
  42. ** \brief 监测模式使能枚举重定义 (MON_EN)
  43. *****************************************************************************/
  44. typedef enum en_trim_monitor
  45. {
  46. TrimMonDisable = 0u, ///< 禁止
  47. TrimMonEnable = 0x40u, ///< 使能
  48. }en_trim_monitor_t;
  49. /**
  50. ******************************************************************************
  51. ** \brief 待校准/监测时钟选择枚举重定义 (CALCLK_SEL)
  52. *****************************************************************************/
  53. typedef enum en_trim_calclksel
  54. {
  55. TrimCalMskRCH = 0x000u, ///< RCH
  56. TrimCalMskXTH = 0x010u, ///< XTH
  57. TrimCalMskRCL = 0x020u, ///< RCL
  58. TrimCalMskXTL = 0x030u, ///< XTL
  59. TrimCalMskPLL = 0x100u, ///< PLL
  60. }en_trim_calclksel_t;
  61. /**
  62. ******************************************************************************
  63. ** \brief 参考时钟选择枚举重定义 (REFCLK_SEL)
  64. *****************************************************************************/
  65. typedef enum en_trim_refclksel
  66. {
  67. TrimRefMskRCH = 0x0u, ///< RCH
  68. TrimRefMskXTH = 0x2u, ///< XTH
  69. TrimRefMskRCL = 0x4u, ///< RCL
  70. TrimRefMskXTL = 0x6u, ///< XTL
  71. TrimRefMskIRC10K = 0x8u, ///< IRC10K
  72. TrimRefMskExtClk = 0xau, ///< 外部输入时钟
  73. }en_trim_refclksel_t;
  74. /**
  75. ******************************************************************************
  76. ** \brief 中断标志类型枚举重定义
  77. *****************************************************************************/
  78. typedef enum en_trim_inttype
  79. {
  80. TrimStop = 0x01u, ///< 参考计数器停止标志
  81. TrimCalCntOf = 0x02u, ///< 校准计数器溢出标志
  82. TrimXTLFault = 0x04u, ///< XTL 失效标志
  83. TrimXTHFault = 0x08u, ///< XTH 失效标志
  84. TrimPLLFault = 0x10u, ///< PLL 失效标志
  85. }en_trim_inttype_t;
  86. /**
  87. ******************************************************************************
  88. ** \brief TRIM 配置结构体定义
  89. *****************************************************************************/
  90. typedef struct stc_trim_cfg
  91. {
  92. en_trim_monitor_t enMON; ///< 监测模式使能
  93. en_trim_calclksel_t enCALCLK; ///< 校准时钟选择
  94. uint32_t u32CalCon; ///< 校准计数器溢出值配置
  95. en_trim_refclksel_t enREFCLK; ///< 参考时钟选择
  96. uint32_t u32RefCon; ///< 参考计数器初值配置
  97. }stc_trim_cfg_t;
  98. /******************************************************************************
  99. * Global variable declarations ('extern', definition in C source)
  100. *****************************************************************************/
  101. /******************************************************************************
  102. * Global function prototypes (definition in C source)
  103. *****************************************************************************/
  104. ///<<功能配置及操作函数
  105. ///<Trim 配置及初始化
  106. en_result_t Trim_Init(stc_trim_cfg_t* pstcCfg);
  107. ///<校准/监测启动/停止
  108. void Trim_Run(void);
  109. void Trim_Stop(void);
  110. ///<参考计数器计数值获取
  111. uint32_t Trim_RefCntGet(void);
  112. ///<校准计数器计数值获取
  113. uint32_t Trim_CalCntGet(void);
  114. ///<中断操作相关函数
  115. ///中断使能/禁止
  116. void Trim_EnableIrq(void);
  117. void Trim_DisableIrq(void);
  118. ///<中断标志获取
  119. boolean_t Trim_GetIntFlag(en_trim_inttype_t enIntType);
  120. ///<中断标志清除
  121. en_result_t Trim_ClearIntFlag(en_trim_inttype_t enIntType);
  122. //@} // TrimGroup
  123. #ifdef __cplusplus
  124. #endif
  125. #endif /* __TRIM_H__ */
  126. /******************************************************************************
  127. * EOF (not truncated)
  128. *****************************************************************************/