uart.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * File : uart.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006-2012, RT-Thread Develop Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-08-08 lgnq first version for LS1B
  13. * 2015-07-06 chinesebear modified for loongson 1c
  14. */
  15. #ifndef __UART_H__
  16. #define __UART_H__
  17. #include "ls1c.h"
  18. #define DEV_CLK 252000000 // 252MHz
  19. #define UART_BAUDRATE 115200
  20. #define UART0_BASE 0xBFE40000
  21. //#define UART0_1_BASE 0xBFE41000
  22. #define UART1_BASE 0xBFE44000
  23. #define UART2_BASE 0xBFE48000
  24. #define UART3_BASE 0xBFE4C000
  25. #define UART4_BASE 0xBFE4C400
  26. #define UART5_BASE 0xBFE4C500
  27. #define UART6_BASE 0xBFE4C600
  28. #define UART7_BASE 0xBFE4C700
  29. #define UART8_BASE 0xBFE4C800
  30. #define UART9_BASE 0xBFE4C900
  31. #define UART10_BASE 0xBFE4Ca00
  32. #define UART11_BASE 0xBFE4Cb00
  33. /* UART registers */
  34. #define UART_DAT(base) __REG8(base + 0x00)
  35. #define UART_IER(base) __REG8(base + 0x01)
  36. #define UART_IIR(base) __REG8(base + 0x02)
  37. #define UART_FCR(base) __REG8(base + 0x02)
  38. #define UART_LCR(base) __REG8(base + 0x03)
  39. #define UART_MCR(base) __REG8(base + 0x04)
  40. #define UART_LSR(base) __REG8(base + 0x05)
  41. #define UART_MSR(base) __REG8(base + 0x06)
  42. #define UART_LSB(base) __REG8(base + 0x00)
  43. #define UART_MSB(base) __REG8(base + 0x01)
  44. /* UART0 registers */
  45. #define UART0_DAT __REG8(UART0_BASE + 0x00)
  46. #define UART0_IER __REG8(UART0_BASE + 0x01)
  47. #define UART0_IIR __REG8(UART0_BASE + 0x02)
  48. #define UART0_FCR __REG8(UART0_BASE + 0x02)
  49. #define UART0_LCR __REG8(UART0_BASE + 0x03)
  50. #define UART0_MCR __REG8(UART0_BASE + 0x04)
  51. #define UART0_LSR __REG8(UART0_BASE + 0x05)
  52. #define UART0_MSR __REG8(UART0_BASE + 0x06)
  53. #define UART0_LSB __REG8(UART0_BASE + 0x00)
  54. #define UART0_MSB __REG8(UART0_BASE + 0x01)
  55. /* UART1 registers */
  56. #define UART1_DAT __REG8(UART1_BASE + 0x00)
  57. #define UART1_IER __REG8(UART1_BASE + 0x01)
  58. #define UART1_IIR __REG8(UART1_BASE + 0x02)
  59. #define UART1_FCR __REG8(UART1_BASE + 0x02)
  60. #define UART1_LCR __REG8(UART1_BASE + 0x03)
  61. #define UART1_MCR __REG8(UART1_BASE + 0x04)
  62. #define UART1_LSR __REG8(UART1_BASE + 0x05)
  63. #define UART1_MSR __REG8(UART1_BASE + 0x06)
  64. #define UART1_LSB __REG8(UART1_BASE + 0x00)
  65. #define UART1_MSB __REG8(UART1_BASE + 0x01)
  66. /* UART interrupt enable register value */
  67. #define UARTIER_IME (1 << 3)
  68. #define UARTIER_ILE (1 << 2)
  69. #define UARTIER_ITXE (1 << 1)
  70. #define UARTIER_IRXE (1 << 0)
  71. /* UART line control register value */
  72. #define UARTLCR_DLAB (1 << 7)
  73. #define UARTLCR_BCB (1 << 6)
  74. #define UARTLCR_SPB (1 << 5)
  75. #define UARTLCR_EPS (1 << 4)
  76. #define UARTLCR_PE (1 << 3)
  77. #define UARTLCR_SB (1 << 2)
  78. /* UART line status register value */
  79. #define UARTLSR_ERROR (1 << 7)
  80. #define UARTLSR_TE (1 << 6)
  81. #define UARTLSR_TFE (1 << 5)
  82. #define UARTLSR_BI (1 << 4)
  83. #define UARTLSR_FE (1 << 3)
  84. #define UARTLSR_PE (1 << 2)
  85. #define UARTLSR_OE (1 << 1)
  86. #define UARTLSR_DR (1 << 0)
  87. void rt_hw_uart_init(void);
  88. #endif