hc32l196_trim.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /******************************************************************************
  2. * Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
  3. *
  4. * This software is owned and published by:
  5. * Huada Semiconductor Co.,Ltd ("HDSC").
  6. *
  7. * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
  8. * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
  9. *
  10. * This software contains source code for use with HDSC
  11. * components. This software is licensed by HDSC to be adapted only
  12. * for use in systems utilizing HDSC components. HDSC shall not be
  13. * responsible for misuse or illegal use of this software for devices not
  14. * supported herein. HDSC is providing this software "AS IS" and will
  15. * not be responsible for issues arising from incorrect user implementation
  16. * of the software.
  17. *
  18. * Disclaimer:
  19. * HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
  20. * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
  21. * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
  22. * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
  23. * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
  24. * WARRANTY OF NONINFRINGEMENT.
  25. * HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
  26. * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
  27. * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
  28. * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
  29. * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
  30. * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
  31. * SAVINGS OR PROFITS,
  32. * EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  33. * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
  34. * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
  35. * FROM, THE SOFTWARE.
  36. *
  37. * This software may be replicated in part or whole for the licensed use,
  38. * with the restriction that this Disclaimer and Copyright notice must be
  39. * included with each copy of this software, whether used in part or whole,
  40. * at all times.
  41. */
  42. /*****************************************************************************/
  43. /** \file trim.h
  44. **
  45. ** TRIM 数据结构及API声明
  46. **
  47. **
  48. ** History:
  49. ** - 2018-04-21 Lux V1.0
  50. **
  51. *****************************************************************************/
  52. #ifndef __TRIM_H__
  53. #define __TRIM_H__
  54. /*****************************************************************************
  55. * Include files
  56. *****************************************************************************/
  57. #include "ddl.h"
  58. #ifdef __cplusplus
  59. extern "C"
  60. {
  61. #endif
  62. /**
  63. ******************************************************************************
  64. ** \defgroup TrimGroup Clock Trimming (TRIM)
  65. **
  66. ******************************************************************************/
  67. //@{
  68. /******************************************************************************
  69. ** Global pre-processor symbols/macros ('#define')
  70. ******************************************************************************/
  71. /******************************************************************************
  72. * Global type definitions
  73. ******************************************************************************/
  74. /**
  75. ******************************************************************************
  76. ** \brief 监测模式使能枚举重定义 (MON_EN)
  77. *****************************************************************************/
  78. typedef enum en_trim_monitor
  79. {
  80. TrimMonDisable = 0u, ///< 禁止
  81. TrimMonEnable = 0x40u, ///< 使能
  82. }en_trim_monitor_t;
  83. /**
  84. ******************************************************************************
  85. ** \brief 待校准/监测时钟选择枚举重定义 (CALCLK_SEL)
  86. *****************************************************************************/
  87. typedef enum en_trim_calclksel
  88. {
  89. TrimCalMskRCH = 0x000u, ///< RCH
  90. TrimCalMskXTH = 0x010u, ///< XTH
  91. TrimCalMskRCL = 0x020u, ///< RCL
  92. TrimCalMskXTL = 0x030u, ///< XTL
  93. TrimCalMskPLL = 0x100u, ///< PLL
  94. }en_trim_calclksel_t;
  95. /**
  96. ******************************************************************************
  97. ** \brief 参考时钟选择枚举重定义 (REFCLK_SEL)
  98. *****************************************************************************/
  99. typedef enum en_trim_refclksel
  100. {
  101. TrimRefMskRCH = 0x0u, ///< RCH
  102. TrimRefMskXTH = 0x2u, ///< XTH
  103. TrimRefMskRCL = 0x4u, ///< RCL
  104. TrimRefMskXTL = 0x6u, ///< XTL
  105. TrimRefMskIRC10K = 0x8u, ///< IRC10K
  106. TrimRefMskExtClk = 0xau, ///< 外部输入时钟
  107. }en_trim_refclksel_t;
  108. /**
  109. ******************************************************************************
  110. ** \brief 中断标志类型枚举重定义
  111. *****************************************************************************/
  112. typedef enum en_trim_inttype
  113. {
  114. TrimStop = 0x01u, ///< 参考计数器停止标志
  115. TrimCalCntOf = 0x02u, ///< 校准计数器溢出标志
  116. TrimXTLFault = 0x04u, ///< XTL 失效标志
  117. TrimXTHFault = 0x08u, ///< XTH 失效标志
  118. TrimPLLFault = 0x10u, ///< PLL 失效标志
  119. }en_trim_inttype_t;
  120. /**
  121. ******************************************************************************
  122. ** \brief TRIM 配置结构体定义
  123. *****************************************************************************/
  124. typedef struct stc_trim_cfg
  125. {
  126. en_trim_monitor_t enMON; ///< 监测模式使能
  127. en_trim_calclksel_t enCALCLK; ///< 校准时钟选择
  128. uint32_t u32CalCon; ///< 校准计数器溢出值配置
  129. en_trim_refclksel_t enREFCLK; ///< 参考时钟选择
  130. uint32_t u32RefCon; ///< 参考计数器初值配置
  131. }stc_trim_cfg_t;
  132. /******************************************************************************
  133. * Global variable declarations ('extern', definition in C source)
  134. *****************************************************************************/
  135. /******************************************************************************
  136. * Global function prototypes (definition in C source)
  137. *****************************************************************************/
  138. ///<<功能配置及操作函数
  139. ///<Trim 配置及初始化
  140. en_result_t Trim_Init(stc_trim_cfg_t* pstcCfg);
  141. ///<校准/监测启动/停止
  142. void Trim_Run(void);
  143. void Trim_Stop(void);
  144. ///<参考计数器计数值获取
  145. uint32_t Trim_RefCntGet(void);
  146. ///<校准计数器计数值获取
  147. uint32_t Trim_CalCntGet(void);
  148. ///<中断操作相关函数
  149. ///中断使能/禁止
  150. void Trim_EnableIrq(void);
  151. void Trim_DisableIrq(void);
  152. ///<中断标志获取
  153. boolean_t Trim_GetIntFlag(en_trim_inttype_t enIntType);
  154. ///<中断标志清除
  155. en_result_t Trim_ClearIntFlag(en_trim_inttype_t enIntType);
  156. //@} // TrimGroup
  157. #ifdef __cplusplus
  158. #endif
  159. #endif /* __TRIM_H__ */
  160. /******************************************************************************
  161. * EOF (not truncated)
  162. *****************************************************************************/