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