uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpc17xx_timer.h
Go to the documentation of this file.
1 /***********************************************************************/
20 /* Peripheral group ----------------------------------------------------------- */
26 #ifndef __LPC17XX_TIMER_H_
27 #define __LPC17XX_TIMER_H_
28 
29 /* Includes ------------------------------------------------------------------- */
30 #include "LPC17xx.h"
31 #include "lpc_types.h"
32 
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37 
38 /* Private Macros ------------------------------------------------------------- */
43 /* --------------------- BIT DEFINITIONS -------------------------------------- */
44 /**********************************************************************
45 ** Interrupt information
46 **********************************************************************/
48 #define TIM_IR_CLR(n) _BIT(n)
49 
50 /**********************************************************************
51 ** Timer interrupt register definitions
52 **********************************************************************/
54 #define TIM_MATCH_INT(n) (_BIT(n & 0x0F))
55 
56 #define TIM_CAP_INT(n) (_BIT(((n & 0x0F) + 4)))
57 
58 /**********************************************************************
59 * Timer control register definitions
60 **********************************************************************/
62 #define TIM_ENABLE ((uint32_t)(1<<0))
63 
64 #define TIM_RESET ((uint32_t)(1<<1))
65 
66 #define TIM_TCR_MASKBIT ((uint32_t)(3))
67 
68 /**********************************************************************
69 * Timer match control register definitions
70 **********************************************************************/
72 #define TIM_INT_ON_MATCH(n) (_BIT((n * 3)))
73 
74 #define TIM_RESET_ON_MATCH(n) (_BIT(((n * 3) + 1)))
75 
76 #define TIM_STOP_ON_MATCH(n) (_BIT(((n * 3) + 2)))
77 
78 #define TIM_MCR_MASKBIT ((uint32_t)(0x0FFF))
79 
80 #define TIM_MCR_CHANNEL_MASKBIT(n) ((uint32_t)(7<<(n*3)))
81 
82 /**********************************************************************
83 * Timer capture control register definitions
84 **********************************************************************/
86 #define TIM_CAP_RISING(n) (_BIT((n * 3)))
87 
88 #define TIM_CAP_FALLING(n) (_BIT(((n * 3) + 1)))
89 
90 #define TIM_INT_ON_CAP(n) (_BIT(((n * 3) + 2)))
91 
92 #define TIM_EDGE_MASK(n) (_SBF((n * 3), 0x03))
93 
94 #define TIM_CCR_MASKBIT ((uint32_t)(0x3F))
95 
96 #define TIM_CCR_CHANNEL_MASKBIT(n) ((uint32_t)(7<<(n*3)))
97 
98 /**********************************************************************
99 * Timer external match register definitions
100 **********************************************************************/
103 #define TIM_EM(n) _BIT(n)
104 
105 #define TIM_EM_NOTHING ((uint8_t)(0x0))
106 
107 #define TIM_EM_LOW ((uint8_t)(0x1))
108 
109 #define TIM_EM_HIGH ((uint8_t)(0x2))
110 
111 #define TIM_EM_TOGGLE ((uint8_t)(0x3))
112 
113 #define TIM_EM_SET(n,s) (_SBF(((n << 1) + 4), (s & 0x03)))
114 
115 #define TIM_EM_MASK(n) (_SBF(((n << 1) + 4), 0x03))
116 
117 #define TIM_EMR_MASKBIT 0x0FFF
118 
119 /**********************************************************************
120 * Timer Count Control Register definitions
121 **********************************************************************/
123 #define TIM_CTCR_MODE_MASK 0x3
124 
125 #define TIM_CTCR_INPUT_MASK 0xC
126 
127 #define TIM_CTCR_MASKBIT 0xF
128 #define TIM_COUNTER_MODE ((uint8_t)(1))
129 
130 
131 /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
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)))
135 
136 /* Macro check interrupt type */
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))
140 
141 /* Macro check TIMER mode */
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))
144 
145 /* Macro check TIMER prescale value */
146 #define PARAM_TIM_PRESCALE_OPT(OPT) ((OPT == TIM_PRESCALE_TICKVAL)||(OPT == TIM_PRESCALE_USVAL))
147 
148 /* Macro check TIMER counter intput mode */
149 #define PARAM_TIM_COUNTER_INPUT_OPT(OPT) ((OPT == TIM_COUNTER_INCAP0)||(OPT == TIM_COUNTER_INCAP1))
150 
151 /* Macro check TIMER external match mode */
152 #define PARAM_TIM_EXTMATCH_OPT(OPT) ((OPT == TIM_EXTMATCH_NOTHING)||(OPT == TIM_EXTMATCH_LOW)\
153 ||(OPT == TIM_EXTMATCH_HIGH)||(OPT == TIM_EXTMATCH_TOGGLE))
154 
155 /* Macro check TIMER external match mode */
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))
158 
164 /* Public Types --------------------------------------------------------------- */
169 /***********************************************************************
170  * Timer device enumeration
171 **********************************************************************/
173 typedef enum
174 {
181 }TIM_INT_TYPE;
182 
184 typedef enum
185 {
190 } TIM_MODE_OPT;
191 
193 typedef enum
194 {
198 
200 typedef enum
201 {
205 
207 typedef enum
208 {
214 
216 typedef enum {
222 
224 typedef struct
225 {
226 
227  uint8_t PrescaleOption;
231  uint8_t Reserved[3];
232  uint32_t PrescaleValue;
234 
236 typedef struct {
237 
238  uint8_t CounterOption;
243  uint8_t Reserved[2];
245 
247 typedef struct {
248  uint8_t MatchChannel;
250  uint8_t IntOnMatch;
254  uint8_t StopOnMatch;
258  uint8_t ResetOnMatch;
269  uint8_t Reserved[3];
270  uint32_t MatchValue;
272 
274 typedef struct {
275  uint8_t CaptureChannel;
277  uint8_t RisingEdge;
281  uint8_t FallingEdge;
285  uint8_t IntOnCaption;
291 
297 /* Public Functions ----------------------------------------------------------- */
301 /* Init/DeInit TIM functions -----------*/
302 void TIM_Init(LPC_TIM_TypeDef *TIMx, TIM_MODE_OPT TimerCounterMode, void *TIM_ConfigStruct);
303 void TIM_DeInit(LPC_TIM_TypeDef *TIMx);
304 
305 /* TIM interrupt functions -------------*/
310 
311 /* TIM configuration functions --------*/
312 void TIM_ConfigStructInit(TIM_MODE_OPT TimerCounterMode, void *TIM_ConfigStruct);
313 void TIM_ConfigMatch(LPC_TIM_TypeDef *TIMx, TIM_MATCHCFG_Type *TIM_MatchConfigStruct);
314 void TIM_UpdateMatchValue(LPC_TIM_TypeDef *TIMx,uint8_t MatchChannel, uint32_t MatchValue);
315 void TIM_SetMatchExt(LPC_TIM_TypeDef *TIMx,TIM_EXTMATCH_OPT ext_match );
316 void TIM_ConfigCapture(LPC_TIM_TypeDef *TIMx, TIM_CAPTURECFG_Type *TIM_CaptureConfigStruct);
317 void TIM_Cmd(LPC_TIM_TypeDef *TIMx, FunctionalState NewState);
318 
319 uint32_t TIM_GetCaptureValue(LPC_TIM_TypeDef *TIMx, TIM_COUNTER_INPUT_OPT CaptureChannel);
321 
325 #ifdef __cplusplus
326 }
327 #endif
328 
329 #endif /* __LPC17XX_TIMER_H_ */
330 
335 /* --------------------------------- End Of File ------------------------------ */