| M480 BSP V3.05.001 The Board Support Package for M480 Series

ecap.h
Go to the documentation of this file.
1 /**************************************************************************/
9 #ifndef __ECAP_H__
10 #define __ECAP_H__
11
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16
17
30 #define ECAP_IC0 (0UL)
31 #define ECAP_IC1 (1UL)
32 #define ECAP_IC2 (2UL)
34 /*---------------------------------------------------------------------------------------------------------*/
35 /* ECAP CTL0 constant definitions */
36 /*---------------------------------------------------------------------------------------------------------*/
37 #define ECAP_NOISE_FILTER_CLKDIV_1 (0UL<<ECAP_CTL0_NFCLKSEL_Pos)
38 #define ECAP_NOISE_FILTER_CLKDIV_2 (1UL<<ECAP_CTL0_NFCLKSEL_Pos)
39 #define ECAP_NOISE_FILTER_CLKDIV_4 (2UL<<ECAP_CTL0_NFCLKSEL_Pos)
40 #define ECAP_NOISE_FILTER_CLKDIV_16 (3UL<<ECAP_CTL0_NFCLKSEL_Pos)
41 #define ECAP_NOISE_FILTER_CLKDIV_32 (4UL<<ECAP_CTL0_NFCLKSEL_Pos)
42 #define ECAP_NOISE_FILTER_CLKDIV_64 (5UL<<ECAP_CTL0_NFCLKSEL_Pos)
45 #define ECAP_CAP_INPUT_SRC_FROM_IC (0UL)
46 #define ECAP_CAP_INPUT_SRC_FROM_CH (2UL)
48 #define ECAP_DISABLE_COMPARE (0UL<<ECAP_CTL0_CMPEN_Pos)
49 #define ECAP_COMPARE_FUNCTION (1UL<<ECAP_CTL0_CMPEN_Pos)
50 /*---------------------------------------------------------------------------------------------------------*/
51 /* ECAP CTL1 constant definitions */
52 /*---------------------------------------------------------------------------------------------------------*/
53 #define ECAP_RISING_EDGE (0UL<<ECAP_CTL1_EDGESEL0_Pos)
54 #define ECAP_FALLING_EDGE (1UL<<ECAP_CTL1_EDGESEL0_Pos)
55 #define ECAP_RISING_FALLING_EDGE (2UL<<ECAP_CTL1_EDGESEL0_Pos)
57 #define ECAP_CAPTURE_TIMER_CLKDIV_1 (0UL<<ECAP_CTL1_CLKSEL_Pos)
58 #define ECAP_CAPTURE_TIMER_CLKDIV_4 (1UL<<ECAP_CTL1_CLKSEL_Pos)
59 #define ECAP_CAPTURE_TIMER_CLKDIV_16 (2UL<<ECAP_CTL1_CLKSEL_Pos)
60 #define ECAP_CAPTURE_TIMER_CLKDIV_32 (3UL<<ECAP_CTL1_CLKSEL_Pos)
61 #define ECAP_CAPTURE_TIMER_CLKDIV_64 (4UL<<ECAP_CTL1_CLKSEL_Pos)
62 #define ECAP_CAPTURE_TIMER_CLKDIV_96 (5UL<<ECAP_CTL1_CLKSEL_Pos)
63 #define ECAP_CAPTURE_TIMER_CLKDIV_112 (6UL<<ECAP_CTL1_CLKSEL_Pos)
64 #define ECAP_CAPTURE_TIMER_CLKDIV_128 (7UL<<ECAP_CTL1_CLKSEL_Pos)
66 #define ECAP_CAPTURE_TIMER_CLK_SRC_CAP_CLK (0UL<<ECAP_CTL1_CNTSRCSEL_Pos)
67 #define ECAP_CAPTURE_TIMER_CLK_SRC_CAP0 (1UL<<ECAP_CTL1_CNTSRCSEL_Pos)
68 #define ECAP_CAPTURE_TIMER_CLK_SRC_CAP1 (2UL<<ECAP_CTL1_CNTSRCSEL_Pos)
69 #define ECAP_CAPTURE_TIMER_CLK_SRC_CAP2 (3UL<<ECAP_CTL1_CNTSRCSEL_Pos)
71 /* end of group ECAP_EXPORTED_CONSTANTS */
72
91 #define ECAP_SET_NOISE_FILTER_CLKDIV(ecap, u32ClkSel) ((ecap)->CTL0 = ((ecap)->CTL0 & ~ECAP_CTL0_NFCLKSEL_Msk)|(u32ClkSel))
92
100 #define ECAP_NOISE_FILTER_DISABLE(ecap) ((ecap)->CTL0 |= ECAP_CTL0_CAPNFDIS_Msk)
101
116 #define ECAP_NOISE_FILTER_ENABLE(ecap, u32ClkSel) ((ecap)->CTL0 = ((ecap)->CTL0 & ~(ECAP_CTL0_CAPNFDIS_Msk|ECAP_CTL0_NFCLKSEL_Msk))|(u32ClkSel))
117
129 #define ECAP_ENABLE_INPUT_CHANNEL(ecap, u32Mask) ((ecap)->CTL0 |= (u32Mask))
130
142 #define ECAP_DISABLE_INPUT_CHANNEL(ecap, u32Mask) ((ecap)->CTL0 &= ~(u32Mask))
143
158 #define ECAP_SEL_INPUT_SRC(ecap, u32Index, u32Src) ((ecap)->CTL0 = ((ecap)->CTL0 & ~(ECAP_CTL0_CAPSEL0_Msk<<((u32Index)<<1)))|(((u32Src)<<ECAP_CTL0_CAPSEL0_Pos)<<((u32Index)<<1)))
159
171 #define ECAP_ENABLE_INT(ecap, u32Mask) ((ecap)->CTL0 |= (u32Mask))
172
184 #define ECAP_DISABLE_INT(ecap, u32Mask) ((ecap)->CTL0 &= ~(u32Mask))
185
193 #define ECAP_ENABLE_OVF_INT(ecap) ((ecap)->CTL0 |= ECAP_CTL0_OVIEN_Msk)
194
202 #define ECAP_DISABLE_OVF_INT(ecap) ((ecap)->CTL0 &= ~ECAP_CTL0_OVIEN_Msk)
203
211 #define ECAP_ENABLE_CMP_MATCH_INT(ecap) ((ecap)->CTL0 |= ECAP_CTL0_CMPIEN_Msk)
212
220 #define ECAP_DISABLE_CMP_MATCH_INT(ecap) ((ecap)->CTL0 &= ~ECAP_CTL0_CMPIEN_Msk)
221
229 #define ECAP_CNT_START(ecap) ((ecap)->CTL0 |= ECAP_CTL0_CNTEN_Msk)
230
238 #define ECAP_CNT_STOP(ecap) ((ecap)->CTL0 &= ~ECAP_CTL0_CNTEN_Msk)
239
254 #define ECAP_SET_CNT_CLEAR_EVENT(ecap, u32Event) do{ \
255 if((u32Event) & ECAP_CTL0_CMPCLREN_Msk) \
256 (ecap)->CTL0 |= ECAP_CTL0_CMPCLREN_Msk; \
257 else \
258 (ecap)->CTL0 &= ~ECAP_CTL0_CMPCLREN_Msk; \
259 (ecap)->CTL1 = ((ecap)->CTL1 &~0xF00) | ((u32Event) & 0xF00); \
260 }while(0);
261
269 #define ECAP_ENABLE_CMP(ecap) ((ecap)->CTL0 |= ECAP_CTL0_CMPEN_Msk)
270
278 #define ECAP_DISABLE_CMP(ecap) ((ecap)->CTL0 &= ~ECAP_CTL0_CMPEN_Msk)
279
287 #define ECAP_ENABLE_CNT(ecap) ((ecap)->CTL0 |= ECAP_CTL0_CAPEN_Msk)
288
296 #define ECAP_DISABLE_CNT(ecap) ((ecap)->CTL0 &= ~ECAP_CTL0_CAPEN_Msk)
297
313 #define ECAP_SEL_CAPTURE_EDGE(ecap, u32Index, u32Edge) ((ecap)->CTL1 = ((ecap)->CTL1 & ~(ECAP_CTL1_EDGESEL0_Msk<<((u32Index)<<1)))|((u32Edge)<<((u32Index)<<1)))
314
327 #define ECAP_SEL_RELOAD_TRIG_SRC(ecap, u32TrigSrc) ((ecap)->CTL1 = ((ecap)->CTL1 & ~0xF00)|(u32TrigSrc))
328
345 #define ECAP_SEL_TIMER_CLK_DIV(ecap, u32Clkdiv) ((ecap)->CTL1 = ((ecap)->CTL1 & ~ECAP_CTL1_CLKSEL_Msk)|(u32Clkdiv))
346
359 #define ECAP_SEL_TIMER_CLK_SRC(ecap, u32ClkSrc) ((ecap)->CTL1 = ((ecap)->CTL1 & ~ECAP_CTL1_CNTSRCSEL_Msk)|(u32ClkSrc))
360
368 #define ECAP_GET_INT_STATUS(ecap) ((ecap)->STATUS)
369
383 #define ECAP_GET_CAPTURE_FLAG(ecap, u32Mask) (((ecap)->STATUS & (u32Mask))?1:0)
384
398 #define ECAP_CLR_CAPTURE_FLAG(ecap, u32Mask) ((ecap)->STATUS = (u32Mask))
399
408 #define ECAP_SET_CNT_VALUE(ecap, u32Val) ((ecap)->CNT = (u32Val))
409
417 #define ECAP_GET_CNT_VALUE(ecap) ((ecap)->CNT)
418
430 #define ECAP_GET_CNT_HOLD_VALUE(ecap, u32Index) (*(__IO uint32_t *) (&((ecap)->HLD0) + (u32Index)))
431
440 #define ECAP_SET_CNT_CMP(ecap, u32Val) ((ecap)->CNTCMP = (u32Val))
441
442 void ECAP_Open(ECAP_T* ecap, uint32_t u32FuncMask);
443 void ECAP_Close(ECAP_T* ecap);
444 void ECAP_EnableINT(ECAP_T* ecap, uint32_t u32Mask);
445 void ECAP_DisableINT(ECAP_T* ecap, uint32_t u32Mask); /* end of group ECAP_EXPORTED_FUNCTIONS */
447 /* end of group ECAP_Driver */
449 /* end of group Standard_Driver */
451
452 #ifdef __cplusplus
453 }
454 #endif
455
456 #endif /* __ECAP_H__ */
457
458 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
ECAP_Open
void ECAP_Open(ECAP_T *ecap, uint32_t u32FuncMask)
Enable ECAP function.
Definition: ecap.c:33
ECAP_T
Definition: ecap_reg.h:26
ECAP_EnableINT
void ECAP_EnableINT(ECAP_T *ecap, uint32_t u32Mask)
This macro is used to enable input channel interrupt.
Definition: ecap.c:68
ECAP_Close
void ECAP_Close(ECAP_T *ecap)
Disable ECAP function.
Definition: ecap.c:50
ECAP_DisableINT
void ECAP_DisableINT(ECAP_T *ecap, uint32_t u32Mask)
This macro is used to disable input channel interrupt.
Definition: ecap.c:96