lpc_tim.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #ifndef _ARCH_CM3_NXP_MACH_LPC_TIM_H_
  2. #define _ARCH_CM3_NXP_MACH_LPC_TIM_H_
  3. /*
  4. * Copyright 2011 by egnite GmbH
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*!
  35. * \file arch/cm3/nxp/mach/lpc_tim.h
  36. * \brief LPC timer/counter definitions
  37. *
  38. * \verbatim
  39. * $Id$
  40. * \endverbatim
  41. */
  42. /*!
  43. * \addtogroup xgNutArchArmLpcTim
  44. */
  45. /*@{*/
  46. /*! \name Timer Interrupt Register */
  47. /*@{*/
  48. #define TIM_IR_OFF 0x00000000
  49. #define TIM_IR_MR0 0x00000001
  50. #define TIM_IR_MR1 0x00000002
  51. #define TIM_IR_MR2 0x00000004
  52. #define TIM_IR_MR3 0x00000008
  53. #define TIM_IR_MR(x) _BV(x)
  54. #define TIM_IR_CR0 0x00000010
  55. #define TIM_IR_CR1 0x00000020
  56. #define TIM_IR_CR(x) _BV((x) + 4)
  57. /*@}*/
  58. /*! \name Timer Control Register */
  59. /*@{*/
  60. #define TIM_TCR_OFF 0x00000004
  61. #define TIM_TCR_ENA 0x00000001
  62. #define TIM_ENABLE TIM_TCR_ENA
  63. #define TIM_TCR_RST 0x00000002
  64. #define TIM_RESET TIM_TCR_RST
  65. /*@}*/
  66. /*! \name Timer Counter Register */
  67. /*@{*/
  68. #define TIM_TC_OFF 0x00000008
  69. /*@}*/
  70. /*! \name Timer Prescale Register */
  71. /*@{*/
  72. #define TIM_PR_OFF 0x0000000C
  73. /*@}*/
  74. /*! \name Timer Prescale Counter Register */
  75. /*@{*/
  76. #define TIM_PC_OFF 0x00000010
  77. /*@}*/
  78. /*! \name Timer Match Control Register */
  79. /*@{*/
  80. #define TIM_MCR_OFF 0x00000014
  81. #define TIM_MCR_MR0I 0x00000001
  82. #define TIM_MCR_MR0R 0x00000002
  83. #define TIM_MCR_MR0S 0x00000004
  84. #define TIM_MCR_MR1I 0x00000008
  85. #define TIM_MCR_MR1R 0x00000010
  86. #define TIM_MCR_MR1S 0x00000020
  87. #define TIM_MCR_MR2I 0x00000040
  88. #define TIM_MCR_MR2R 0x00000080
  89. #define TIM_MCR_MR2S 0x00000100
  90. #define TIM_MCR_MR3I 0x00000200
  91. #define TIM_MCR_MR3R 0x00000400
  92. #define TIM_MCR_MR3S 0x00000800
  93. #define TIM_INT_ON_MATCH(x) _BV((x) * 3)
  94. #define TIM_RESET_ON_MATCH(x) _BV((x) * 3 + 1)
  95. #define TIM_STOP_ON_MATCH(x) _BV((x) * 3 + 2)
  96. #define TIM_MCR_CHANNEL_MASK(x) (7 << ((x) * 3))
  97. /*@}*/
  98. /*! \name Timer Match Registers */
  99. /*@{*/
  100. #define TIM_MR_OFF(x) (0x00000018 + ((x) * 4))
  101. /*@}*/
  102. /*! \name Timer Capture Control Register */
  103. /*@{*/
  104. #define TIM_CCR_OFF 0x00000028
  105. #define TIM_CAP_RISING(x) _BV((x) * 3)
  106. #define TIM_CAP_FALLING(x) _BV((x) * 3 + 1)
  107. #define TIM_INT_ON_CAP(x) _BV((x) * 3 + 2)
  108. #define TIM_EDGE_MASK(x) (3 << ((x) * 3))
  109. #define TIM_CCR_CHANNEL_MASK(x) (7 << ((x) * 3))
  110. /*@}*/
  111. /*! \name Timer Capture Registers */
  112. /*@{*/
  113. #define TIM_CR_OFF(x) (0x0000002C + ((x) * 4)
  114. /*@}*/
  115. /*! \name Timer External Match Register */
  116. /*@{*/
  117. #define TIM_EMR_OFF 0x0000003C
  118. #define TIM_EM(x) _BV(x)
  119. #define TIM_EM_NOTHING 0x0
  120. #define TIM_EM_LOW 0x1
  121. #define TIM_EM_HIGH 0x2
  122. #define TIM_EM_TOGGLE 0x3
  123. #define TIM_EM_SET(x,f) ((f) << ((x) + 4))
  124. #define TIM_EM_MASK(x) (3 << ((x) + 4))
  125. /*@}*/
  126. /*! \name Timer Count Control Register */
  127. /*@{*/
  128. #define TIM_CTCR_OFF 0x00000070
  129. #define TIM_TIMER_MODE 0
  130. #define TIM_COUNTER_RISING_MODE 1
  131. #define TIM_COUNTER_FALLING_MODE 2
  132. #define TIM_COUNTER_ANY_MODE 3
  133. #define TIM_CTCR_MODE_LSB 0
  134. #define TIM_CTCR_MODE_MSK 0x3
  135. #define TIM_CTCR_INPUT_LSB 2
  136. #define TIM_CTCR_INPUT_MSK 0xC
  137. /*@}*/
  138. #if defined(LPC_TIM0_BASE)
  139. #define TIM0IR (LPC_TIM0_BASE + TIM_IR_OFF)
  140. #define TIM0TCR (LPC_TIM0_BASE + TIM_TCR_OFF)
  141. #define TIM0TC (LPC_TIM0_BASE + TIM_TC_OFF)
  142. #define TIM0PR (LPC_TIM0_BASE + TIM_PR_OFF)
  143. #define TIM0PC (LPC_TIM0_BASE + TIM_PC_OFF)
  144. #define TIM0MCR (LPC_TIM0_BASE + TIM_MCR_OFF)
  145. #define TIM0MR(x) (LPC_TIM0_BASE + TIM_MR_OFF(x))
  146. #define TIM0CCR (LPC_TIM0_BASE + TIM_CCR_OFF)
  147. #define TIM0CR(x) (LPC_TIM0_BASE + TIM_CR_OFF(x))
  148. #define TIM0EMR (LPC_TIM0_BASE + TIM_EMR_OFF)
  149. #define TIM0CTCR (LPC_TIM0_BASE + TIM_CTCR_OFF)
  150. #endif
  151. #if defined(LPC_TIM1_BASE)
  152. #define TIM1IR (LPC_TIM1_BASE + TIM_IR_OFF)
  153. #define TIM1TCR (LPC_TIM1_BASE + TIM_TCR_OFF)
  154. #define TIM1TC (LPC_TIM1_BASE + TIM_TC_OFF)
  155. #define TIM1PR (LPC_TIM1_BASE + TIM_PR_OFF)
  156. #define TIM1PC (LPC_TIM1_BASE + TIM_PC_OFF)
  157. #define TIM1MCR (LPC_TIM1_BASE + TIM_MCR_OFF)
  158. #define TIM1MR(x) (LPC_TIM1_BASE + TIM_MR_OFF(x))
  159. #define TIM1CCR (LPC_TIM1_BASE + TIM_CCR_OFF)
  160. #define TIM1CR(x) (LPC_TIM1_BASE + TIM_CR_OFF(x))
  161. #define TIM1EMR (LPC_TIM1_BASE + TIM_EMR_OFF)
  162. #define TIM1CTCR (LPC_TIM1_BASE + TIM_CTCR_OFF)
  163. #endif
  164. #if defined(LPC_TIM2_BASE)
  165. #define TIM2IR (LPC_TIM2_BASE + TIM_IR_OFF)
  166. #define TIM2TCR (LPC_TIM2_BASE + TIM_TCR_OFF)
  167. #define TIM2TC (LPC_TIM2_BASE + TIM_TC_OFF)
  168. #define TIM2PR (LPC_TIM2_BASE + TIM_PR_OFF)
  169. #define TIM2PC (LPC_TIM2_BASE + TIM_PC_OFF)
  170. #define TIM2MCR (LPC_TIM2_BASE + TIM_MCR_OFF)
  171. #define TIM2MR(x) (LPC_TIM2_BASE + TIM_MR_OFF(x))
  172. #define TIM2CCR (LPC_TIM2_BASE + TIM_CCR_OFF)
  173. #define TIM2CR(x) (LPC_TIM2_BASE + TIM_CR_OFF(x))
  174. #define TIM2EMR (LPC_TIM2_BASE + TIM_EMR_OFF)
  175. #define TIM2CTCR (LPC_TIM2_BASE + TIM_CTCR_OFF)
  176. #endif
  177. #if defined(LPC_TIM3_BASE)
  178. #define TIM3IR (LPC_TIM3_BASE + TIM_IR_OFF)
  179. #define TIM3TCR (LPC_TIM3_BASE + TIM_TCR_OFF)
  180. #define TIM3TC (LPC_TIM3_BASE + TIM_TC_OFF)
  181. #define TIM3PR (LPC_TIM3_BASE + TIM_PR_OFF)
  182. #define TIM3PC (LPC_TIM3_BASE + TIM_PC_OFF)
  183. #define TIM3MCR (LPC_TIM3_BASE + TIM_MCR_OFF)
  184. #define TIM3MR(x) (LPC_TIM3_BASE + TIM_MR_OFF(x))
  185. #define TIM3CCR (LPC_TIM3_BASE + TIM_CCR_OFF)
  186. #define TIM3CR(x) (LPC_TIM3_BASE + TIM_CR_OFF(x))
  187. #define TIM3EMR (LPC_TIM3_BASE + TIM_EMR_OFF)
  188. #define TIM3CTCR (LPC_TIM3_BASE + TIM_CTCR_OFF)
  189. #endif
  190. /*@}*/
  191. #endif