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