drv_uart.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-04-05 bigmagic Initial version
  9. */
  10. #ifndef _DRV_UART_H__
  11. #define _DRV_UART_H__
  12. #include "ls2k1000.h"
  13. #include <rthw.h>
  14. /* UART registers */
  15. #define UART_DAT(base) HWREG8(base + 0x00)
  16. #define UART_IER(base) HWREG8(base + 0x01)
  17. #define UART_IIR(base) HWREG8(base + 0x02)
  18. #define UART_FCR(base) HWREG8(base + 0x02)
  19. #define UART_LCR(base) HWREG8(base + 0x03)
  20. #define UART_MCR(base) HWREG8(base + 0x04)
  21. #define UART_LSR(base) HWREG8(base + 0x05)
  22. #define UART_MSR(base) HWREG8(base + 0x06)
  23. #define UART_LSB(base) HWREG8(base + 0x00)
  24. #define UART_MSB(base) HWREG8(base + 0x01)
  25. /* interrupt enable register */
  26. #define IER_IRxE 0x1
  27. #define IER_ITxE 0x2
  28. #define IER_ILE 0x4
  29. #define IER_IME 0x8
  30. /* interrupt identification register */
  31. #define IIR_IMASK 0xf /* mask */
  32. #define IIR_RXTOUT 0xc /* receive timeout */
  33. #define IIR_RLS 0x6 /* receive line status */
  34. #define IIR_RXRDY 0x4 /* receive ready */
  35. #define IIR_TXRDY 0x2 /* transmit ready */
  36. #define IIR_NOPEND 0x1 /* nothing */
  37. #define IIR_MLSC 0x0 /* modem status */
  38. #define IIR_FIFO_MASK 0xc0 /* set if FIFOs are enabled */
  39. /* fifo control register */
  40. #define FIFO_ENABLE 0x01 /* enable fifo */
  41. #define FIFO_RCV_RST 0x02 /* reset receive fifo */
  42. #define FIFO_XMT_RST 0x04 /* reset transmit fifo */
  43. #define FIFO_DMA_MODE 0x08 /* enable dma mode */
  44. #define FIFO_TRIGGER_1 0x00 /* trigger at 1 char */
  45. #define FIFO_TRIGGER_4 0x40 /* trigger at 4 chars */
  46. #define FIFO_TRIGGER_8 0x80 /* trigger at 8 chars */
  47. #define FIFO_TRIGGER_14 0xc0 /* trigger at 14 chars */
  48. // 线路控制寄存器
  49. /* character format control register */
  50. #define CFCR_DLAB 0x80 /* divisor latch */
  51. #define CFCR_SBREAK 0x40 /* send break */
  52. #define CFCR_PZERO 0x30 /* zero parity */
  53. #define CFCR_PONE 0x20 /* one parity */
  54. #define CFCR_PEVEN 0x10 /* even parity */
  55. #define CFCR_PODD 0x00 /* odd parity */
  56. #define CFCR_PENAB 0x08 /* parity enable */
  57. #define CFCR_STOPB 0x04 /* 2 stop bits */
  58. #define CFCR_8BITS 0x03 /* 8 data bits */
  59. #define CFCR_7BITS 0x02 /* 7 data bits */
  60. #define CFCR_6BITS 0x01 /* 6 data bits */
  61. #define CFCR_5BITS 0x00 /* 5 data bits */
  62. /* modem control register */
  63. #define MCR_LOOPBACK 0x10 /* loopback */
  64. #define MCR_IENABLE 0x08 /* output 2 = int enable */
  65. #define MCR_DRS 0x04 /* output 1 = xxx */
  66. #define MCR_RTS 0x02 /* enable RTS */
  67. #define MCR_DTR 0x01 /* enable DTR */
  68. /* line status register */
  69. #define LSR_RCV_FIFO 0x80 /* error in receive fifo */
  70. #define LSR_TSRE 0x40 /* transmitter empty */
  71. #define LSR_TXRDY 0x20 /* transmitter ready */
  72. #define LSR_BI 0x10 /* break detected */
  73. #define LSR_FE 0x08 /* framing error */
  74. #define LSR_PE 0x04 /* parity error */
  75. #define LSR_OE 0x02 /* overrun error */
  76. #define LSR_RXRDY 0x01 /* receiver ready */
  77. #define LSR_RCV_MASK 0x1f
  78. /* UART interrupt enable register value */
  79. #define UARTIER_IME (1 << 3)
  80. #define UARTIER_ILE (1 << 2)
  81. #define UARTIER_ITXE (1 << 1)
  82. #define UARTIER_IRXE (1 << 0)
  83. /* UART line control register value */
  84. #define UARTLCR_DLAB (1 << 7)
  85. #define UARTLCR_BCB (1 << 6)
  86. #define UARTLCR_SPB (1 << 5)
  87. #define UARTLCR_EPS (1 << 4)
  88. #define UARTLCR_PE (1 << 3)
  89. #define UARTLCR_SB (1 << 2)
  90. /* UART line status register value */
  91. #define UARTLSR_ERROR (1 << 7)
  92. #define UARTLSR_TE (1 << 6)
  93. #define UARTLSR_TFE (1 << 5)
  94. #define UARTLSR_BI (1 << 4)
  95. #define UARTLSR_FE (1 << 3)
  96. #define UARTLSR_PE (1 << 2)
  97. #define UARTLSR_OE (1 << 1)
  98. #define UARTLSR_DR (1 << 0)
  99. #endif