timer.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //*****************************************************************************
  2. //
  3. // timer.h
  4. //
  5. // Prototypes for the timer module
  6. //
  7. // Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
  8. //
  9. //
  10. // Redistribution and use in source and binary forms, with or without
  11. // modification, are permitted provided that the following conditions
  12. // are met:
  13. //
  14. // Redistributions of source code must retain the above copyright
  15. // notice, this list of conditions and the following disclaimer.
  16. //
  17. // Redistributions in binary form must reproduce the above copyright
  18. // notice, this list of conditions and the following disclaimer in the
  19. // documentation and/or other materials provided with the
  20. // distribution.
  21. //
  22. // Neither the name of Texas Instruments Incorporated nor the names of
  23. // its contributors may be used to endorse or promote products derived
  24. // from this software without specific prior written permission.
  25. //
  26. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  29. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  30. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  31. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  32. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  33. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  34. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. //
  38. //*****************************************************************************
  39. #ifndef __TIMER_H__
  40. #define __TIMER_H__
  41. //*****************************************************************************
  42. //
  43. // If building with a C++ compiler, make all of the definitions in this header
  44. // have a C binding.
  45. //
  46. //*****************************************************************************
  47. #ifdef __cplusplus
  48. extern "C"
  49. {
  50. #endif
  51. //*****************************************************************************
  52. //
  53. // Values that can be passed to TimerConfigure as the ulConfig parameter.
  54. //
  55. //*****************************************************************************
  56. #define TIMER_CFG_ONE_SHOT 0x00000021 // Full-width one-shot timer
  57. #define TIMER_CFG_ONE_SHOT_UP 0x00000031 // Full-width one-shot up-count
  58. // timer
  59. #define TIMER_CFG_PERIODIC 0x00000022 // Full-width periodic timer
  60. #define TIMER_CFG_PERIODIC_UP 0x00000032 // Full-width periodic up-count
  61. // timer
  62. #define TIMER_CFG_SPLIT_PAIR 0x04000000 // Two half-width timers
  63. #define TIMER_CFG_A_ONE_SHOT 0x00000021 // Timer A one-shot timer
  64. #define TIMER_CFG_A_ONE_SHOT_UP 0x00000031 // Timer A one-shot up-count timer
  65. #define TIMER_CFG_A_PERIODIC 0x00000022 // Timer A periodic timer
  66. #define TIMER_CFG_A_PERIODIC_UP 0x00000032 // Timer A periodic up-count timer
  67. #define TIMER_CFG_A_CAP_COUNT 0x00000003 // Timer A event counter
  68. #define TIMER_CFG_A_CAP_COUNT_UP 0x00000013 // Timer A event up-counter
  69. #define TIMER_CFG_A_CAP_TIME 0x00000007 // Timer A event timer
  70. #define TIMER_CFG_A_CAP_TIME_UP 0x00000017 // Timer A event up-count timer
  71. #define TIMER_CFG_A_PWM 0x0000000A // Timer A PWM output
  72. #define TIMER_CFG_B_ONE_SHOT 0x00002100 // Timer B one-shot timer
  73. #define TIMER_CFG_B_ONE_SHOT_UP 0x00003100 // Timer B one-shot up-count timer
  74. #define TIMER_CFG_B_PERIODIC 0x00002200 // Timer B periodic timer
  75. #define TIMER_CFG_B_PERIODIC_UP 0x00003200 // Timer B periodic up-count timer
  76. #define TIMER_CFG_B_CAP_COUNT 0x00000300 // Timer B event counter
  77. #define TIMER_CFG_B_CAP_COUNT_UP 0x00001300 // Timer B event up-counter
  78. #define TIMER_CFG_B_CAP_TIME 0x00000700 // Timer B event timer
  79. #define TIMER_CFG_B_CAP_TIME_UP 0x00001700 // Timer B event up-count timer
  80. #define TIMER_CFG_B_PWM 0x00000A00 // Timer B PWM output
  81. //*****************************************************************************
  82. //
  83. // Values that can be passed to TimerIntEnable, TimerIntDisable, and
  84. // TimerIntClear as the ulIntFlags parameter, and returned from TimerIntStatus.
  85. //
  86. //*****************************************************************************
  87. #define TIMER_TIMB_DMA 0x00002000 // TimerB DMA Done interrupt
  88. #define TIMER_TIMB_MATCH 0x00000800 // TimerB match interrupt
  89. #define TIMER_CAPB_EVENT 0x00000400 // CaptureB event interrupt
  90. #define TIMER_CAPB_MATCH 0x00000200 // CaptureB match interrupt
  91. #define TIMER_TIMB_TIMEOUT 0x00000100 // TimerB time out interrupt
  92. #define TIMER_TIMA_DMA 0x00000020 // TimerA DMA Done interrupt
  93. #define TIMER_TIMA_MATCH 0x00000010 // TimerA match interrupt
  94. #define TIMER_CAPA_EVENT 0x00000004 // CaptureA event interrupt
  95. #define TIMER_CAPA_MATCH 0x00000002 // CaptureA match interrupt
  96. #define TIMER_TIMA_TIMEOUT 0x00000001 // TimerA time out interrupt
  97. //*****************************************************************************
  98. //
  99. // Values that can be passed to TimerControlEvent as the ulEvent parameter.
  100. //
  101. //*****************************************************************************
  102. #define TIMER_EVENT_POS_EDGE 0x00000000 // Count positive edges
  103. #define TIMER_EVENT_NEG_EDGE 0x00000404 // Count negative edges
  104. #define TIMER_EVENT_BOTH_EDGES 0x00000C0C // Count both edges
  105. //*****************************************************************************
  106. //
  107. // Values that can be passed to most of the timer APIs as the ulTimer
  108. // parameter.
  109. //
  110. //*****************************************************************************
  111. #define TIMER_A 0x000000ff // Timer A
  112. #define TIMER_B 0x0000ff00 // Timer B
  113. #define TIMER_BOTH 0x0000ffff // Timer Both
  114. //*****************************************************************************
  115. //
  116. // Values that can be passed to TimerSynchronize as the ulTimers parameter.
  117. //
  118. //*****************************************************************************
  119. #define TIMER_0A_SYNC 0x00000001 // Synchronize Timer 0A
  120. #define TIMER_0B_SYNC 0x00000002 // Synchronize Timer 0B
  121. #define TIMER_1A_SYNC 0x00000004 // Synchronize Timer 1A
  122. #define TIMER_1B_SYNC 0x00000008 // Synchronize Timer 1B
  123. #define TIMER_2A_SYNC 0x00000010 // Synchronize Timer 2A
  124. #define TIMER_2B_SYNC 0x00000020 // Synchronize Timer 2B
  125. #define TIMER_3A_SYNC 0x00000040 // Synchronize Timer 3A
  126. #define TIMER_3B_SYNC 0x00000080 // Synchronize Timer 3B
  127. //*****************************************************************************
  128. //
  129. // Values that can be passed to TimerDMAEventSet() or returned from
  130. // TimerDMAEventGet().
  131. //
  132. //*****************************************************************************
  133. #define TIMER_DMA_MODEMATCH_B 0x00000800
  134. #define TIMER_DMA_CAPEVENT_B 0x00000400
  135. #define TIMER_DMA_CAPMATCH_B 0x00000200
  136. #define TIMER_DMA_TIMEOUT_B 0x00000100
  137. #define TIMER_DMA_MODEMATCH_A 0x00000010
  138. #define TIMER_DMA_CAPEVENT_A 0x00000004
  139. #define TIMER_DMA_CAPMATCH_A 0x00000002
  140. #define TIMER_DMA_TIMEOUT_A 0x00000001
  141. //*****************************************************************************
  142. //
  143. // Prototypes for the APIs.
  144. //
  145. //*****************************************************************************
  146. extern void TimerEnable(unsigned long ulBase, unsigned long ulTimer);
  147. extern void TimerDisable(unsigned long ulBase, unsigned long ulTimer);
  148. extern void TimerConfigure(unsigned long ulBase, unsigned long ulConfig);
  149. extern void TimerControlLevel(unsigned long ulBase, unsigned long ulTimer,
  150. tBoolean bInvert);
  151. extern void TimerControlEvent(unsigned long ulBase, unsigned long ulTimer,
  152. unsigned long ulEvent);
  153. extern void TimerControlStall(unsigned long ulBase, unsigned long ulTimer,
  154. tBoolean bStall);
  155. extern void TimerPrescaleSet(unsigned long ulBase, unsigned long ulTimer,
  156. unsigned long ulValue);
  157. extern unsigned long TimerPrescaleGet(unsigned long ulBase,
  158. unsigned long ulTimer);
  159. extern void TimerPrescaleMatchSet(unsigned long ulBase, unsigned long ulTimer,
  160. unsigned long ulValue);
  161. extern unsigned long TimerPrescaleMatchGet(unsigned long ulBase,
  162. unsigned long ulTimer);
  163. extern void TimerLoadSet(unsigned long ulBase, unsigned long ulTimer,
  164. unsigned long ulValue);
  165. extern unsigned long TimerLoadGet(unsigned long ulBase, unsigned long ulTimer);
  166. extern unsigned long TimerValueGet(unsigned long ulBase,
  167. unsigned long ulTimer);
  168. extern void TimerValueSet(unsigned long ulBase, unsigned long ulTimer,
  169. unsigned long ulValue);
  170. extern void TimerMatchSet(unsigned long ulBase, unsigned long ulTimer,
  171. unsigned long ulValue);
  172. extern unsigned long TimerMatchGet(unsigned long ulBase,
  173. unsigned long ulTimer);
  174. extern void TimerIntRegister(unsigned long ulBase, unsigned long ulTimer,
  175. void (*pfnHandler)(void));
  176. extern void TimerIntUnregister(unsigned long ulBase, unsigned long ulTimer);
  177. extern void TimerIntEnable(unsigned long ulBase, unsigned long ulIntFlags);
  178. extern void TimerIntDisable(unsigned long ulBase, unsigned long ulIntFlags);
  179. extern unsigned long TimerIntStatus(unsigned long ulBase, tBoolean bMasked);
  180. extern void TimerIntClear(unsigned long ulBase, unsigned long ulIntFlags);
  181. extern void TimerDMAEventSet(unsigned long ulBase, unsigned long ulDMAEvent);
  182. extern unsigned long TimerDMAEventGet(unsigned long ulBase);
  183. //*****************************************************************************
  184. //
  185. // Mark the end of the C bindings section for C++ compilers.
  186. //
  187. //*****************************************************************************
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. #endif // __TIMER_H__