dmtimer.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /**
  2. * \file dmtimer.h
  3. *
  4. * \brief DMTimer API prototypes 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 _DMTIMER_H_
  42. #define _DMTIMER_H_
  43. #include "hw_dmtimer.h"
  44. #include "hw_types.h"
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /*****************************************************************************/
  49. /*
  50. ** Values that can be passed to DMTimerPreScalerClkEnable as ptv so as to derive
  51. ** Pre-Scalar clock from timer clock.
  52. */
  53. /* Value used to divide timer clock by 2 */
  54. #define DMTIMER_PRESCALER_CLK_DIV_BY_2 ((0 << DMTIMER_TCLR_PTV_SHIFT) | \
  55. DMTIMER_TCLR_PRE)
  56. /* Value used to divide timer clock by 4 */
  57. #define DMTIMER_PRESCALER_CLK_DIV_BY_4 ((1 << DMTIMER_TCLR_PTV_SHIFT) | \
  58. DMTIMER_TCLR_PRE)
  59. /* Value used to divide timer clock by 8 */
  60. #define DMTIMER_PRESCALER_CLK_DIV_BY_8 ((2 << DMTIMER_TCLR_PTV_SHIFT) | \
  61. DMTIMER_TCLR_PRE)
  62. /* Value used to divide timer clock by 16 */
  63. #define DMTIMER_PRESCALER_CLK_DIV_BY_16 ((3 << DMTIMER_TCLR_PTV_SHIFT) | \
  64. DMTIMER_TCLR_PRE)
  65. /* Value used to divide timer clock by 32 */
  66. #define DMTIMER_PRESCALER_CLK_DIV_BY_32 ((4 << DMTIMER_TCLR_PTV_SHIFT) | \
  67. DMTIMER_TCLR_PRE)
  68. /* Value used to divide timer clock by 64 */
  69. #define DMTIMER_PRESCALER_CLK_DIV_BY_64 ((5 << DMTIMER_TCLR_PTV_SHIFT) | \
  70. DMTIMER_TCLR_PRE)
  71. /* Value used to divide timer clock by 128 */
  72. #define DMTIMER_PRESCALER_CLK_DIV_BY_128 ((6 << DMTIMER_TCLR_PTV_SHIFT) | \
  73. DMTIMER_TCLR_PRE)
  74. /* Value used to divide timer clock by 256 */
  75. #define DMTIMER_PRESCALER_CLK_DIV_BY_256 ((7 << DMTIMER_TCLR_PTV_SHIFT) | \
  76. DMTIMER_TCLR_PRE)
  77. /******************************************************************************/
  78. /*
  79. ** Values that can be passed to DMTimerModeConfigure as timerMode.
  80. */
  81. /* Value used to enable the timer in one-shot and compare mode */
  82. #define DMTIMER_ONESHOT_CMP_ENABLE (DMTIMER_TCLR_CE)
  83. /* Value used to enable the timer only in one-shot mode */
  84. #define DMTIMER_ONESHOT_NOCMP_ENABLE (0x0000000)
  85. /* Value used to enable the timer in auto-reload and compare mode */
  86. #define DMTIMER_AUTORLD_CMP_ENABLE (DMTIMER_TCLR_AR | DMTIMER_TCLR_CE)
  87. /* Value used to enable the timer only in auto-reload mode */
  88. #define DMTIMER_AUTORLD_NOCMP_ENABLE (DMTIMER_TCLR_AR)
  89. /******************************************************************************/
  90. /*
  91. ** Values that can be passed to DMTimerGPOConfigure as gpoCfg.
  92. */
  93. /* Value used to drive 0 on PORGPOCFG pin */
  94. #define DMTIMER_GPO_CFG_0 (DMTIMER_TCLR_GPO_CFG_DRIVE0)
  95. /* Value used to drive 1 on PORGPOCFG pin */
  96. #define DMTIMER_GPO_CFG_1 (DMTIMER_TCLR_GPO_CFG_DRIVE1 << \
  97. DMTIMER_TCLR_GPO_CFG_SHIFT)
  98. /******************************************************************************/
  99. /*
  100. ** Values that can be passed to DMTimerIntStatusClear/DMTimerIntRawStatusSet/
  101. ** as intFlags. Also these values can be used while checking the status got from
  102. ** DMTimerIntRawStatusGet/DMTimerIntStatusGet.
  103. ** Any combination is also followed.
  104. ** Example- (DMTIMER_INT_TCAR_IT_FLAG | DMTIMER_INT_OVF_IT_FLAG)
  105. */
  106. /* Value used for capture event of DMTimer */
  107. #define DMTIMER_INT_TCAR_IT_FLAG (DMTIMER_IRQSTATUS_RAW_TCAR_IT_FLAG)
  108. /* Value used for overflow event of DMTimer */
  109. #define DMTIMER_INT_OVF_IT_FLAG (DMTIMER_IRQSTATUS_RAW_OVF_IT_FLAG)
  110. /* Value used for Match event of DMTimer */
  111. #define DMTIMER_INT_MAT_IT_FLAG (DMTIMER_IRQSTATUS_RAW_MAT_IT_FLAG)
  112. /******************************************************************************/
  113. /*
  114. ** Values that can be passed to DMTimerIntEnable/DMTimerIntDisable as intFlags.
  115. ** Also these values can be used while checking the status got from
  116. ** DMTimerIntEnableGet.
  117. ** Any combination is also followed.
  118. ** Example- (DMTIMER_INT_TCAR_EN_FLAG | DMTIMER_INT_OVF_EN_FLAG)
  119. */
  120. /* Value used for capture event of DMTimer */
  121. #define DMTIMER_INT_TCAR_EN_FLAG (DMTIMER_IRQENABLE_SET_TCAR_EN_FLAG)
  122. /* Value used for overflow event of DMTimer */
  123. #define DMTIMER_INT_OVF_EN_FLAG (DMTIMER_IRQENABLE_SET_OVF_EN_FLAG)
  124. /* Value used for Match event of DMTimer */
  125. #define DMTIMER_INT_MAT_EN_FLAG (DMTIMER_IRQENABLE_SET_MAT_EN_FLAG)
  126. /******************************************************************************/
  127. /*
  128. ** Values that can be passed to DMTimerResetConfigure as rstOption.
  129. */
  130. /* Value used to enable software reset for DMTimer */
  131. #define DMTIMER_SFT_RESET_ENABLE (DMTIMER_TSICR_SFT_RESETENABLE)
  132. /* Value used to disable software reset for DMTimer */
  133. #define DMTIMER_SFT_RESET_DISABLE (DMTIMER_TSICR_SFT)
  134. /******************************************************************************/
  135. /*
  136. ** Values that can be used while checking the status received from
  137. ** DMTimerIsResetDone.
  138. */
  139. /* Value used to check whether reset is done */
  140. #define DMTIMER_IS_RESET_DONE (DMTIMER_TIOCP_CFG_SOFTRESET_DONE)
  141. /* Value used to check whether reset is ongoing */
  142. #define DMTIMER_IS_RESET_ONGOING (DMTIMER_TIOCP_CFG_SOFTRESET_ONGOING)
  143. /******************************************************************************/
  144. /*
  145. ** Values that can be passed to DMTimerPostedModeConfig as postMode.
  146. */
  147. /* Value used to enable the posted mode of operation */
  148. #define DMTIMER_POSTED (DMTIMER_TSICR_POSTED)
  149. /* Value used to disable the posted mode of operation */
  150. #define DMTIMER_NONPOSTED (DMTIMER_TSICR_POSTED_INACTIVE)
  151. /******************************************************************************/
  152. /*
  153. ** Values that can be used while checking status received from
  154. ** DMTimerWritePostedStatusGet API.
  155. */
  156. /* Value used to check the write posted condition for TMAR register */
  157. #define DMTIMER_WRITE_POST_TMAR (DMTIMER_TWPS_W_PEND_TMAR)
  158. /* Value used to check the write posted condition for TTGR register */
  159. #define DMTIMER_WRITE_POST_TTGR (DMTIMER_TWPS_W_PEND_TTGR)
  160. /* Value used to check the write posted condition for TLDR register */
  161. #define DMTIMER_WRITE_POST_TLDR (DMTIMER_TWPS_W_PEND_TLDR)
  162. /* Value used to check the write posted condition for TCRR register */
  163. #define DMTIMER_WRITE_POST_TCRR (DMTIMER_TWPS_W_PEND_TCRR)
  164. /* Value used to check the write posted condition for TCLR register */
  165. #define DMTIMER_WRITE_POST_TCLR (DMTIMER_TWPS_W_PEND_TCLR)
  166. /******************************************************************************/
  167. /*
  168. ** Structure to store the DM timer context
  169. */
  170. typedef struct dmtimerContext{
  171. unsigned int tldr;
  172. unsigned int tmar;
  173. unsigned int irqenableset;
  174. unsigned int tcrr;
  175. unsigned int tclr;
  176. }DMTIMERCONTEXT;
  177. /*
  178. ** Prototype of the APIs
  179. */
  180. extern void DMTimerEnable(unsigned int baseAdd);
  181. extern void DMTimerDisable(unsigned int baseAdd);
  182. extern void DMTimerModeConfigure(unsigned int baseAdd, unsigned int timerMode);
  183. extern void DMTimerPreScalerClkEnable(unsigned int baseAdd, unsigned int ptv);
  184. extern void DMTimerPreScalerClkDisable(unsigned int baseAdd);
  185. extern void DMTimerCounterSet(unsigned int baseAdd, unsigned int counter);
  186. extern unsigned int DMTimerCounterGet(unsigned int baseAdd);
  187. extern void DMTimerReloadSet(unsigned int baseAdd, unsigned int reload);
  188. extern unsigned int DMTimerReloadGet(unsigned int baseAdd);
  189. extern void DMTimerGPOConfigure(unsigned int baseAdd, unsigned int gpoCfg);
  190. extern void DMTimerCompareSet(unsigned int baseAdd, unsigned int compareVal);
  191. extern unsigned int DMTimerCompareGet(unsigned int baseAdd);
  192. extern void DMTimerEmulationModeConfigure(unsigned int baseAdd, unsigned int emuMode);
  193. extern void DMTimerIntRawStatusSet(unsigned int baseAdd, unsigned int intFlags);
  194. extern unsigned int DMTimerIntRawStatusGet(unsigned int baseAdd);
  195. extern unsigned int DMTimerIntStatusGet(unsigned int baseAdd);
  196. extern void DMTimerIntStatusClear(unsigned int baseAdd, unsigned int intFlags);
  197. extern void DMTimerIntEnable(unsigned int baseAdd, unsigned int intFlags);
  198. extern void DMTimerIntDisable(unsigned int baseAdd, unsigned int intFlags);
  199. extern void DMTimerTriggerSet(unsigned int baseAdd);
  200. extern unsigned int DMTimerIntEnableGet(unsigned int baseAdd);
  201. extern void DMTimerResetConfigure(unsigned int baseAdd, unsigned int rstOption);
  202. extern void DMTimerReset(unsigned int baseAdd);
  203. extern void DMTimerContextSave(unsigned int baseAdd, DMTIMERCONTEXT *contextPtr);
  204. extern void DMTimerContextRestore(unsigned int baseAdd, DMTIMERCONTEXT *contextPtr);
  205. extern void DMTimerPostedModeConfig(unsigned int baseAdd, unsigned int postMode);
  206. extern unsigned int DMTimerWritePostedStatusGet(unsigned int baseAdd);
  207. #ifdef __cplusplus
  208. }
  209. #endif
  210. #endif