serial.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * File : serial.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2013, 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. * 2006-03-13 Bernard first version
  23. * 2009-04-20 yi.qiu modified according bernard's stm32 version
  24. * 2010-10-6 wangmeng added sep4020 surpport
  25. * 2013-7-15 Peng Fan Modified from sep4020
  26. */
  27. #ifndef __SERIAL_H__
  28. #define __SERIAL_H__
  29. #include <sep6200.h>
  30. #define USTAT_RCV_READY 0x01 /* receive data ready */
  31. #define USTAT_OVERRUN 0x02 /* overrun */
  32. #define USTAT_PARITY_ERR 0x04 /* parity error */
  33. #define USTAT_FRAME_ERROR 0x08 /* frame error */
  34. #define USTAT_BREAK 0x10 /* break */
  35. #define USTAT_TXB_EMPTY 0x40 /* tx buffer empty */
  36. #define USTAT_RCV_ERR 0x80 /* receive error */
  37. #define BPS 115200 /* serial baudrate */
  38. #define UART_RX_BUFFER_SIZE 64
  39. #define UART_TX_BUFFER_SIZE 64
  40. /*For sep6200's uart have several secondary function*/
  41. /*we use union to decribe it*/
  42. union dlbl_fifo
  43. {
  44. rt_uint32_t dlbl;
  45. rt_uint32_t rxfifo;
  46. rt_uint32_t txfifo;
  47. };
  48. union dlbh_ier
  49. {
  50. rt_uint32_t dlbh;
  51. rt_uint32_t ier;
  52. };
  53. union iir_fcr
  54. {
  55. rt_uint32_t iir;
  56. rt_uint32_t fcr;
  57. };
  58. struct serial_int_rx
  59. {
  60. rt_uint8_t rx_buffer[UART_RX_BUFFER_SIZE];
  61. rt_uint32_t read_index, save_index;
  62. };
  63. struct serial_int_tx
  64. {
  65. rt_uint8_t tx_buffer[UART_TX_BUFFER_SIZE];
  66. rt_uint32_t write_index, save_index;
  67. };
  68. typedef struct uartport
  69. {
  70. union dlbl_fifo dlbl_fifo;
  71. union dlbh_ier dlbh_ier;
  72. union iir_fcr iir_fcr;
  73. rt_uint32_t lcr;
  74. rt_uint32_t mcr;
  75. rt_uint32_t lsr;
  76. rt_uint32_t msr;
  77. }uartport;
  78. struct serial_device
  79. {
  80. uartport* uart_device;
  81. /* rx structure */
  82. struct serial_int_rx* int_rx;
  83. /* tx structure */
  84. struct serial_int_tx* int_tx;
  85. };
  86. rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag, struct serial_device *serial);
  87. void rt_hw_serial_isr(rt_device_t device);
  88. #endif