drv_uart.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * File : drv_uart.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_UART_H_
  25. #define DRV_UART_H_
  26. /* Uart Register */
  27. #define UART_RDR(base) REG8((base) + 0x00) /* R 8b H'xx */
  28. #define UART_TDR(base) REG8((base) + 0x00) /* W 8b H'xx */
  29. #define UART_DLLR(base) REG8((base) + 0x00) /* RW 8b H'00 */
  30. #define UART_DLHR(base) REG8((base) + 0x04) /* RW 8b H'00 */
  31. #define UART_IER(base) REG8((base) + 0x04) /* RW 8b H'00 */
  32. #define UART_ISR(base) REG8((base) + 0x08) /* R 8b H'01 */
  33. #define UART_FCR(base) REG8((base) + 0x08) /* W 8b H'00 */
  34. #define UART_LCR(base) REG8((base) + 0x0C) /* RW 8b H'00 */
  35. #define UART_MCR(base) REG8((base) + 0x10) /* RW 8b H'00 */
  36. #define UART_LSR(base) REG8((base) + 0x14) /* R 8b H'00 */
  37. #define UART_MSR(base) REG8((base) + 0x18) /* R 8b H'00 */
  38. #define UART_SPR(base) REG8((base) + 0x1C) /* RW 8b H'00 */
  39. #define UART_MCR(base) REG8((base) + 0x10) /* RW 8b H'00 */
  40. #define UART_SIRCR(base) REG8((base) + 0x20) /* RW 8b H'00 */
  41. #define UART_UMR(base) REG8((base) + 0x24) /* W 8b H'00 */
  42. #define UART_UACR(base) REG8((base) + 0x28) /* W 8b H'00 */
  43. /*
  44. * Define macros for UARTIER
  45. * UART Interrupt Enable Register
  46. */
  47. #define UARTIER_RIE (1 << 0) /* 0: receive fifo "full" interrupt disable */
  48. #define UARTIER_TIE (1 << 1) /* 0: transmit fifo "empty" interrupt disable */
  49. #define UARTIER_RLIE (1 << 2) /* 0: receive line status interrupt disable */
  50. #define UARTIER_MIE (1 << 3) /* 0: modem status interrupt disable */
  51. #define UARTIER_RTIE (1 << 4) /* 0: receive timeout interrupt disable */
  52. /*
  53. * Define macros for UARTISR
  54. * UART Interrupt Status Register
  55. */
  56. #define UARTISR_IP (1 << 0) /* 0: interrupt is pending 1: no interrupt */
  57. #define UARTISR_IID (7 << 1) /* Source of Interrupt */
  58. #define UARTISR_IID_MSI (0 << 1) /* Modem status interrupt */
  59. #define UARTISR_IID_THRI (1 << 1) /* Transmitter holding register empty */
  60. #define UARTISR_IID_RDI (2 << 1) /* Receiver data interrupt */
  61. #define UARTISR_IID_RLSI (3 << 1) /* Receiver line status interrupt */
  62. #define UARTISR_FFMS (3 << 6) /* FIFO mode select, set when UARTFCR.FE is set to 1 */
  63. #define UARTISR_FFMS_NO_FIFO (0 << 6)
  64. #define UARTISR_FFMS_FIFO_MODE (3 << 6)
  65. /*
  66. * Define macros for UARTFCR
  67. * UART FIFO Control Register
  68. */
  69. #define UARTFCR_FE (1 << 0) /* 0: non-FIFO mode 1: FIFO mode */
  70. #define UARTFCR_RFLS (1 << 1) /* write 1 to flush receive FIFO */
  71. #define UARTFCR_TFLS (1 << 2) /* write 1 to flush transmit FIFO */
  72. #define UARTFCR_DMS (1 << 3) /* 0: disable DMA mode */
  73. #define UARTFCR_UUE (1 << 4) /* 0: disable UART */
  74. #define UARTFCR_RTRG (3 << 6) /* Receive FIFO Data Trigger */
  75. #define UARTFCR_RTRG_1 (0 << 6)
  76. #define UARTFCR_RTRG_4 (1 << 6)
  77. #define UARTFCR_RTRG_8 (2 << 6)
  78. #define UARTFCR_RTRG_15 (3 << 6)
  79. /*
  80. * Define macros for UARTLCR
  81. * UART Line Control Register
  82. */
  83. #define UARTLCR_WLEN (3 << 0) /* word length */
  84. #define UARTLCR_WLEN_5 (0 << 0)
  85. #define UARTLCR_WLEN_6 (1 << 0)
  86. #define UARTLCR_WLEN_7 (2 << 0)
  87. #define UARTLCR_WLEN_8 (3 << 0)
  88. #define UARTLCR_STOP (1 << 2) /* 0: 1 stop bit when word length is 5,6,7,8
  89. 1: 1.5 stop bits when 5; 2 stop bits when 6,7,8 */
  90. #define UARTLCR_PE (1 << 3) /* 0: parity disable */
  91. #define UARTLCR_PROE (1 << 4) /* 0: even parity 1: odd parity */
  92. #define UARTLCR_SPAR (1 << 5) /* 0: sticky parity disable */
  93. #define UARTLCR_SBRK (1 << 6) /* write 0 normal, write 1 send break */
  94. #define UARTLCR_DLAB (1 << 7) /* 0: access UARTRDR/TDR/IER 1: access UARTDLLR/DLHR */
  95. /*
  96. * Define macros for UARTLSR
  97. * UART Line Status Register
  98. */
  99. #define UARTLSR_DR (1 << 0) /* 0: receive FIFO is empty 1: receive data is ready */
  100. #define UARTLSR_ORER (1 << 1) /* 0: no overrun error */
  101. #define UARTLSR_PER (1 << 2) /* 0: no parity error */
  102. #define UARTLSR_FER (1 << 3) /* 0; no framing error */
  103. #define UARTLSR_BRK (1 << 4) /* 0: no break detected 1: receive a break signal */
  104. #define UARTLSR_TDRQ (1 << 5) /* 1: transmit FIFO half "empty" */
  105. #define UARTLSR_TEMT (1 << 6) /* 1: transmit FIFO and shift registers empty */
  106. #define UARTLSR_RFER (1 << 7) /* 0: no receive error 1: receive error in FIFO mode */
  107. /*
  108. * Define macros for UARTMCR
  109. * UART Modem Control Register
  110. */
  111. #define UARTMCR_DTR (1 << 0) /* 0: DTR_ ouput high */
  112. #define UARTMCR_RTS (1 << 1) /* 0: RTS_ output high */
  113. #define UARTMCR_OUT1 (1 << 2) /* 0: UARTMSR.RI is set to 0 and RI_ input high */
  114. #define UARTMCR_OUT2 (1 << 3) /* 0: UARTMSR.DCD is set to 0 and DCD_ input high */
  115. #define UARTMCR_LOOP (1 << 4) /* 0: normal 1: loopback mode */
  116. #define UARTMCR_FCM (1 << 6) /* 0: flow control by software; 1: hardware */
  117. #define UARTMCR_MCE (1 << 7) /* 0: modem function is disable */
  118. /*
  119. * Define macros for UARTMSR
  120. * UART Modem Status Register
  121. */
  122. #define UARTMSR_DCTS (1 << 0) /* 0: no change on CTS_ pin since last read of UARTMSR */
  123. #define UARTMSR_DDSR (1 << 1) /* 0: no change on DSR_ pin since last read of UARTMSR */
  124. #define UARTMSR_DRI (1 << 2) /* 0: no change on RI_ pin since last read of UARTMSR */
  125. #define UARTMSR_DDCD (1 << 3) /* 0: no change on DCD_ pin since last read of UARTMSR */
  126. #define UARTMSR_CTS (1 << 4) /* 0: CTS_ pin is high */
  127. #define UARTMSR_DSR (1 << 5) /* 0: DSR_ pin is high */
  128. #define UARTMSR_RI (1 << 6) /* 0: RI_ pin is high */
  129. #define UARTMSR_DCD (1 << 7) /* 0: DCD_ pin is high */
  130. /*
  131. * Define macros for SIRCR
  132. * Slow IrDA Control Register
  133. */
  134. #define SIRCR_TSIRE (1 << 0) /* 0: transmitter is in UART mode 1: IrDA mode */
  135. #define SIRCR_RSIRE (1 << 1) /* 0: receiver is in UART mode 1: IrDA mode */
  136. #define SIRCR_TPWS (1 << 2) /* 0: transmit 0 pulse width is 3/16 of bit length
  137. 1: 0 pulse width is 1.6us for 115.2Kbps */
  138. #define SIRCR_TXPL (1 << 3) /* 0: encoder generates a positive pulse for 0 */
  139. #define SIRCR_RXPL (1 << 4) /* 0: decoder interprets positive pulse as 0 */
  140. void rt_hw_uart_init(void);
  141. /* only used for bt_audio */
  142. int uart_set_baudrate(int baudrate);
  143. #endif /* _BOARD_UART_H_ */