pca.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 pca.h
  12. *
  13. * @brief Header file for PCA functions
  14. *
  15. * @author MADS Team
  16. *
  17. ******************************************************************************/
  18. #ifndef __PCA_H__
  19. #define __PCA_H__
  20. /*****************************************************************************
  21. * Include files
  22. *****************************************************************************/
  23. #include "ddl.h"
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. /**
  29. ******************************************************************************
  30. ** \defgroup PcaGroup Programmable Counter Array (PCA)
  31. **
  32. ******************************************************************************/
  33. //@{
  34. /******************************************************************************/
  35. /* Global pre-processor symbols/macros ('#define') */
  36. /******************************************************************************/
  37. /******************************************************************************
  38. * Global type definitions
  39. ******************************************************************************/
  40. /**
  41. *******************************************************************************
  42. ** \brief PCA 模块选择
  43. ** \note
  44. ******************************************************************************/
  45. typedef enum
  46. {
  47. PcaModule0 = 0, // PCA_0
  48. PcaModule1 = 1, // PCA_1
  49. PcaModule2 = 2, // PCA_2
  50. PcaModule3 = 3, // PCA_3
  51. PcaModule4 = 4 // PCA_4
  52. }en_pca_module_t;
  53. /**
  54. *******************************************************************************
  55. ** \brief PCA 中断标志位 中断清除位
  56. ** \note PCA_CCON中的CCF0-CCF4与CF; PCA_ICLR中的CCF0-CCF4与CF
  57. ******************************************************************************/
  58. typedef enum
  59. {
  60. PcaCcf0 = 0,
  61. PcaCcf1 = 1,
  62. PcaCcf2 = 2,
  63. PcaCcf3 = 3,
  64. PcaCcf4 = 4,
  65. PcaCf = 7
  66. }en_pca_ccficlr_t;
  67. /**
  68. *******************************************************************************
  69. ** \brief PCA 时钟分频选择及时钟源选择
  70. ** \note PCA_CMOD CPS[2:0]
  71. ******************************************************************************/
  72. typedef enum
  73. {
  74. PcaPclkdiv32 = 0, // PCLK/32
  75. PcaPclkdiv16 = 1, // PCLK/16
  76. PcaPclkdiv8 = 2, // PCLK/8
  77. PcaPclkdiv4 = 3, // PCLK/4
  78. PcaPclkdiv2 = 4, // PCLK/2
  79. PcaTim0ovf = 5, // timer0 overflow
  80. PcaTim1ovf = 6, // timer1 overflow
  81. PcaEci = 7 // ECI外部时钟
  82. }en_pca_clksrc_t;
  83. /**
  84. *******************************************************************************
  85. ** \brief PCA 允许比较器功能控制
  86. ** \note PCA_CCAPMx ECOM
  87. ******************************************************************************/
  88. typedef enum
  89. {
  90. PcaEcomDisable = 0,
  91. PcaEcomEnable = 1
  92. }en_pca_ecom_t;
  93. /**
  94. *******************************************************************************
  95. ** \brief PCA 正沿捕获控制位
  96. ** \note PCA_CCAPMx CAPP
  97. ******************************************************************************/
  98. typedef enum
  99. {
  100. PcaCappDisable = 0,
  101. PcaCappEnable = 1
  102. }en_pca_capp_t;
  103. /**
  104. *******************************************************************************
  105. ** \brief PCA 负沿捕获控制位
  106. ** \note PCA_CCAPMx CAPN
  107. ******************************************************************************/
  108. typedef enum
  109. {
  110. PcaCapnDisable = 0,
  111. PcaCapnEnable = 1
  112. }en_pca_capn_t;
  113. /**
  114. *******************************************************************************
  115. ** \brief PCA 匹配控制位
  116. ** \note PCA_CCAPMx MAT
  117. ******************************************************************************/
  118. typedef enum
  119. {
  120. PcaMatDisable = 0,
  121. PcaMatEnable = 1
  122. }en_pca_mat_t;
  123. /**
  124. *******************************************************************************
  125. ** \brief PCA 翻转控制位
  126. ** \note PCA_CCAPMx TOG
  127. ******************************************************************************/
  128. typedef enum
  129. {
  130. PcaTogDisable = 0,
  131. PcaTogEnable = 1
  132. }en_pca_tog_t;
  133. /**
  134. *******************************************************************************
  135. ** \brief PCA PWM控制位
  136. ** \note PCA_CCAPMx PWM
  137. ******************************************************************************/
  138. typedef enum
  139. {
  140. PcaPwm8bitDisable = 0,
  141. PcaPwm8bitEnable = 1
  142. }en_pca_pwm8bit_t;
  143. /**
  144. *******************************************************************************
  145. ** \brief PCA EPWM控制位
  146. ** \note PCA_EPWM EPWM
  147. ******************************************************************************/
  148. typedef enum
  149. {
  150. PcaEpwmDisable = 0,
  151. PcaEpwmEnable = 1
  152. }en_pca_epwm_t;
  153. /**
  154. *******************************************************************************
  155. ** \brief PCA 初始化配置的结构体
  156. ** \note
  157. ******************************************************************************/
  158. typedef struct
  159. {
  160. en_pca_clksrc_t pca_clksrc; // PCA_CMOD CPS[2:0]
  161. boolean_t pca_cidl; // PCA_CMOD CIDL
  162. en_pca_ecom_t pca_ecom; // PCA_CCAPMx ECOM
  163. en_pca_capp_t pca_capp; // PCA_CCAPMx CAPP
  164. en_pca_capn_t pca_capn; // PCA_CCAPMx CAPN
  165. en_pca_mat_t pca_mat; // PCA_CCAPMx MAT
  166. en_pca_tog_t pca_tog; // PCA_CCAPMx TOG
  167. en_pca_pwm8bit_t pca_pwm; // PCA_CCAPMx PWM
  168. en_pca_epwm_t pca_epwm; // PCA_EPWM
  169. uint16_t pca_ccap; // PCA_CCAP
  170. uint8_t pca_ccapl; // PCA_CCAPL PCA_CCAP的低字节
  171. uint8_t pca_ccaph; // PCA_CCAPH PCA_CCAP的高字节
  172. uint16_t pca_carr; // PCA_CARR
  173. }stc_pcacfg_t;
  174. /******************************************************************************
  175. * Global variable declarations ('extern', definition in C source)
  176. *****************************************************************************/
  177. /******************************************************************************
  178. * Global function prototypes (definition in C source)
  179. *****************************************************************************/
  180. extern boolean_t Pca_GetItStatus(en_pca_ccficlr_t It_Src);
  181. extern void Pca_ClrItStatus(en_pca_ccficlr_t It_Src);
  182. extern void Pca_StartPca(boolean_t NewStatus);
  183. extern void Pca_SetCidl(boolean_t NewStatus);
  184. extern void Pca_Set4Wdte(boolean_t NewStatus);
  185. extern void Pca_ConfPcaIt(boolean_t NewStatus);
  186. extern void Pca_ConfModulexIt(en_pca_module_t Modulex, boolean_t NewStatus);
  187. extern void Pca_M0Init(stc_pcacfg_t* InitStruct);
  188. extern void Pca_M1Init(stc_pcacfg_t* InitStruct);
  189. extern void Pca_M2Init(stc_pcacfg_t* InitStruct);
  190. extern void Pca_M3Init(stc_pcacfg_t* InitStruct);
  191. extern void Pca_M4Init(stc_pcacfg_t* InitStruct);
  192. extern uint16_t Pca_GetCnt(void);
  193. extern void Pca_SetCnt(uint16_t cnt);
  194. extern boolean_t Pca_GetOut(en_pca_module_t Modulex);
  195. extern void Pca_SetCcap(en_pca_module_t Modulex, uint16_t Value);
  196. extern uint16_t Pca_GetCcap(en_pca_module_t Modulex);
  197. extern void Pca_SetCarr(uint16_t Value);
  198. extern uint16_t Pca_GetCarr(void);
  199. extern void Pca_SetCcapHL(en_pca_module_t Modulex, uint8_t ValueH, uint8_t ValueL);
  200. extern void Pca_GetCcapHL(en_pca_module_t Modulex, uint8_t *ValueH, uint8_t *ValueL);
  201. //@} // PcaGroup
  202. #ifdef __cplusplus
  203. #endif
  204. #endif /* __PCA_H__ */
  205. /******************************************************************************
  206. * EOF (not truncated)
  207. *****************************************************************************/