1 /**********************************************************************
\r
2 * $Id$ lpc18xx_timer.c 2011-06-02
\r
4 * @file lpc18xx_timer.c
\r
5 * @brief Contains all functions support for Timer firmware library on LPC18xx
\r
7 * @date 02. June. 2011
\r
8 * @author NXP MCU SW Application Team
\r
10 * Copyright(C) 2011, NXP Semiconductor
\r
11 * All rights reserved.
\r
13 ***********************************************************************
\r
14 * Software that is described herein is for illustrative purposes only
\r
15 * which provides customers with programming information regarding the
\r
16 * products. This software is supplied "AS IS" without any warranties.
\r
17 * NXP Semiconductors assumes no responsibility or liability for the
\r
18 * use of the software, conveys no license or title under any patent,
\r
19 * copyright, or mask work right to the product. NXP Semiconductors
\r
20 * reserves the right to make changes in the software without
\r
21 * notification. NXP Semiconductors also make no representation or
\r
22 * warranty that such application will be suitable for the specified
\r
23 * use without further testing or modification.
\r
24 **********************************************************************/
\r
26 /* Peripheral group ----------------------------------------------------------- */
\r
27 /** @addtogroup TIMER
\r
31 /* Includes ------------------------------------------------------------------- */
\r
32 #include "lpc18xx_timer.h"
\r
33 #include "lpc18xx_cgu.h"
\r
35 /* If this source file built with example, the LPC18xx FW library configuration
\r
36 * file in each example directory ("lpc18xx_libcfg.h") must be included,
\r
37 * otherwise the default FW library configuration file must be included instead
\r
39 #ifdef __BUILD_WITH_EXAMPLE__
\r
40 #include "lpc18xx_libcfg.h"
\r
42 #include "lpc18xx_libcfg_default.h"
\r
43 #endif /* __BUILD_WITH_EXAMPLE__ */
\r
47 /* Private Functions ---------------------------------------------------------- */
\r
49 static uint32_t getPClock (uint32_t timernum);
\r
50 static uint32_t converUSecToVal (uint32_t timernum, uint32_t usec);
\r
51 static uint32_t converPtrToTimeNum (LPC_TIMERn_Type *TIMx);
\r
54 /*********************************************************************//**
\r
55 * @brief Get peripheral clock of each timer controller
\r
56 * @param[in] timernum Timer number, should be: 0..3
\r
57 * @return Peripheral clock of timer
\r
58 **********************************************************************/
\r
59 extern uint32_t M3Frequency;
\r
60 static uint32_t getPClock (uint32_t timernum)
\r
66 clkdlycnt = /*CGU_GetPCLK (CGU_PCLKSEL_TIMER0)*/ CGU_GetPCLKFrequency(CGU_PERIPHERAL_TIMER0);
\r
70 clkdlycnt = /*CGU_GetPCLK (CGU_PCLKSEL_TIMER1)*/ CGU_GetPCLKFrequency(CGU_PERIPHERAL_TIMER1);
\r
74 clkdlycnt = /*CGU_GetPCLK (CGU_PCLKSEL_TIMER2)*/ CGU_GetPCLKFrequency(CGU_PERIPHERAL_TIMER2);
\r
78 clkdlycnt = /*CGU_GetPCLK (CGU_PCLKSEL_TIMER3)*/ CGU_GetPCLKFrequency(CGU_PERIPHERAL_TIMER3);
\r
85 /*********************************************************************//**
\r
86 * @brief Convert a time to a timer count value
\r
87 * @param[in] timernum Timer number, should be: 0..3
\r
88 * @param[in] usec Time in microseconds
\r
89 * @return The number of required clock ticks to give the time delay
\r
90 **********************************************************************/
\r
91 uint32_t converUSecToVal (uint32_t timernum, uint32_t usec)
\r
95 // Get Pclock of timer
\r
96 clkdlycnt = (uint64_t) getPClock(timernum);
\r
98 clkdlycnt = (clkdlycnt * usec) / 1000000;
\r
99 return (uint32_t) clkdlycnt;
\r
103 /*********************************************************************//**
\r
104 * @brief Convert a timer register pointer to a timer number
\r
105 * @param[in] TIMx Pointer to LPC_TIMERn_Type, should be:
\r
106 * - LPC_TIM0 :TIMER0 peripheral
\r
107 * - LPC_TIM1 :TIMER1 peripheral
\r
108 * - LPC_TIM2 :TIMER2 peripheral
\r
109 * - LPC_TIM3 :TIMER3 peripheral
\r
110 * @return The timer number (0 to 3) or -1 if register pointer is bad
\r
111 **********************************************************************/
\r
112 uint32_t converPtrToTimeNum (LPC_TIMERn_Type *TIMx)
\r
114 uint32_t tnum = 0xFFFFFFFF;
\r
116 if (TIMx == LPC_TIMER0)
\r
120 else if (TIMx == LPC_TIMER1)
\r
124 else if (TIMx == LPC_TIMER2)
\r
128 else if (TIMx == LPC_TIMER3)
\r
136 /* End of Private Functions ---------------------------------------------------- */
\r
139 /* Public Functions ----------------------------------------------------------- */
\r
140 /** @addtogroup TIM_Public_Functions
\r
144 /*********************************************************************//**
\r
145 * @brief Get Interrupt Status
\r
146 * @param[in] TIMx Timer selection, should be:
\r
147 * - LPC_TIM0 :TIMER0 peripheral
\r
148 * - LPC_TIM1 :TIMER1 peripheral
\r
149 * - LPC_TIM2 :TIMER2 peripheral
\r
150 * - LPC_TIM3 :TIMER3 peripheral
\r
151 * @param[in] IntFlag: interrupt type, should be:
\r
152 * - TIM_MR0_INT :Interrupt for Match channel 0
\r
153 * - TIM_MR1_INT :Interrupt for Match channel 1
\r
154 * - TIM_MR2_INT :Interrupt for Match channel 2
\r
155 * - TIM_MR3_INT :Interrupt for Match channel 3
\r
156 * - TIM_CR0_INT :Interrupt for Capture channel 0
\r
157 * - TIM_CR1_INT :Interrupt for Capture channel 1
\r
158 * @return FlagStatus
\r
160 * - RESET :no interrupt
\r
161 **********************************************************************/
\r
162 FlagStatus TIM_GetIntStatus(LPC_TIMERn_Type *TIMx, TIM_INT_TYPE IntFlag)
\r
165 CHECK_PARAM(PARAM_TIMx(TIMx));
\r
166 CHECK_PARAM(PARAM_TIM_INT_TYPE(IntFlag));
\r
167 temp = (TIMx->IR)& TIM_IR_CLR(IntFlag);
\r
174 /*********************************************************************//**
\r
175 * @brief Get Capture Interrupt Status
\r
176 * @param[in] TIMx Timer selection, should be:
\r
177 * - LPC_TIM0 :TIMER0 peripheral
\r
178 * - LPC_TIM1 :TIMER1 peripheral
\r
179 * - LPC_TIM2 :TIMER2 peripheral
\r
180 * - LPC_TIM3 :TIMER3 peripheral
\r
181 * @param[in] IntFlag: interrupt type, should be:
\r
182 * - TIM_MR0_INT :Interrupt for Match channel 0
\r
183 * - TIM_MR1_INT :Interrupt for Match channel 1
\r
184 * - TIM_MR2_INT :Interrupt for Match channel 2
\r
185 * - TIM_MR3_INT :Interrupt for Match channel 3
\r
186 * - TIM_CR0_INT :Interrupt for Capture channel 0
\r
187 * - TIM_CR1_INT :Interrupt for Capture channel 1
\r
188 * @return FlagStatus
\r
190 * - RESET :no interrupt
\r
191 **********************************************************************/
\r
192 FlagStatus TIM_GetIntCaptureStatus(LPC_TIMERn_Type *TIMx, TIM_INT_TYPE IntFlag)
\r
195 CHECK_PARAM(PARAM_TIMx(TIMx));
\r
196 CHECK_PARAM(PARAM_TIM_INT_TYPE(IntFlag));
\r
197 temp = (TIMx->IR) & (1<<(4+IntFlag));
\r
202 /*********************************************************************//**
\r
203 * @brief Clear Interrupt pending
\r
204 * @param[in] TIMx Timer selection, should be:
\r
205 * - LPC_TIM0 :TIMER0 peripheral
\r
206 * - LPC_TIM1 :TIMER1 peripheral
\r
207 * - LPC_TIM2 :TIMER2 peripheral
\r
208 * - LPC_TIM3 :TIMER3 peripheral
\r
209 * @param[in] IntFlag: interrupt type, should be:
\r
210 * - TIM_MR0_INT :Interrupt for Match channel 0
\r
211 * - TIM_MR1_INT :Interrupt for Match channel 1
\r
212 * - TIM_MR2_INT :Interrupt for Match channel 2
\r
213 * - TIM_MR3_INT :Interrupt for Match channel 3
\r
214 * - TIM_CR0_INT :Interrupt for Capture channel 0
\r
215 * - TIM_CR1_INT :Interrupt for Capture channel 1
\r
217 **********************************************************************/
\r
218 void TIM_ClearIntPending(LPC_TIMERn_Type *TIMx, TIM_INT_TYPE IntFlag)
\r
220 CHECK_PARAM(PARAM_TIMx(TIMx));
\r
221 CHECK_PARAM(PARAM_TIM_INT_TYPE(IntFlag));
\r
222 TIMx->IR = TIM_IR_CLR(IntFlag);
\r
225 /*********************************************************************//**
\r
226 * @brief Clear Capture Interrupt pending
\r
227 * @param[in] TIMx Timer selection, should be
\r
228 * - LPC_TIM0 :TIMER0 peripheral
\r
229 * - LPC_TIM1 :TIMER1 peripheral
\r
230 * - LPC_TIM2 :TIMER2 peripheral
\r
231 * - LPC_TIM3 :TIMER3 peripheral
\r
232 * @param[in] IntFlag interrupt type, should be:
\r
233 * - TIM_MR0_INT :Interrupt for Match channel 0
\r
234 * - TIM_MR1_INT :Interrupt for Match channel 1
\r
235 * - TIM_MR2_INT :Interrupt for Match channel 2
\r
236 * - TIM_MR3_INT :Interrupt for Match channel 3
\r
237 * - TIM_CR0_INT :Interrupt for Capture channel 0
\r
238 * - TIM_CR1_INT :Interrupt for Capture channel 1
\r
240 **********************************************************************/
\r
241 void TIM_ClearIntCapturePending(LPC_TIMERn_Type *TIMx, TIM_INT_TYPE IntFlag)
\r
243 CHECK_PARAM(PARAM_TIMx(TIMx));
\r
244 CHECK_PARAM(PARAM_TIM_INT_TYPE(IntFlag));
\r
245 TIMx->IR = (1<<(4+IntFlag));
\r
248 /*********************************************************************//**
\r
249 * @brief Configuration for Timer at initial time
\r
250 * @param[in] TimerCounterMode timer counter mode, should be:
\r
251 * - TIM_TIMER_MODE :Timer mode
\r
252 * - TIM_COUNTER_RISING_MODE :Counter rising mode
\r
253 * - TIM_COUNTER_FALLING_MODE :Counter falling mode
\r
254 * - TIM_COUNTER_ANY_MODE :Counter on both edges
\r
255 * @param[in] TIM_ConfigStruct pointer to TIM_TIMERCFG_Type or
\r
256 * TIM_COUNTERCFG_Type
\r
258 **********************************************************************/
\r
259 void TIM_ConfigStructInit(TIM_MODE_OPT TimerCounterMode, void *TIM_ConfigStruct)
\r
261 if (TimerCounterMode == TIM_TIMER_MODE )
\r
263 TIM_TIMERCFG_Type * pTimeCfg = (TIM_TIMERCFG_Type *)TIM_ConfigStruct;
\r
264 pTimeCfg->PrescaleOption = TIM_PRESCALE_USVAL;
\r
265 pTimeCfg->PrescaleValue = 1;
\r
269 TIM_COUNTERCFG_Type * pCounterCfg = (TIM_COUNTERCFG_Type *)TIM_ConfigStruct;
\r
270 pCounterCfg->CountInputSelect = TIM_COUNTER_INCAP0;
\r
274 /*********************************************************************//**
\r
275 * @brief Initial Timer/Counter device
\r
276 * Set Clock frequency for Timer
\r
277 * Set initial configuration for Timer
\r
278 * @param[in] TIMx Timer selection, should be:
\r
279 * - LPC_TIM0 :TIMER0 peripheral
\r
280 * - LPC_TIM1 :TIMER1 peripheral
\r
281 * - LPC_TIM2 :TIMER2 peripheral
\r
282 * - LPC_TIM3 :TIMER3 peripheral
\r
283 * @param[in] TimerCounterMode Timer counter mode, should be:
\r
284 * - TIM_TIMER_MODE :Timer mode
\r
285 * - TIM_COUNTER_RISING_MODE :Counter rising mode
\r
286 * - TIM_COUNTER_FALLING_MODE :Counter falling mode
\r
287 * - TIM_COUNTER_ANY_MODE :Counter on both edges
\r
288 * @param[in] TIM_ConfigStruct pointer to TIM_TIMERCFG_Type
\r
289 * that contains the configuration information for the
\r
290 * specified Timer peripheral.
\r
292 **********************************************************************/
\r
293 void TIM_Init(LPC_TIMERn_Type *TIMx, TIM_MODE_OPT TimerCounterMode, void *TIM_ConfigStruct)
\r
295 TIM_TIMERCFG_Type *pTimeCfg;
\r
296 TIM_COUNTERCFG_Type *pCounterCfg;
\r
298 CHECK_PARAM(PARAM_TIMx(TIMx));
\r
299 CHECK_PARAM(PARAM_TIM_MODE_OPT(TimerCounterMode));
\r
302 if (TIMx== LPC_TIMER0)
\r
306 else if (TIMx== LPC_TIMER1)
\r
311 else if (TIMx== LPC_TIMER2)
\r
315 else if (TIMx== LPC_TIMER3)
\r
320 TIMx->CCR &= ~TIM_CTCR_MODE_MASK;
\r
321 TIMx->CCR |= TIM_TIMER_MODE;
\r
326 TIMx->TCR |= (1<<1); //Reset Counter
\r
327 TIMx->TCR &= ~(1<<1); //release reset
\r
328 if (TimerCounterMode == TIM_TIMER_MODE )
\r
330 pTimeCfg = (TIM_TIMERCFG_Type *)TIM_ConfigStruct;
\r
331 if (pTimeCfg->PrescaleOption == TIM_PRESCALE_TICKVAL)
\r
333 TIMx->PR = pTimeCfg->PrescaleValue -1 ;
\r
337 TIMx->PR = converUSecToVal (converPtrToTimeNum(TIMx),pTimeCfg->PrescaleValue)-1;
\r
343 pCounterCfg = (TIM_COUNTERCFG_Type *)TIM_ConfigStruct;
\r
344 TIMx->CCR &= ~TIM_CTCR_INPUT_MASK;
\r
345 if (pCounterCfg->CountInputSelect == TIM_COUNTER_INCAP1)
\r
346 TIMx->CCR |= _BIT(2);
\r
349 // Clear interrupt pending
\r
350 TIMx->IR = 0xFFFFFFFF;
\r
354 /*********************************************************************//**
\r
355 * @brief Close Timer/Counter device
\r
356 * @param[in] TIMx Pointer to timer device, should be:
\r
357 * - LPC_TIM0 :TIMER0 peripheral
\r
358 * - LPC_TIM1 :TIMER1 peripheral
\r
359 * - LPC_TIM2 :TIMER2 peripheral
\r
360 * - LPC_TIM3 :TIMER3 peripheral
\r
362 **********************************************************************/
\r
363 void TIM_DeInit (LPC_TIMERn_Type *TIMx)
\r
365 CHECK_PARAM(PARAM_TIMx(TIMx));
\r
366 // Disable timer/counter
\r
371 /*********************************************************************//**
\r
372 * @brief Start/Stop Timer/Counter device
\r
373 * @param[in] TIMx Pointer to timer device, should be:
\r
374 * - LPC_TIM0 :TIMER0 peripheral
\r
375 * - LPC_TIM1 :TIMER1 peripheral
\r
376 * - LPC_TIM2 :TIMER2 peripheral
\r
377 * - LPC_TIM3 :TIMER3 peripheral
\r
378 * @param[in] NewState
\r
379 * - ENABLE :Set timer enable
\r
380 * - DISABLE :Disable timer
\r
382 **********************************************************************/
\r
383 void TIM_Cmd(LPC_TIMERn_Type *TIMx, FunctionalState NewState)
\r
385 CHECK_PARAM(PARAM_TIMx(TIMx));
\r
386 if (NewState == ENABLE)
\r
388 TIMx->TCR |= TIM_ENABLE;
\r
392 TIMx->TCR &= ~TIM_ENABLE;
\r
396 /*********************************************************************//**
\r
397 * @brief Reset Timer/Counter device,
\r
398 * Make TC and PC are synchronously reset on the next
\r
399 * positive edge of PCLK
\r
400 * @param[in] TIMx Pointer to timer device, should be:
\r
401 * - LPC_TIM0 :TIMER0 peripheral
\r
402 * - LPC_TIM1 :TIMER1 peripheral
\r
403 * - LPC_TIM2 :TIMER2 peripheral
\r
404 * - LPC_TIM3 :TIMER3 peripheral
\r
406 **********************************************************************/
\r
407 void TIM_ResetCounter(LPC_TIMERn_Type *TIMx)
\r
409 CHECK_PARAM(PARAM_TIMx(TIMx));
\r
410 TIMx->TCR |= TIM_RESET;
\r
411 TIMx->TCR &= ~TIM_RESET;
\r
414 /*********************************************************************//**
\r
415 * @brief Configuration for Match register
\r
416 * @param[in] TIMx Pointer to timer device, should be:
\r
417 * - LPC_TIM0 :TIMER0 peripheral
\r
418 * - LPC_TIM1 :TIMER1 peripheral
\r
419 * - LPC_TIM2 :TIMER2 peripheral
\r
420 * - LPC_TIM3 :TIMER3 peripheral
\r
421 * @param[in] TIM_MatchConfigStruct Pointer to TIM_MATCHCFG_Type
\r
422 * - MatchChannel : choose channel 0 or 1
\r
423 * - IntOnMatch : if SET, interrupt will be generated when MRxx match
\r
425 * - StopOnMatch : if SET, TC and PC will be stopped whenM Rxx match
\r
427 * - ResetOnMatch : if SET, Reset on MR0 when MRxx match
\r
429 * -ExtMatchOutputType: Select output for external match
\r
430 * + 0: Do nothing for external output pin if match
\r
431 * + 1: Force external output pin to low if match
\r
432 * + 2: Force external output pin to high if match
\r
433 * + 3: Toggle external output pin if match
\r
434 * MatchValue: Set the value to be compared with TC value
\r
436 **********************************************************************/
\r
437 void TIM_ConfigMatch(LPC_TIMERn_Type *TIMx, TIM_MATCHCFG_Type *TIM_MatchConfigStruct)
\r
440 CHECK_PARAM(PARAM_TIMx(TIMx));
\r
441 CHECK_PARAM(PARAM_TIM_EXTMATCH_OPT(TIM_MatchConfigStruct->ExtMatchOutputType));
\r
443 switch(TIM_MatchConfigStruct->MatchChannel)
\r
446 TIMx->MR[0] = TIM_MatchConfigStruct->MatchValue;
\r
449 TIMx->MR[1] = TIM_MatchConfigStruct->MatchValue;
\r
452 TIMx->MR[2] = TIM_MatchConfigStruct->MatchValue;
\r
455 TIMx->MR[3] = TIM_MatchConfigStruct->MatchValue;
\r
458 //Error match value
\r
463 TIMx->MCR &=~TIM_MCR_CHANNEL_MASKBIT(TIM_MatchConfigStruct->MatchChannel);
\r
465 if (TIM_MatchConfigStruct->IntOnMatch)
\r
466 TIMx->MCR |= TIM_INT_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);
\r
469 if (TIM_MatchConfigStruct->ResetOnMatch)
\r
470 TIMx->MCR |= TIM_RESET_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);
\r
473 if (TIM_MatchConfigStruct->StopOnMatch)
\r
474 TIMx->MCR |= TIM_STOP_ON_MATCH(TIM_MatchConfigStruct->MatchChannel);
\r
476 // match output type
\r
478 TIMx->EMR &= ~TIM_EM_MASK(TIM_MatchConfigStruct->MatchChannel);
\r
479 TIMx->EMR |= TIM_EM_SET(TIM_MatchConfigStruct->MatchChannel,TIM_MatchConfigStruct->ExtMatchOutputType);
\r
481 /*********************************************************************//**
\r
482 * @brief Update Match value
\r
483 * @param[in] TIMx Pointer to timer device, should be:
\r
484 * - LPC_TIM0 :TIMER0 peripheral
\r
485 * - LPC_TIM1 :TIMER1 peripheral
\r
486 * - LPC_TIM2 :TIMER2 peripheral
\r
487 * - LPC_TIM3 :TIMER3 peripheral
\r
488 * @param[in] MatchChannel Match channel, should be: 0..3
\r
489 * @param[in] MatchValue updated match value
\r
491 **********************************************************************/
\r
492 void TIM_UpdateMatchValue(LPC_TIMERn_Type *TIMx,uint8_t MatchChannel, uint32_t MatchValue)
\r
494 CHECK_PARAM(PARAM_TIMx(TIMx));
\r
495 switch(MatchChannel)
\r
498 TIMx->MR[0] = MatchValue;
\r
501 TIMx->MR[1] = MatchValue;
\r
504 TIMx->MR[2] = MatchValue;
\r
507 TIMx->MR[3] = MatchValue;
\r
515 /*********************************************************************//**
\r
516 * @brief Configuration for Capture register
\r
517 * @param[in] TIMx Pointer to timer device, should be:
\r
518 * - LPC_TIM0 :TIMER0 peripheral
\r
519 * - LPC_TIM1 :TIMER1 peripheral
\r
520 * - LPC_TIM2 :TIMER2 peripheral
\r
521 * - LPC_TIM3 :TIMER3 peripheral
\r
522 * @param[in] TIM_CaptureConfigStruct Pointer to TIM_CAPTURECFG_Type
\r
524 **********************************************************************/
\r
525 void TIM_ConfigCapture(LPC_TIMERn_Type *TIMx, TIM_CAPTURECFG_Type *TIM_CaptureConfigStruct)
\r
528 CHECK_PARAM(PARAM_TIMx(TIMx));
\r
529 TIMx->CCR &= ~TIM_CCR_CHANNEL_MASKBIT(TIM_CaptureConfigStruct->CaptureChannel);
\r
531 if (TIM_CaptureConfigStruct->RisingEdge)
\r
532 TIMx->CCR |= TIM_CAP_RISING(TIM_CaptureConfigStruct->CaptureChannel);
\r
534 if (TIM_CaptureConfigStruct->FallingEdge)
\r
535 TIMx->CCR |= TIM_CAP_FALLING(TIM_CaptureConfigStruct->CaptureChannel);
\r
537 if (TIM_CaptureConfigStruct->IntOnCaption)
\r
538 TIMx->CCR |= TIM_INT_ON_CAP(TIM_CaptureConfigStruct->CaptureChannel);
\r
541 /*********************************************************************//**
\r
542 * @brief Read value of capture register in timer/counter device
\r
543 * @param[in] TIMx Pointer to timer/counter device, should be:
\r
544 * - LPC_TIM0 :TIMER0 peripheral
\r
545 * - LPC_TIM1 :TIMER1 peripheral
\r
546 * - LPC_TIM2 :TIMER2 peripheral
\r
547 * - LPC_TIM3 :TIMER3 peripheral
\r
548 * @param[in] CaptureChannel: capture channel number, should be:
\r
549 * - TIM_COUNTER_INCAP0: CAPn.0 input pin for TIMERn
\r
550 * - TIM_COUNTER_INCAP1: CAPn.1 input pin for TIMERn
\r
551 * - TIM_COUNTER_INCAP1: CAPn.2 input pin for TIMERn
\r
552 * - TIM_COUNTER_INCAP1: CAPn.3 input pin for TIMERn
\r
553 * @return Value of capture register
\r
554 **********************************************************************/
\r
555 uint32_t TIM_GetCaptureValue(LPC_TIMERn_Type *TIMx, TIM_COUNTER_INPUT_OPT CaptureChannel)
\r
557 CHECK_PARAM(PARAM_TIMx(TIMx));
\r
558 CHECK_PARAM(PARAM_TIM_COUNTER_INPUT_OPT(CaptureChannel));
\r
560 switch(CaptureChannel){
\r
561 case 0: return TIMx->CR[0];
\r
562 case 1: return TIMx->CR[1];
\r
563 case 2: return TIMx->CR[2];
\r
564 case 3: return TIMx->CR[3];
\r
568 /*---------------Advanced TIMER functions -----------------------------------------*/
\r
569 /*********************************************************************//**
\r
570 * @brief Timer wait (microseconds)
\r
571 * @param[in] time number of microseconds waiting
\r
573 **********************************************************************/
\r
574 void TIM_Waitus(uint32_t time)
\r
576 TIM_MATCHCFG_Type MatchConfigStruct;
\r
577 LPC_TIMER0->IR = 0xFFFFFFFF;
\r
579 MatchConfigStruct.MatchChannel = 0;
\r
580 MatchConfigStruct.IntOnMatch = ENABLE;
\r
581 MatchConfigStruct.ResetOnMatch = ENABLE;
\r
582 MatchConfigStruct.StopOnMatch = ENABLE;
\r
583 MatchConfigStruct.ExtMatchOutputType = 0;
\r
584 MatchConfigStruct.MatchValue = time;
\r
586 TIM_ConfigMatch(LPC_TIMER0, &MatchConfigStruct);
\r
587 TIM_Cmd(LPC_TIMER0,ENABLE);
\r
588 //wait until interrupt flag occur
\r
589 while(!(LPC_TIMER0->IR & 0x01));
\r
590 TIM_ResetCounter(LPC_TIMER0);
\r
592 /*********************************************************************//**
\r
593 * @brief Timer wait (milliseconds)
\r
594 * @param[in] time number of millisecond waiting
\r
596 **********************************************************************/
\r
597 void TIM_Waitms(uint32_t time)
\r
599 TIM_Waitus(time * 1000);
\r
605 #endif /* _TIMER */
\r
611 /* --------------------------------- End Of File ------------------------------ */
\r