drv_uart.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2006-2024, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023/06/25 flyingcys first version
  9. */
  10. #ifndef __DRV_USART_H__
  11. #define __DRV_USART_H__
  12. #include <rtthread.h>
  13. #include "rtdevice.h"
  14. #include <rthw.h>
  15. #include "pinctrl.h"
  16. #include "mmio.h"
  17. #define UART_REG_SHIFT 0x2 /* Register Shift*/
  18. #define UART_INPUT_CLK 25000000
  19. #define UART0_BASE 0x04140000
  20. #define UART1_BASE 0x04150000
  21. #define UART2_BASE 0x04160000
  22. #define UART3_BASE 0x04170000
  23. #define UART4_BASE 0x041C0000
  24. #define UART0_IRQ (UART_IRQ_BASE + 0)
  25. #define UART1_IRQ (UART_IRQ_BASE + 1)
  26. #define UART2_IRQ (UART_IRQ_BASE + 2)
  27. #define UART3_IRQ (UART_IRQ_BASE + 3)
  28. #define UART4_IRQ (UART_IRQ_BASE + 4)
  29. /*
  30. * The Synopsys DesignWare 8250 has an extra feature whereby it detects if the
  31. * LCR is written whilst busy. If it is, then a busy detect interrupt is
  32. * raised, the LCR needs to be rewritten and the uart status register read.
  33. */
  34. #define UART_RX 0 /* In: Receive buffer */
  35. #define UART_TX 0 /* Out: Transmit buffer */
  36. #define UART_DLL 0 /* Out: Divisor Latch Low */
  37. #define UART_DLM 1 /* Out: Divisor Latch High */
  38. #define UART_IER 1 /* Out: Interrupt Enable Register */
  39. #define UART_IER_RDI 0x01 /* Enable receiver data interrupt */
  40. #define UART_SSR 0x22 /* In: Software Reset Register */
  41. #define UART_USR 0x1f /* UART Status Register */
  42. #define UART_IIR 2 /* In: Interrupt ID Register */
  43. #define UART_IIR_NO_INT 0x01 /* No interrupts pending */
  44. #define UART_IIR_BUSY 0x07 /* DesignWare APB Busy Detect */
  45. #define UART_IIR_RX_TIMEOUT 0x0c /* OMAP RX Timeout interrupt */
  46. #define UART_FCR 2 /* Out: FIFO Control Register */
  47. #define UART_FCR_FIFO_EN 0x01 /* Fifo enable */
  48. #define UART_FCR_RXSR 0x02 /* Receiver soft reset */
  49. #define UART_FCR_TXSR 0x04 /* Transmitter soft reset */
  50. #define UART_LCR 3 /* Out: Line Control Register */
  51. #define UART_LCR_WLS_MSK 0x03 /* character length select mask */
  52. #define UART_LCR_WLS_5 0x00 /* 5 bit character length */
  53. #define UART_LCR_WLS_6 0x01 /* 6 bit character length */
  54. #define UART_LCR_WLS_7 0x02 /* 7 bit character length */
  55. #define UART_LCR_WLS_8 0x03 /* 8 bit character length */
  56. #define UART_LCR_STB 0x04 /* # stop Bits, off=1, on=1.5 or 2) */
  57. #define UART_LCR_PEN 0x08 /* Parity eneble */
  58. #define UART_LCR_EPS 0x10 /* Even Parity Select */
  59. #define UART_LCR_STKP 0x20 /* Stick Parity */
  60. #define UART_LCR_SBRK 0x40 /* Set Break */
  61. #define UART_LCR_BKSE 0x80 /* Bank select enable */
  62. #define UART_LCR_DLAB 0x80 /* Divisor latch access bit */
  63. #define UART_MCR 4 /* Out: Modem Control Register */
  64. #define UART_MCR_DTR 0x01 /* DTR */
  65. #define UART_MCR_RTS 0x02 /* RTS */
  66. #define UART_LSR 5 /* In: Line Status Register */
  67. #define UART_LSR_BI 0x10 /* Break interrupt indicator */
  68. #define UART_LSR_DR 0x01 /* Receiver data ready */
  69. #define UART_LSR_TEMT 0x40 /* Transmitter empty */
  70. #define UART_LSR_THRE 0x20 /* Transmit-hold-register empty */
  71. #define UART_MCRVAL (UART_MCR_DTR | UART_MCR_RTS) /* RTS/DTR */
  72. /* Clear & enable FIFOs */
  73. #define UART_FCR_DEFVAL (UART_FCR_FIFO_EN | UART_FCR_RXSR | UART_FCR_TXSR)
  74. #define UART_LCR_8N1 0x03
  75. int rt_hw_uart_init(void);
  76. #endif /* __DRV_USART_H__ */