serial.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * File : serial.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development 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://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-03-13 Bernard first version
  13. * 2009-04-20 yi.qiu modified according bernard's stm32 version
  14. * 2010-10-6 wangmeng added sep4020 surpport
  15. */
  16. #ifndef __SERIAL_H__
  17. #define __SERIAL_H__
  18. #include <sep4020.h>
  19. #define USTAT_RCV_READY 0x01 /* receive data ready */
  20. #define USTAT_TXB_EMPTY 0x40 /* tx buffer empty */
  21. #define BPS 115200 /* serial baudrate */
  22. #define UART_RX_BUFFER_SIZE 64
  23. #define UART_TX_BUFFER_SIZE 64
  24. /*For sep4020's uart have several secondary function*/
  25. /*we use union to decribe it*/
  26. union dlbl_fifo
  27. {
  28. rt_uint32_t dlbl;
  29. rt_uint32_t rxfifo;
  30. rt_uint32_t txfifo;
  31. };
  32. union dlbh_ier
  33. {
  34. rt_uint32_t dlbh;
  35. rt_uint32_t ier;
  36. };
  37. union iir_fcr
  38. {
  39. rt_uint32_t iir;
  40. rt_uint32_t fcr;
  41. };
  42. struct serial_int_rx
  43. {
  44. rt_uint8_t rx_buffer[UART_RX_BUFFER_SIZE];
  45. rt_uint32_t read_index, save_index;
  46. };
  47. struct serial_int_tx
  48. {
  49. rt_uint8_t tx_buffer[UART_TX_BUFFER_SIZE];
  50. rt_uint32_t write_index, save_index;
  51. };
  52. typedef struct uartport
  53. {
  54. union dlbl_fifo dlbl_fifo;
  55. union dlbh_ier dlbh_ier;
  56. union iir_fcr iir_fcr;
  57. rt_uint32_t lcr;
  58. rt_uint32_t mcr;
  59. rt_uint32_t lsr;
  60. rt_uint32_t msr;
  61. }uartport;
  62. struct serial_device
  63. {
  64. uartport* uart_device;
  65. /* rx structure */
  66. struct serial_int_rx* int_rx;
  67. /* tx structure */
  68. struct serial_int_tx* int_tx;
  69. };
  70. rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag, struct serial_device *serial);
  71. void rt_hw_serial_isr(rt_device_t device);
  72. #endif