26 #ifndef __LPC17XX_TIMER_H_
27 #define __LPC17XX_TIMER_H_
48 #define TIM_IR_CLR(n) _BIT(n)
54 #define TIM_MATCH_INT(n) (_BIT(n & 0x0F))
56 #define TIM_CAP_INT(n) (_BIT(((n & 0x0F) + 4)))
62 #define TIM_ENABLE ((uint32_t)(1<<0))
64 #define TIM_RESET ((uint32_t)(1<<1))
66 #define TIM_TCR_MASKBIT ((uint32_t)(3))
72 #define TIM_INT_ON_MATCH(n) (_BIT((n * 3)))
74 #define TIM_RESET_ON_MATCH(n) (_BIT(((n * 3) + 1)))
76 #define TIM_STOP_ON_MATCH(n) (_BIT(((n * 3) + 2)))
78 #define TIM_MCR_MASKBIT ((uint32_t)(0x0FFF))
80 #define TIM_MCR_CHANNEL_MASKBIT(n) ((uint32_t)(7<<(n*3)))
86 #define TIM_CAP_RISING(n) (_BIT((n * 3)))
88 #define TIM_CAP_FALLING(n) (_BIT(((n * 3) + 1)))
90 #define TIM_INT_ON_CAP(n) (_BIT(((n * 3) + 2)))
92 #define TIM_EDGE_MASK(n) (_SBF((n * 3), 0x03))
94 #define TIM_CCR_MASKBIT ((uint32_t)(0x3F))
96 #define TIM_CCR_CHANNEL_MASKBIT(n) ((uint32_t)(7<<(n*3)))
103 #define TIM_EM(n) _BIT(n)
105 #define TIM_EM_NOTHING ((uint8_t)(0x0))
107 #define TIM_EM_LOW ((uint8_t)(0x1))
109 #define TIM_EM_HIGH ((uint8_t)(0x2))
111 #define TIM_EM_TOGGLE ((uint8_t)(0x3))
113 #define TIM_EM_SET(n,s) (_SBF(((n << 1) + 4), (s & 0x03)))
115 #define TIM_EM_MASK(n) (_SBF(((n << 1) + 4), 0x03))
117 #define TIM_EMR_MASKBIT 0x0FFF
123 #define TIM_CTCR_MODE_MASK 0x3
125 #define TIM_CTCR_INPUT_MASK 0xC
127 #define TIM_CTCR_MASKBIT 0xF
128 #define TIM_COUNTER_MODE ((uint8_t)(1))
133 #define PARAM_TIMx(n) ((((uint32_t *)n)==((uint32_t *)LPC_TIM0)) || (((uint32_t *)n)==((uint32_t *)LPC_TIM1)) \
134 || (((uint32_t *)n)==((uint32_t *)LPC_TIM2)) || (((uint32_t *)n)==((uint32_t *)LPC_TIM3)))
137 #define PARAM_TIM_INT_TYPE(TYPE) ((TYPE ==TIM_MR0_INT)||(TYPE ==TIM_MR1_INT)\
138 ||(TYPE ==TIM_MR2_INT)||(TYPE ==TIM_MR3_INT)\
139 ||(TYPE ==TIM_CR0_INT)||(TYPE ==TIM_CR1_INT))
142 #define PARAM_TIM_MODE_OPT(MODE) ((MODE == TIM_TIMER_MODE)||(MODE == TIM_COUNTER_RISING_MODE)\
143 || (MODE == TIM_COUNTER_RISING_MODE)||(MODE == TIM_COUNTER_RISING_MODE))
146 #define PARAM_TIM_PRESCALE_OPT(OPT) ((OPT == TIM_PRESCALE_TICKVAL)||(OPT == TIM_PRESCALE_USVAL))
149 #define PARAM_TIM_COUNTER_INPUT_OPT(OPT) ((OPT == TIM_COUNTER_INCAP0)||(OPT == TIM_COUNTER_INCAP1))
152 #define PARAM_TIM_EXTMATCH_OPT(OPT) ((OPT == TIM_EXTMATCH_NOTHING)||(OPT == TIM_EXTMATCH_LOW)\
153 ||(OPT == TIM_EXTMATCH_HIGH)||(OPT == TIM_EXTMATCH_TOGGLE))
156 #define PARAM_TIM_CAP_MODE_OPT(OPT) ((OPT == TIM_CAPTURE_NONE)||(OPT == TIM_CAPTURE_RISING) \
157 ||(OPT == TIM_CAPTURE_FALLING)||(OPT == TIM_CAPTURE_ANY))