timer.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /**
  2. * \file timer.h
  3. *
  4. * \brief Timer APIs and macros.
  5. *
  6. * This file contains the driver API prototypes and macro definitions.
  7. */
  8. /*
  9. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  10. */
  11. /*
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the
  22. * distribution.
  23. *
  24. * Neither the name of Texas Instruments Incorporated nor the names of
  25. * its contributors may be used to endorse or promote products derived
  26. * from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  31. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  34. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  35. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  36. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  38. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. */
  41. #ifndef __TIMER_H__
  42. #define __TIMER_H__
  43. #include "hw_tmr.h"
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /*****************************************************************************/
  48. /*
  49. ** Values that can be passed to Timer APIs as timer
  50. */
  51. #define TMR_TIMER12 (0x00003FFEu) /* Timer12 */
  52. #define TMR_TIMER34 (0x3FFE0000u) /* Timer34 */
  53. #define TMR_TIMER_BOTH (0x3FFE3FFEu) /* Both Timers */
  54. /*****************************************************************************/
  55. /*
  56. ** Values that can be passed to TimerEnable API as enaMode to select the mode
  57. */
  58. /* Enable the Timer for once */
  59. #define TMR_ENABLE_ONCE (0x00400040u)
  60. /* Enable the Timer for continuous operation without period reload */
  61. #define TMR_ENABLE_CONT (0x00800080u)
  62. /* Enable the Timer for continuous operation with period reload */
  63. #define TMR_ENABLE_CONTRELOAD (0x00C000C0u)
  64. /*****************************************************************************/
  65. /*
  66. ** Values that can be passed to TimerConfigure API as config
  67. */
  68. /* 64 Bit mode with internal clock source */
  69. #define TMR_CFG_64BIT_CLK_INT (0x00000013u)
  70. /* 64 Bit mode with external clock source */
  71. #define TMR_CFG_64BIT_CLK_EXT (0x01000113u)
  72. /* 64 Bit Watchdog timer mode */
  73. #define TMR_CFG_64BIT_WATCHDOG (0x0000001Bu)
  74. /* 32 Bit chained mode with internal clock source */
  75. #define TMR_CFG_32BIT_CH_CLK_INT (0x0000001Fu)
  76. /* 32 Bit chained mode with external clock source */
  77. #define TMR_CFG_32BIT_CH_CLK_EXT (0x0100011Fu)
  78. /* 32 Bit unchained mode with internal clock source for both timers */
  79. #define TMR_CFG_32BIT_UNCH_CLK_BOTH_INT (0x00000017u)
  80. /* 32 Bit unchained mode; clock Internal for Timer12; external for Timer34 */
  81. #define TMR_CFG_32BIT_UNCH_CLK_12INT_34EXT (0x01000017u)
  82. /* 32 Bit unchained mode; clock external for Timer12; internal for Timer34 */
  83. #define TMR_CFG_32BIT_UNCH_CLK_12EXT_34INT (0x00000117u)
  84. /* 32 Bit unchained mode with external clock source for both timers */
  85. #define TMR_CFG_32BIT_UNCH_CLK_BOTH_EXT (0x01000117u)
  86. /*****************************************************************************/
  87. /*
  88. ** Values that can be passed to TimerIntEnable/IntDisable APIs as intFlag
  89. ** Any combination is also allowed.
  90. ** Example- (TMR_INTCTLSTAT_PRDINTEN12 | TMR_INTCTLSTAT_EVTINTEN34)
  91. */
  92. /* To enable/disable the interrupt for Timer12 in Capture mode */
  93. #define TMR_INT_TMR12_CAPT_MODE (TMR_INTCTLSTAT_EVTINTEN12)
  94. /* To enable/disable the interrupt for Timer12 in in 64 Bit/32 Bit/WDT mode */
  95. #define TMR_INT_TMR12_NON_CAPT_MODE (TMR_INTCTLSTAT_PRDINTEN12)
  96. /* To enable/disable the interrupt for Timer34 in Capture mode */
  97. #define TMR_INT_TMR34_CAPT_MODE (TMR_INTCTLSTAT_EVTINTEN34)
  98. /* To enable/disable the interrupt for Timer34 in 64 Bit/32 Bit/WDT mode */
  99. #define TMR_INT_TMR34_NON_CAPT_MODE (TMR_INTCTLSTAT_PRDINTEN34)
  100. /*****************************************************************************/
  101. /*
  102. ** Values that can be passed to TimerIntStatusGet/Clear as statFlag
  103. ** Any combination is also allowed.
  104. */
  105. /* Interrupt Generated when Timer 12 in 64 Bit/32 Bit/WDT mode */
  106. #define TMR_INTSTAT12_TIMER_NON_CAPT (TMR_INTCTLSTAT_PRDINTSTAT12)
  107. /* Interrupt Generated when Timer 12 in capture mode */
  108. #define TMR_INTSTAT12_TIMER_CAPT (TMR_INTCTLSTAT_EVTINTSTAT12)
  109. /* Interrupt Generated when Timer 34 in 64 Bit/32 Bit/WDT mode */
  110. #define TMR_INTSTAT34_TIMER_NON_CAPT (TMR_INTCTLSTAT_PRDINTSTAT34)
  111. /* Interrupt Generated when Timer 34 in capture mode */
  112. #define TMR_INTSTAT34_TIMER_CAPT (TMR_INTCTLSTAT_EVTINTSTAT12)
  113. /*****************************************************************************/
  114. /*
  115. ** Values that can be passed to TimerCaptureConfig as cfgCap
  116. */
  117. /* Disable Capture Mode */
  118. #define TMR_CAPT_DISABLE (0x00000000)
  119. /* Enable Capture Mode. Event Occurs in rising edge */
  120. #define TMR_CAPT_ENABLE_RIS_EDGE (0x08000800)
  121. /* Enable Capture Mode. Event Occurs in falling edge */
  122. #define TMR_CAPT_ENABLE_FALL_EDGE (0x18001800)
  123. /* Enable Capture Mode. Event Occurs in both edges */
  124. #define TMR_CAPT_ENABLE_BOTH_EDGE (0x28002800)
  125. /*****************************************************************************/
  126. /*
  127. ** Values that can be passed to TimerPulseWidthSet as pulseWidth
  128. */
  129. #define TMR_PULSE_WIDTH_1_CLK (0x00000000) /* 1 clock cycle */
  130. #define TMR_PULSE_WIDTH_2_CLK (0x00100010) /* 2 clock cycles */
  131. #define TMR_PULSE_WIDTH_3_CLK (0x00200020) /* 3 clock cycles */
  132. #define TMR_PULSE_WIDTH_4_CLK (0x00300030) /* 4 clock cycles */
  133. /*****************************************************************************/
  134. /*
  135. ** Values returned by TimerOUTStatusGet API
  136. */
  137. #define TMR_OUT12_ASSERTED (TMR_TCR_TSTAT12) /* TMR64P_OUT12 */
  138. #define TMR_OUT34_ASSERTED (TMR_TCR_TSTAT34) /* TMR64P_OUT34 */
  139. /*****************************************************************************/
  140. /*
  141. ** Prototypes for the APIs
  142. */
  143. extern unsigned int TimerCompareGet(unsigned int baseAddr,
  144. unsigned int regIndex);
  145. extern unsigned int TimerOUTStatusGet(unsigned int baseAddr,
  146. unsigned int timer);
  147. extern unsigned int TimerIntStatusGet(unsigned int baseAddr,
  148. unsigned int statFlag);
  149. extern unsigned int TimerIntStatusClear(unsigned int baseAddr,
  150. unsigned int statFlag);
  151. extern unsigned int TimerCaptureGet(unsigned int baseAddr,unsigned int timer);
  152. extern unsigned int TimerCounterGet(unsigned int baseAddr, unsigned int timer);
  153. extern unsigned int TimerPeriodGet(unsigned int baseAddr, unsigned int timer);
  154. extern unsigned int TimerReloadGet(unsigned int baseAddr, unsigned int timer);
  155. extern unsigned int TimerPreScalarCount34Get(unsigned int baseAddr);
  156. extern unsigned int TimerDivDwnRatio34Get(unsigned int baseAddr);
  157. extern void TimerCounterSet(unsigned int baseAddr, unsigned int timer,
  158. unsigned int counter);
  159. extern void TimerPeriodSet(unsigned int baseAddr, unsigned int timer,
  160. unsigned int period);
  161. extern void TimerReloadSet(unsigned int baseAddr, unsigned int timer,
  162. unsigned int reload);
  163. extern void TimerEnable(unsigned int baseAddr, unsigned int timer,
  164. unsigned int enaMode);
  165. extern void TimerPreScalarCount34Set(unsigned int baseAddr,
  166. unsigned int psc34);
  167. extern void TimerDivDwnRatio34Set(unsigned int baseAddr, unsigned int tddr34);
  168. extern void TimerInvertOUTDisable(unsigned int baseAddr, unsigned int timer);
  169. extern void TimerReadResetDisable(unsigned int baseAddr, unsigned int timer);
  170. extern void TimerInputGateDisable(unsigned int baseAddr, unsigned int timer);
  171. extern void TimerReadResetEnable(unsigned int baseAddr, unsigned int timer);
  172. extern void TimerInvertINDisable(unsigned int baseAddr, unsigned int timer);
  173. extern void TimerInvertOUTEnable(unsigned int baseAddr, unsigned int timer);
  174. extern void TimerInputGateEnable(unsigned int baseAddr, unsigned int timer);
  175. extern void TimerInvertINEnable(unsigned int baseAddr, unsigned int timer);
  176. extern void TimerIntDisable(unsigned int baseAddr, unsigned int intFlags);
  177. extern void TimerClockModeSet(unsigned int baseAddr, unsigned int timer);
  178. extern void TimerPulseModeSet(unsigned int baseAddr, unsigned int timer);
  179. extern void TimerIntEnable(unsigned int baseAddr, unsigned int intFlags);
  180. extern void TimerConfigure(unsigned int baseAddr, unsigned int config);
  181. extern void TimerDisable(unsigned int baseAddr, unsigned int timer);
  182. extern void TimerWatchdogReactivate(unsigned int baseAddr);
  183. extern void TimerWatchdogActivate(unsigned int baseAddr);
  184. extern void TimerCaptureConfigure(unsigned int baseAddr, unsigned int timer,
  185. unsigned int cfgCap);
  186. extern void TimerCompareSet(unsigned int baseAddr, unsigned int regIndex,
  187. unsigned int compare);
  188. extern void TimerPulseWidthSet(unsigned int baseAddr, unsigned int timer,
  189. unsigned int pulseWidth);
  190. #ifdef __cplusplus
  191. }
  192. #endif
  193. #endif /* __TIMER_H__ */