hc32l196_pca.h 9.7 KB

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