uart.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * File : interrupt.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2015, 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-04-14 ArdaFu first version
  23. */
  24. #ifndef __UART_H__
  25. #define __UART_H__
  26. #define R_VAL 0
  27. #define R_SET 1
  28. #define R_CLR 2
  29. #define R_TOG 3
  30. typedef struct
  31. {
  32. volatile rt_uint32_t CTRL0[4];
  33. volatile rt_uint32_t CTRL1[4];
  34. volatile rt_uint32_t CTRL2[4];
  35. volatile rt_uint32_t LINECTRL[4];
  36. volatile rt_uint32_t INTR[4];
  37. volatile rt_uint32_t DATA[4];
  38. volatile rt_uint32_t STAT[4];
  39. volatile const rt_uint32_t DEBUG[4];
  40. volatile rt_uint32_t ILPR[4];
  41. volatile rt_uint32_t RS485CTRL[4];
  42. volatile rt_uint32_t RS485ADRMATCH[4];
  43. volatile rt_uint32_t RS485DLY[4];
  44. volatile rt_uint32_t AUTOBAUD[4];
  45. volatile rt_uint32_t CTRL3[4];
  46. volatile rt_uint32_t ISO7816CTRL[4];
  47. volatile rt_uint32_t ISO7816ERRCNT[4];
  48. volatile rt_uint32_t ISO7816STATUS[4];
  49. } HW_USART_TypeDef;
  50. #define USART0 ((HW_USART_TypeDef *)UART0_BASE)
  51. #define USART1 ((HW_USART_TypeDef *)UART1_BASE)
  52. #define USART2 ((HW_USART_TypeDef *)UART2_BASE)
  53. #define USART3 ((HW_USART_TypeDef *)UART3_BASE)
  54. #define USART4 ((HW_USART_TypeDef *)UART4_BASE)
  55. #define USART5 ((HW_USART_TypeDef *)UART5_BASE)
  56. #define USART6 ((HW_USART_TypeDef *)UART6_BASE)
  57. #define USART7 ((HW_USART_TypeDef *)UART7_BASE)
  58. #define USART8 ((HW_USART_TypeDef *)UART8_BASE)
  59. #define USART9 ((HW_USART_TypeDef *)UART9_BASE)
  60. #define ASM_UART_INTR_RXIS (1UL << 4)
  61. #define ASM_UART_INTR_TXIS (1UL << 5)
  62. #define ASM_UART_INTR_RTIS (1UL << 6)
  63. #define ASM_UART_INTR_RXIEN (1UL << 20)
  64. #define ASM_UART_INTR_TXIEN (1UL << 21)
  65. #define ASM_UART_INTR_RTIEN (1UL << 22)
  66. #define UART_BAUD_DIVINT_MASK 0x003FFFC0UL
  67. #define UART_BAUD_DIVFRAC_MASK 0x0000003FUL
  68. #define UART_FIFO_ENABLE 0x00000010UL
  69. #define MAIN_CLOCK_EXT12M 0
  70. #define MAIN_CLOCK_SYSPLL 1
  71. #define UART_INT_FIFO_LV_SEL_MASK 0x00770000UL
  72. #define RXTIMEOUT_ENABLE 0x01000000UL
  73. #define RXTIMEOUT_MASK 0x00FF0000UL
  74. #define ASM_UART_CTRL0_SFTRST (1UL << 31)
  75. #define ASM_UART_CTRL0_CLKGATE (1UL << 30)
  76. #define ASM_UART_CTRL0_RXTO_ENABLE (1UL << 24)
  77. #define ASM_UART_CTRL2_USARTEN (1UL << 0)
  78. #define ASM_UART_CTRL2_TXE (1UL << 8)
  79. #define ASM_UART_CTRL2_RXE (1UL << 9)
  80. #define ASM_UART_LINECTRL_PEN (1UL << 1)
  81. #define ASM_UART_LINECTRL_EPS (1UL << 2)
  82. #define ASM_UART_LINECTRL_STP2 (1UL << 3)
  83. #define ASM_UART_LINECTRL_FEN (1UL << 4)
  84. #define ASM_UART_LINECTRL_WLEN5 (0UL << 5)
  85. #define ASM_UART_LINECTRL_WLEN6 (1UL << 5)
  86. #define ASM_UART_LINECTRL_WLEN7 (2UL << 5)
  87. #define ASM_UART_LINECTRL_WLEN8 (3UL << 5)
  88. #define ASM_UART_LINECTRL_SPS (1UL << 7)
  89. #define ASM_UART_STAT_TXFF (1UL << 25)
  90. #define ASM_UART_STAT_RXFE (1UL << 24)
  91. extern void Hw_UartDisable(HW_USART_TypeDef* uartBase);
  92. extern void Hw_UartEnable(HW_USART_TypeDef* uartBase);
  93. extern void Hw_UartReset(HW_USART_TypeDef* uartBase);
  94. extern void Hw_UartConfig(HW_USART_TypeDef* uartBase, int baudRate,
  95. int dataBits, int stopBits, int parity);
  96. extern void Hw_UartInit(int index);
  97. #endif