LPC_Timer.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #ifndef __LPC_TIMER_H
  2. #define __LPC_TIMER_H
  3. /*************************************************************************
  4. *
  5. * Used with ICCARM and AARM.
  6. *
  7. * (c) Copyright IAR Systems 2003
  8. *
  9. * File name : LPC_Timer.h
  10. * Description :
  11. *
  12. * History :
  13. * 1. Date: July 08, 2004
  14. * Author: Wilson Liu
  15. * Description: Create the basic function
  16. *
  17. * 2. Date: August 12, 2004
  18. * Author: Shawn Zhang
  19. * Description: Re-write some API interface
  20. *
  21. * 3. Data : Oct 10, 2004
  22. * Author : Stanimir Bonev
  23. * Description : Modify some function and interface
  24. *
  25. * $Revision: 1.1 $
  26. **************************************************************************/
  27. #include <includes.h>
  28. /* Timer Control register bit descriptions */
  29. #define TCR_ENABLE_BIT 0
  30. #define TCR_RESET_BIT 1
  31. // The channel name which is used in matching, in fact they represent
  32. // corresponding Match Register
  33. #define CH_MAXNUM 4
  34. #define CH0 0
  35. #define CH1 1
  36. #define CH2 2
  37. #define CH3 3
  38. // The channel name which is used in capturing, in fact they represent
  39. // corresponding Capture Register
  40. #define CPCH_MAXNUM 4
  41. #define CPCH0 0
  42. #define CPCH1 1
  43. #define CPCH2 2
  44. #define CPCH3 3
  45. //The actions when matching
  46. #define TimerAction_Interrupt 0x1
  47. #define TimerAction_ResetTimer 0x2
  48. #define TimerAction_StopTimer 0x4
  49. //Interrupt source type
  50. #define TIMERMR0Int 0x01
  51. #define TIMERMR1Int 0x02
  52. #define TIMERMR2Int 0x04
  53. #define TIMERMR3Int 0x08
  54. #define TIMERCR0Int 0x10
  55. #define TIMERCR1Int 0x20
  56. #define TIMERCR2Int 0x40
  57. #define TIMERCR3Int 0x80
  58. #define TIMERALLInt 0xFF
  59. // TIMER Chanel def
  60. typedef enum {
  61. TIMER0 = 0,
  62. TIMER1
  63. } LPC_TimerChanel_t;
  64. // External Match Control Action Type
  65. typedef enum {
  66. DONOTHING = 0,
  67. SETTOLOW,
  68. SETTOHIGH,
  69. TOGGLE
  70. } LPC_Timer_ExtAction_t;
  71. // Capture Control Action Type
  72. typedef enum {
  73. TimerCPTrigger_Rising = 1,
  74. TimerCPTrigger_Falling
  75. } LPC_Timer_CapureAction_t;
  76. typedef struct {
  77. bool Enable;
  78. unsigned char Action;
  79. unsigned long TimeValue;
  80. void (* Fnpr)(void *);
  81. void * FnprArg;
  82. } LPC_Timer_MatchChannel_t;
  83. typedef struct {
  84. bool Enable;
  85. unsigned char TriggerType;
  86. bool EnableInt;
  87. void (* Fnpr)(void *);
  88. void * FnprArg;
  89. long CPValue;
  90. } LPC_Timer_CaptureChannel_t;
  91. typedef struct {
  92. unsigned long Precision;
  93. unsigned long Prescaler;
  94. LPC_Timer_MatchChannel_t MatchCH[CH_MAXNUM];
  95. LPC_Timer_CaptureChannel_t CaptureCH[CPCH_MAXNUM];
  96. LPC_Timer_ExtAction_t ExtAction[CH_MAXNUM];
  97. unsigned char ExtBitValue[CH_MAXNUM]; // low or high, only 1 bit
  98. } LPC_Timer_Config_t;
  99. /* Declare functions */
  100. int TIMER_Init(LPC_TimerChanel_t DevNum, unsigned long precision);
  101. int TIMER_Reset(LPC_TimerChanel_t DevNum);
  102. int TIMER_Start(LPC_TimerChanel_t DevNum);
  103. int TIMER_Stop(LPC_TimerChanel_t DevNum);
  104. int TIMER_SetMatchAction(LPC_TimerChanel_t DevNum,
  105. unsigned int CHNum,
  106. unsigned int action ,
  107. unsigned long TimeValue,
  108. void (* Fnpr)(void *),
  109. void * FnprArg,
  110. LPC_Timer_ExtAction_t ExtAction);
  111. int TIMER_GetTimerMatch(LPC_TimerChanel_t DevNum, unsigned int MRNum,
  112. unsigned int * pAction , unsigned int * pMatchValue);
  113. int TIMER_GetTimerExternalMatch(LPC_TimerChanel_t DevNum, unsigned int MATNum,
  114. unsigned int * pAction , unsigned int *pExternalMatchValue);
  115. int TIMER_SetCaptureAction (LPC_TimerChanel_t DevNum,
  116. unsigned char CPCHNum,
  117. unsigned char TriggerType,
  118. bool EnableInt,
  119. void (* Fnpr)(void *),
  120. void * FnprArg );
  121. int TIMER_GetTimerCapture(LPC_TimerChanel_t DevNum, unsigned int CRNum,
  122. unsigned int * pCaptureValue);
  123. unsigned long TIMER_CheckIntType(LPC_TimerChanel_t DevNum);
  124. unsigned long TIMER_ClearInt(LPC_TimerChanel_t DevNum, int IntType);
  125. unsigned long TIMER_GetREGValue_CR(LPC_TimerChanel_t DevNum, int CRNum);
  126. unsigned long TIMER_GetREGValue_TC(LPC_TimerChanel_t DevNum);
  127. unsigned long TIMER_GetPrescaler(LPC_TimerChanel_t DevNum);
  128. void TIMER0_ISR ();
  129. void TIMER1_ISR ();
  130. // Time defenition
  131. #define sec_T0 *(SYS_GetFpclk()/TIMER_GetPrescaler(TIMER0))
  132. #define msec_T0 *(SYS_GetFpclk()/(TIMER_GetPrescaler(TIMER0)*1000))
  133. #define usec_T0 *(SYS_GetFpclk()/(TIMER_GetPrescaler(TIMER0)*1000000))
  134. #define sec_T1 *(SYS_GetFpclk()/TIMER_GetPrescaler(TIMER1))
  135. #define msec_T1 *(SYS_GetFpclk()/(TIMER_GetPrescaler(TIMER1)*1000))
  136. #define usec_T1 *(SYS_GetFpclk()/(TIMER_GetPrescaler(TIMER1)*1000000))
  137. #endif //__LPC_Timer_H