1 #ifndef __RT_HW_SERIAL_H__
2 #define __RT_HW_SERIAL_H__
3 
4 #include <rthw.h>
5 #include <rtthread.h>
6 
7 #define USTAT_RCV_READY     0x01    /* receive data ready */
8 #define USTAT_TXB_EMPTY     0x02    /* tx buffer empty */
9 #define BPS                 115200  /* serial baudrate */
10 
11 #define UART_RX_BUFFER_SIZE     64
12 #define UART_TX_BUFFER_SIZE     64
13 
14 struct serial_int_rx
15 {
16     rt_uint8_t  rx_buffer[UART_RX_BUFFER_SIZE];
17     rt_uint32_t read_index, save_index;
18 };
19 
20 struct serial_int_tx
21 {
22     rt_uint8_t  tx_buffer[UART_TX_BUFFER_SIZE];
23     rt_uint32_t write_index, save_index;
24 };
25 
26 typedef struct uartport
27 {
28     volatile rt_uint16_t rbr_thr;  //receive buffer register and transmit hold register
29     volatile rt_uint16_t reserved0;
30     volatile rt_uint16_t reserved1;
31     volatile rt_uint16_t reserved2;
32     volatile rt_uint16_t reserved3;
33     volatile rt_uint16_t reserved4;
34     volatile rt_uint16_t reserved5;
35     volatile rt_uint16_t reserved6;
36     volatile rt_uint16_t reserved7;
37     volatile rt_uint16_t reserved8;
38     volatile rt_uint16_t lsr;      //line status register
39 }uartport;
40 
41 struct serial_device
42 {
43     uartport* uart_device;
44 
45     /* rx structure */
46     struct serial_int_rx* int_rx;
47 
48     /* tx structure */
49     struct serial_int_tx* int_tx;
50 };
51 
52 rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag, struct serial_device *serial);
53 
54 void rt_hw_serial_isr(rt_device_t device);
55 
56 #endif
57