tiva_timer.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. //*****************************************************************************
  2. //
  3. // timer.h - Prototypes for the timer module
  4. //
  5. // Copyright (c) 2005-2014 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. // This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. #ifndef __DRIVERLIB_TIVA_TIMER_H__
  40. #define __DRIVERLIB_TIVA_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 ui32Config 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_RTC 0x01000000 // Full-width RTC timer
  63. #define TIMER_CFG_SPLIT_PAIR 0x04000000 // Two half-width timers
  64. #define TIMER_CFG_A_ONE_SHOT 0x00000021 // Timer A one-shot timer
  65. #define TIMER_CFG_A_ONE_SHOT_UP 0x00000031 // Timer A one-shot up-count timer
  66. #define TIMER_CFG_A_PERIODIC 0x00000022 // Timer A periodic timer
  67. #define TIMER_CFG_A_PERIODIC_UP 0x00000032 // Timer A periodic up-count timer
  68. #define TIMER_CFG_A_CAP_COUNT 0x00000003 // Timer A event counter
  69. #define TIMER_CFG_A_CAP_COUNT_UP 0x00000013 // Timer A event up-counter
  70. #define TIMER_CFG_A_CAP_TIME 0x00000007 // Timer A event timer
  71. #define TIMER_CFG_A_CAP_TIME_UP 0x00000017 // Timer A event up-count timer
  72. #define TIMER_CFG_A_PWM 0x0000000A // Timer A PWM output
  73. #define TIMER_CFG_B_ONE_SHOT 0x00002100 // Timer B one-shot timer
  74. #define TIMER_CFG_B_ONE_SHOT_UP 0x00003100 // Timer B one-shot up-count timer
  75. #define TIMER_CFG_B_PERIODIC 0x00002200 // Timer B periodic timer
  76. #define TIMER_CFG_B_PERIODIC_UP 0x00003200 // Timer B periodic up-count timer
  77. #define TIMER_CFG_B_CAP_COUNT 0x00000300 // Timer B event counter
  78. #define TIMER_CFG_B_CAP_COUNT_UP 0x00001300 // Timer B event up-counter
  79. #define TIMER_CFG_B_CAP_TIME 0x00000700 // Timer B event timer
  80. #define TIMER_CFG_B_CAP_TIME_UP 0x00001700 // Timer B event up-count timer
  81. #define TIMER_CFG_B_PWM 0x00000A00 // Timer B PWM output
  82. #define TIMER_CFG_A_ACT_TOINTD 0x00010000 // Timer A compare action disable
  83. // time-out interrupt.
  84. #define TIMER_CFG_A_ACT_NONE 0x00000000 // Timer A compare action none.
  85. #define TIMER_CFG_A_ACT_TOGGLE 0x00020000 // Timer A compare action toggle.
  86. #define TIMER_CFG_A_ACT_CLRTO 0x00040000 // Timer A compare action CCP
  87. // clear on time-out.
  88. #define TIMER_CFG_A_ACT_SETTO 0x00060000 // Timer A compare action CCP set
  89. // on time-out.
  90. #define TIMER_CFG_A_ACT_SETTOGTO 0x00080000 // Timer A compare action set CCP
  91. // toggle on time-out.
  92. #define TIMER_CFG_A_ACT_CLRTOGTO 0x000A0000 // Timer A compare action clear
  93. // CCP toggle on time-out.
  94. #define TIMER_CFG_A_ACT_SETCLRTO 0x000C0000 // Timer A compare action set CCP
  95. // clear on time-out.
  96. #define TIMER_CFG_A_ACT_CLRSETTO 0x000E0000 // Timer A compare action clear
  97. // CCP set on time-out.
  98. #define TIMER_CFG_B_ACT_TOINTD 0x00100000 // Timer B compare action disable
  99. // time-out interrupt.
  100. #define TIMER_CFG_B_ACT_NONE 0x00000000 // Timer A compare action none.
  101. #define TIMER_CFG_B_ACT_TOGGLE 0x00200000 // Timer A compare action toggle.
  102. #define TIMER_CFG_B_ACT_CLRTO 0x00400000 // Timer A compare action CCP
  103. // clear on time-out.
  104. #define TIMER_CFG_B_ACT_SETTO 0x00600000 // Timer A compare action CCP set
  105. // on time-out.
  106. #define TIMER_CFG_B_ACT_SETTOGTO 0x00800000 // Timer A compare action set CCP
  107. // toggle on time-out.
  108. #define TIMER_CFG_B_ACT_CLRTOGTO 0x00A00000 // Timer A compare action clear
  109. // CCP toggle on time-out.
  110. #define TIMER_CFG_B_ACT_SETCLRTO 0x00C00000 // Timer A compare action set CCP
  111. // clear on time-out.
  112. #define TIMER_CFG_B_ACT_CLRSETTO 0x0000E000 // Timer A compare action clear
  113. // CCP set on time-out.
  114. //*****************************************************************************
  115. //
  116. // Values that can be passed to TimerIntEnable, TimerIntDisable, and
  117. // TimerIntClear as the ui32IntFlags parameter, and returned from
  118. // TimerIntStatus.
  119. //
  120. //*****************************************************************************
  121. #define TIMER_TIMB_DMA 0x00002000 // TimerB DMA Complete Interrupt.
  122. #define TIMER_TIMB_MATCH 0x00000800 // TimerB match interrupt
  123. #define TIMER_CAPB_EVENT 0x00000400 // CaptureB event interrupt
  124. #define TIMER_CAPB_MATCH 0x00000200 // CaptureB match interrupt
  125. #define TIMER_TIMB_TIMEOUT 0x00000100 // TimerB time out interrupt
  126. #define TIMER_TIMA_DMA 0x00000020 // TimerA DMA Complete Interrupt.
  127. #define TIMER_TIMA_MATCH 0x00000010 // TimerA match interrupt
  128. #define TIMER_RTC_MATCH 0x00000008 // RTC interrupt mask
  129. #define TIMER_CAPA_EVENT 0x00000004 // CaptureA event interrupt
  130. #define TIMER_CAPA_MATCH 0x00000002 // CaptureA match interrupt
  131. #define TIMER_TIMA_TIMEOUT 0x00000001 // TimerA time out interrupt
  132. //*****************************************************************************
  133. //
  134. // Values that can be passed to TimerControlEvent as the ui32Event parameter.
  135. //
  136. //*****************************************************************************
  137. #define TIMER_EVENT_POS_EDGE 0x00000000 // Count positive edges
  138. #define TIMER_EVENT_NEG_EDGE 0x00000404 // Count negative edges
  139. #define TIMER_EVENT_BOTH_EDGES 0x00000C0C // Count both edges
  140. //*****************************************************************************
  141. //
  142. // Values that can be passed to most of the timer APIs as the ui32Timer
  143. // parameter.
  144. //
  145. //*****************************************************************************
  146. #define TIMER_A 0x000000ff // Timer A
  147. #define TIMER_B 0x0000ff00 // Timer B
  148. #define TIMER_BOTH 0x0000ffff // Timer Both
  149. //*****************************************************************************
  150. //
  151. // Values that can be passed to TimerSynchronize as the ui32Timers parameter.
  152. //
  153. //*****************************************************************************
  154. #define TIMER_0A_SYNC 0x00000001 // Synchronize Timer 0A
  155. #define TIMER_0B_SYNC 0x00000002 // Synchronize Timer 0B
  156. #define TIMER_1A_SYNC 0x00000004 // Synchronize Timer 1A
  157. #define TIMER_1B_SYNC 0x00000008 // Synchronize Timer 1B
  158. #define TIMER_2A_SYNC 0x00000010 // Synchronize Timer 2A
  159. #define TIMER_2B_SYNC 0x00000020 // Synchronize Timer 2B
  160. #define TIMER_3A_SYNC 0x00000040 // Synchronize Timer 3A
  161. #define TIMER_3B_SYNC 0x00000080 // Synchronize Timer 3B
  162. #define TIMER_4A_SYNC 0x00000100 // Synchronize Timer 4A
  163. #define TIMER_4B_SYNC 0x00000200 // Synchronize Timer 4B
  164. #define TIMER_5A_SYNC 0x00000400 // Synchronize Timer 5A
  165. #define TIMER_5B_SYNC 0x00000800 // Synchronize Timer 5B
  166. #define WTIMER_0A_SYNC 0x00001000 // Synchronize Wide Timer 0A
  167. #define WTIMER_0B_SYNC 0x00002000 // Synchronize Wide Timer 0B
  168. #define WTIMER_1A_SYNC 0x00004000 // Synchronize Wide Timer 1A
  169. #define WTIMER_1B_SYNC 0x00008000 // Synchronize Wide Timer 1B
  170. #define WTIMER_2A_SYNC 0x00010000 // Synchronize Wide Timer 2A
  171. #define WTIMER_2B_SYNC 0x00020000 // Synchronize Wide Timer 2B
  172. #define WTIMER_3A_SYNC 0x00040000 // Synchronize Wide Timer 3A
  173. #define WTIMER_3B_SYNC 0x00080000 // Synchronize Wide Timer 3B
  174. #define WTIMER_4A_SYNC 0x00100000 // Synchronize Wide Timer 4A
  175. #define WTIMER_4B_SYNC 0x00200000 // Synchronize Wide Timer 4B
  176. #define WTIMER_5A_SYNC 0x00400000 // Synchronize Wide Timer 5A
  177. #define WTIMER_5B_SYNC 0x00800000 // Synchronize Wide Timer 5B
  178. //*****************************************************************************
  179. //
  180. // Values that can be passed to TimerClockSourceSet() or returned from
  181. // TimerClockSourceGet().
  182. //
  183. //*****************************************************************************
  184. #define TIMER_CLOCK_SYSTEM 0x00000000
  185. #define TIMER_CLOCK_PIOSC 0x00000001
  186. //*****************************************************************************
  187. //
  188. // Values that can be passed to TimerDMAEventSet() or returned from
  189. // TimerDMAEventGet().
  190. //
  191. //*****************************************************************************
  192. #define TIMER_DMA_MODEMATCH_B 0x00000800
  193. #define TIMER_DMA_CAPEVENT_B 0x00000400
  194. #define TIMER_DMA_CAPMATCH_B 0x00000200
  195. #define TIMER_DMA_TIMEOUT_B 0x00000100
  196. #define TIMER_DMA_MODEMATCH_A 0x00000010
  197. #define TIMER_DMA_RTC_A 0x00000008
  198. #define TIMER_DMA_CAPEVENT_A 0x00000004
  199. #define TIMER_DMA_CAPMATCH_A 0x00000002
  200. #define TIMER_DMA_TIMEOUT_A 0x00000001
  201. //*****************************************************************************
  202. //
  203. // Values that can be passed to TimerADCEventSet() or returned from
  204. // TimerADCEventGet().
  205. //
  206. //*****************************************************************************
  207. #define TIMER_ADC_MODEMATCH_B 0x00000800
  208. #define TIMER_ADC_CAPEVENT_B 0x00000400
  209. #define TIMER_ADC_CAPMATCH_B 0x00000200
  210. #define TIMER_ADC_TIMEOUT_B 0x00000100
  211. #define TIMER_ADC_MODEMATCH_A 0x00000010
  212. #define TIMER_ADC_RTC_A 0x00000008
  213. #define TIMER_ADC_CAPEVENT_A 0x00000004
  214. #define TIMER_ADC_CAPMATCH_A 0x00000002
  215. #define TIMER_ADC_TIMEOUT_A 0x00000001
  216. //*****************************************************************************
  217. //
  218. // Values that can be passed to TimerUpdateMode().
  219. //
  220. //*****************************************************************************
  221. #define TIMER_UP_LOAD_IMMEDIATE 0x00000000
  222. #define TIMER_UP_LOAD_TIMEOUT 0x00000100
  223. #define TIMER_UP_MATCH_IMMEDIATE \
  224. 0x00000000
  225. #define TIMER_UP_MATCH_TIMEOUT 0x00000400
  226. //*****************************************************************************
  227. //
  228. // Prototypes for the APIs.
  229. //
  230. //*****************************************************************************
  231. extern void TimerEnable(uint32_t ui32Base, uint32_t ui32Timer);
  232. extern void TimerDisable(uint32_t ui32Base, uint32_t ui32Timer);
  233. extern void TimerConfigure(uint32_t ui32Base, uint32_t ui32Config);
  234. extern void TimerControlLevel(uint32_t ui32Base, uint32_t ui32Timer,
  235. bool bInvert);
  236. extern void TimerControlTrigger(uint32_t ui32Base, uint32_t ui32Timer,
  237. bool bEnable);
  238. extern void TimerControlEvent(uint32_t ui32Base, uint32_t ui32Timer,
  239. uint32_t ui32Event);
  240. extern void TimerControlStall(uint32_t ui32Base, uint32_t ui32Timer,
  241. bool bStall);
  242. extern void TimerControlWaitOnTrigger(uint32_t ui32Base, uint32_t ui32Timer,
  243. bool bWait);
  244. extern void TimerRTCEnable(uint32_t ui32Base);
  245. extern void TimerRTCDisable(uint32_t ui32Base);
  246. extern void TimerPrescaleSet(uint32_t ui32Base, uint32_t ui32Timer,
  247. uint32_t ui32Value);
  248. extern uint32_t TimerPrescaleGet(uint32_t ui32Base, uint32_t ui32Timer);
  249. extern void TimerPrescaleMatchSet(uint32_t ui32Base, uint32_t ui32Timer,
  250. uint32_t ui32Value);
  251. extern uint32_t TimerPrescaleMatchGet(uint32_t ui32Base, uint32_t ui32Timer);
  252. extern void TimerLoadSet(uint32_t ui32Base, uint32_t ui32Timer,
  253. uint32_t ui32Value);
  254. extern uint32_t TimerLoadGet(uint32_t ui32Base, uint32_t ui32Timer);
  255. extern void TimerLoadSet64(uint32_t ui32Base, uint64_t ui64Value);
  256. extern uint64_t TimerLoadGet64(uint32_t ui32Base);
  257. extern uint32_t TimerValueGet(uint32_t ui32Base, uint32_t ui32Timer);
  258. extern uint64_t TimerValueGet64(uint32_t ui32Base);
  259. extern void TimerMatchSet(uint32_t ui32Base, uint32_t ui32Timer,
  260. uint32_t ui32Value);
  261. extern uint32_t TimerMatchGet(uint32_t ui32Base, uint32_t ui32Timer);
  262. extern void TimerMatchSet64(uint32_t ui32Base, uint64_t ui64Value);
  263. extern uint64_t TimerMatchGet64(uint32_t ui32Base);
  264. extern void TimerIntRegister(uint32_t ui32Base, uint32_t ui32Timer,
  265. void (*pfnHandler)(void));
  266. extern void TimerIntUnregister(uint32_t ui32Base, uint32_t ui32Timer);
  267. extern void TimerIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags);
  268. extern void TimerIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags);
  269. extern uint32_t TimerIntStatus(uint32_t ui32Base, bool bMasked);
  270. extern void TimerIntClear(uint32_t ui32Base, uint32_t ui32IntFlags);
  271. extern void TimerSynchronize(uint32_t ui32Base, uint32_t ui32Timers);
  272. extern uint32_t TimerClockSourceGet(uint32_t ui32Base);
  273. extern void TimerClockSourceSet(uint32_t ui32Base, uint32_t ui32Source);
  274. extern uint32_t TimerADCEventGet(uint32_t ui32Base);
  275. extern void TimerADCEventSet(uint32_t ui32Base, uint32_t ui32ADCEvent);
  276. extern uint32_t TimerDMAEventGet(uint32_t ui32Base);
  277. extern void TimerDMAEventSet(uint32_t ui32Base, uint32_t ui32DMAEvent);
  278. extern void TimerUpdateMode(uint32_t ui32Base, uint32_t ui32Timer,
  279. uint32_t ui32Config);
  280. //*****************************************************************************
  281. //
  282. // Mark the end of the C bindings section for C++ compilers.
  283. //
  284. //*****************************************************************************
  285. #ifdef __cplusplus
  286. }
  287. #endif
  288. #endif // __DRIVERLIB_TIMER_H__