summaryrefslogtreecommitdiff
path: root/bsp/hc32l196/libraries/HC32L196_StdPeriph_Driver/inc/hc32l196_pca.h
blob: e96a24f8ef7cb6489eff54ce5842f1937ff13adc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/******************************************************************************
* Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file pca.h
 **
 ** PCA(可编程计数阵列)数据结构及API声明
 **  
 **
 ** History:
 **   - 2019-04-09        First version
 **
 *****************************************************************************/

#ifndef __PCA_H__
#define __PCA_H__

/*****************************************************************************
 * Include files
 *****************************************************************************/
#include "ddl.h"

#ifdef __cplusplus
extern "C"
{
#endif

/**
 ******************************************************************************
 ** \defgroup PcaGroup Programmable Counter Array (PCA)
 **
 ******************************************************************************/
//@{

/******************************************************************************/
/* Global pre-processor symbols/macros ('#define')                            */
/******************************************************************************/

/******************************************************************************
 * Global type definitions
 ******************************************************************************/
/**
 *******************************************************************************
 ** \brief PCA  模块选择
 ** \note 
 ******************************************************************************/
typedef enum
{
    PcaModule0 = 0,      //  PCA_0
    PcaModule1 = 1,      //  PCA_1
    PcaModule2 = 2,      //  PCA_2
    PcaModule3 = 3,      //  PCA_3
    PcaModule4 = 4       //  PCA_4
}en_pca_module_t;

/**
 *******************************************************************************
 ** \brief PCA  中断标志位  中断清除位
 ** \note           PCA_CCON中的CCF0-CCF4与CF; PCA_ICLR中的CCF0-CCF4与CF
 ******************************************************************************/
typedef enum
{
    PcaCcf0 = 0,
    PcaCcf1 = 1,
    PcaCcf2 = 2,
    PcaCcf3 = 3,
    PcaCcf4 = 4,
    PcaCf   = 7
}en_pca_ccficlr_t;

/**
 *******************************************************************************
 ** \brief PCA  时钟分频选择及时钟源选择
 ** \note       PCA_CMOD   CPS[2:0]
 ******************************************************************************/
typedef enum
{
    PcaPclkdiv32 = 0,      // PCLK/32
    PcaPclkdiv16 = 1,      // PCLK/16
    PcaPclkdiv8  = 2,      // PCLK/8
    PcaPclkdiv4  = 3,      // PCLK/4
    PcaPclkdiv2  = 4,      // PCLK/2
    PcaTim0ovf   = 5,      // timer0 overflow
    PcaTim1ovf   = 6,      // timer1 overflow
    PcaEci       = 7       // ECI外部时钟
}en_pca_clksrc_t;

/**
 *******************************************************************************
 ** \brief PCA  允许比较器功能控制
 ** \note       PCA_CCAPMx   ECOM
 ******************************************************************************/
typedef enum
{
    PcaEcomDisable = 0,
    PcaEcomEnable  = 1
}en_pca_ecom_t;

/**
 *******************************************************************************
 ** \brief PCA  正沿捕获控制位
 ** \note       PCA_CCAPMx  CAPP
 ******************************************************************************/
typedef enum
{
    PcaCappDisable = 0,
    PcaCappEnable  = 1
}en_pca_capp_t;

/**
 *******************************************************************************
 ** \brief PCA  负沿捕获控制位
 ** \note       PCA_CCAPMx  CAPN
 ******************************************************************************/
typedef enum
{
    PcaCapnDisable = 0,
    PcaCapnEnable  = 1
}en_pca_capn_t;

/**
 *******************************************************************************
 ** \brief PCA  匹配控制位
 ** \note       PCA_CCAPMx  MAT
 ******************************************************************************/
typedef enum
{
    PcaMatDisable = 0,
    PcaMatEnable  = 1
}en_pca_mat_t;

/**
 *******************************************************************************
 ** \brief PCA  翻转控制位
 ** \note       PCA_CCAPMx  TOG
 ******************************************************************************/
typedef enum
{
    PcaTogDisable = 0,
    PcaTogEnable  = 1
}en_pca_tog_t;

/**
 *******************************************************************************
 ** \brief PCA  PWM控制位
 ** \note       PCA_CCAPMx  PWM
 ******************************************************************************/
typedef enum
{
    PcaPwm8bitDisable = 0,
    PcaPwm8bitEnable  = 1
}en_pca_pwm8bit_t;

/**
 *******************************************************************************
 ** \brief PCA  EPWM控制位
 ** \note       PCA_EPWM  EPWM
 ******************************************************************************/
typedef enum
{
    PcaEpwmDisable = 0,
    PcaEpwmEnable  = 1
}en_pca_epwm_t;

/**
 *******************************************************************************
 ** \brief PCA  初始化配置的结构体
 ** \note       
 ******************************************************************************/
typedef struct
{
    en_pca_clksrc_t     pca_clksrc;           // PCA_CMOD CPS[2:0] 
    boolean_t           pca_cidl;             // PCA_CMOD CIDL
    en_pca_ecom_t       pca_ecom;             // PCA_CCAPMx ECOM
    en_pca_capp_t       pca_capp;             // PCA_CCAPMx CAPP
    en_pca_capn_t       pca_capn;             // PCA_CCAPMx CAPN
    en_pca_mat_t        pca_mat;              // PCA_CCAPMx MAT
    en_pca_tog_t        pca_tog;              // PCA_CCAPMx TOG
    en_pca_pwm8bit_t    pca_pwm;              // PCA_CCAPMx PWM
    en_pca_epwm_t       pca_epwm;             // PCA_EPWM
    uint16_t            pca_ccap;             // PCA_CCAP
    uint8_t             pca_ccapl;            // PCA_CCAPL  PCA_CCAP的低字节
    uint8_t             pca_ccaph;            // PCA_CCAPH  PCA_CCAP的高字节
    uint16_t            pca_carr;             // PCA_CARR
}stc_pcacfg_t;
/******************************************************************************
 * Global variable declarations ('extern', definition in C source)
 *****************************************************************************/

/******************************************************************************
 * Global function prototypes (definition in C source)
 *****************************************************************************/
extern boolean_t Pca_GetItStatus(en_pca_ccficlr_t It_Src);
extern void Pca_ClrItStatus(en_pca_ccficlr_t It_Src);
extern void Pca_StartPca(boolean_t NewStatus);
extern void Pca_SetCidl(boolean_t NewStatus);
extern void Pca_Set4Wdte(boolean_t NewStatus);
extern void Pca_ConfPcaIt(boolean_t NewStatus);
extern void Pca_ConfModulexIt(en_pca_module_t Modulex, boolean_t NewStatus);
extern void Pca_M0Init(stc_pcacfg_t* InitStruct);
extern void Pca_M1Init(stc_pcacfg_t* InitStruct);
extern void Pca_M2Init(stc_pcacfg_t* InitStruct);
extern void Pca_M3Init(stc_pcacfg_t* InitStruct);
extern void Pca_M4Init(stc_pcacfg_t* InitStruct);
extern uint16_t Pca_GetCnt(void);
extern void Pca_SetCnt(uint16_t cnt);
extern boolean_t Pca_GetOut(en_pca_module_t Modulex);
extern void Pca_SetCcap(en_pca_module_t Modulex, uint16_t Value);
extern uint16_t Pca_GetCcap(en_pca_module_t Modulex);
extern void Pca_SetCarr(uint16_t Value);
extern uint16_t Pca_GetCarr(void);
extern void Pca_SetCcapHL(en_pca_module_t Modulex, uint8_t ValueH, uint8_t ValueL);
extern void Pca_GetCcapHL(en_pca_module_t Modulex, uint8_t *ValueH, uint8_t *ValueL);

//@} // PcaGroup

#ifdef __cplusplus
#endif

#endif /* __PCA_H__ */
/******************************************************************************
 * EOF (not truncated)
 *****************************************************************************/