drv_ost.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * File : board_timer.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2015-11-19 Urey the first version
  23. */
  24. #ifndef DRV_OST_H__
  25. #define DRV_OST_H__
  26. #define TCU_TSTR (0xF0) /* Timer Status Register,Only Used In Tcu2 Mode */
  27. #define TCU_TSTSR (0xF4) /* Timer Status Set Register */
  28. #define TCU_TSTCR (0xF8) /* Timer Status Clear Register */
  29. #define TCU_TSR (0x1C) /* Timer Stop Register */
  30. #define TCU_TSSR (0x2C) /* Timer Stop Set Register */
  31. #define TCU_TSCR (0x3C) /* Timer Stop Clear Register */
  32. #define TCU_TER (0x10) /* Timer Counter Enable Register */
  33. #define TCU_TESR (0x14) /* Timer Counter Enable Set Register */
  34. #define TCU_TECR (0x18) /* Timer Counter Enable Clear Register */
  35. #define TCU_TFR (0x20) /* Timer Flag Register */
  36. #define TCU_TFSR (0x24) /* Timer Flag Set Register */
  37. #define TCU_TFCR (0x28) /* Timer Flag Clear Register */
  38. #define TCU_TMR (0x30) /* Timer Mask Register */
  39. #define TCU_TMSR (0x34) /* Timer Mask Set Register */
  40. #define TCU_TMCR (0x38) /* Timer Mask Clear Register */
  41. #define CH_TDFR(n) (0x40 + (n)*0x10) /* Timer Data Full Reg */
  42. #define CH_TDHR(n) (0x44 + (n)*0x10) /* Timer Data Half Reg */
  43. #define CH_TCNT(n) (0x48 + (n)*0x10) /* Timer Counter Reg */
  44. #define CH_TCSR(n) (0x4C + (n)*0x10) /* Timer Control Reg */
  45. #define REG_TCU_TSTR REG32(TCU_BASE + (0xF0))
  46. #define REG_TCU_TSTSR REG32(TCU_BASE + (0xF4))
  47. #define REG_TCU_TSTCR REG32(TCU_BASE + (0xF8))
  48. #define REG_TCU_TSR REG32(TCU_BASE + (0x1C))
  49. #define REG_TCU_TSSR REG32(TCU_BASE + (0x2C))
  50. #define REG_TCU_TSCR REG32(TCU_BASE + (0x3C))
  51. #define REG_TCU_TER REG32(TCU_BASE + (0x10))
  52. #define REG_TCU_TESR REG32(TCU_BASE + (0x14))
  53. #define REG_TCU_TECR REG16(TCU_BASE + (0x18))
  54. #define REG_TCU_TFR REG32(TCU_BASE + (0x20))
  55. #define REG_TCU_TFSR REG32(TCU_BASE + (0x24))
  56. #define REG_TCU_TFCR REG32(TCU_BASE + (0x28))
  57. #define REG_TCU_TMR REG32(TCU_BASE + (0x30))
  58. #define REG_TCU_TMSR REG32(TCU_BASE + (0x34))
  59. #define REG_TCU_TMCR REG32(TCU_BASE + (0x38))
  60. #define REG_CH_TDFR(n) REG32(TCU_BASE + (0x40 + (n)*0x10))
  61. #define REG_CH_TDHR(n) REG32(TCU_BASE + (0x44 + (n)*0x10))
  62. #define REG_CH_TCNT(n) REG32(TCU_BASE + (0x48 + (n)*0x10))
  63. #define REG_CH_TCSR(n) REG32(TCU_BASE + (0x4C + (n)*0x10))
  64. #define TER_OSTEN (1 << 15) /* enable the counter in ost */
  65. #define TMR_OSTM (1 << 15) /* ost comparison match interrupt mask */
  66. #define TFR_OSTF (1 << 15) /* ost interrupt flag */
  67. #define TSR_OSTS (1 << 15) /*the clock supplies to osts is stopped */
  68. #define TSR_WDTS (1 << 16) /*the clock supplies to wdt is stopped */
  69. // Register bits definitions
  70. #define TSTR_REAL2 (1 << 18) /* only used in TCU2 mode */
  71. #define TSTR_REAL1 (1 << 17) /* only used in TCU2 mode */
  72. #define TSTR_BUSY2 (1 << 2) /* only used in TCU2 mode */
  73. #define TSTR_BUSY1 (1 << 1) /* only used in TCU2 mode */
  74. #define TCSR_CNT_CLRZ (1 << 10) /* clear counter to 0, only used in TCU2 mode */
  75. #define TCSR_PWM_SD (1 << 9) /* shut down the pwm output only used in TCU1 mode */
  76. #define TCSR_PWM_HIGH (1 << 8) /* selects an initial output level for pwm output */
  77. #define TCSR_PWM_EN (1 << 7) /* pwm pin output enable */
  78. /*********************************************************************************************************
  79. ** OST
  80. *********************************************************************************************************/
  81. #define REG_OSTCCR REG32(OST_BASE + 0x00)
  82. #define REG_OSTER REG32(OST_BASE + 0x04)
  83. #define REG_OSTCR REG32(OST_BASE + 0x08)
  84. #define REG_OSTFR REG32(OST_BASE + 0x0C)
  85. #define REG_OSTMR REG32(OST_BASE + 0x10)
  86. #define REG_OST1DFR REG32(OST_BASE + 0x14)
  87. #define REG_OST1CNT REG32(OST_BASE + 0x18)
  88. #define REG_OST2CNTL REG32(OST_BASE + 0x20)
  89. #define REG_OSTCNT2HBUF REG32(OST_BASE + 0x24)
  90. #define REG_OSTESR REG32(OST_BASE + 0x34)
  91. #define REG_OSTECR REG32(OST_BASE + 0x38)
  92. /*
  93. * Operating system timer module(OST) address definition
  94. */
  95. #define OST_DR (0xE0)
  96. #define OST_CNTL (0xE4)
  97. #define OST_CNTH (0xE8)
  98. #define OST_CSR (0xEC)
  99. #define OST_CNTH_BUF (0xFC)
  100. #define REG_OST_DR REG32(OST_BASE + (0xE0))
  101. #define REG_OST_CNTL REG32(OST_BASE + (0xE4))
  102. #define REG_OST_CNTH REG32(OST_BASE + (0xE8))
  103. #define REG_OST_CSR REG16(OST_BASE + (0xEC))
  104. #define REG_OST_CNTH_BUF REG32(OST_BASE + (0xFC))
  105. /* Operating system control register(OSTCSR) */
  106. #define OST_CSR_CNT_MD (1 << 15)
  107. #define CSR_EXT_EN (1 << 2) /* select extal as the timer clock input */
  108. #define CSR_RTC_EN (1 << 1) /* select rtcclk as the timer clock input */
  109. #define CSR_PCK_EN (1 << 0) /* select pclk as the timer clock input */
  110. #define CSR_CLK_MSK (0x7)
  111. #define CSR_DIV1 (0x0 << 3)
  112. #define CSR_DIV4 (0x1 << 3)
  113. #define CSR_DIV16 (0x2 << 3)
  114. #define CSR_DIV64 (0x3 << 3)
  115. #define CSR_DIV256 (0x4 << 3)
  116. #define CSR_DIV1024 (0x5 << 3)
  117. #define CSR_DIV_MSK (0x7 << 3)
  118. #define OST_DIV1 (0x0)
  119. #define OST_DIV4 (0x1)
  120. #define OST_DIV16 (0x2)
  121. int rt_hw_ost_init(void);
  122. #endif