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 28 #ifndef __SERIAL_H__ 29 #define __SERIAL_H__ 30 31 #include <sep6200.h> 32 33 #define USTAT_RCV_READY 0x01 /* receive data ready */ 34 #define USTAT_OVERRUN 0x02 /* overrun */ 35 #define USTAT_PARITY_ERR 0x04 /* parity error */ 36 #define USTAT_FRAME_ERROR 0x08 /* frame error */ 37 #define USTAT_BREAK 0x10 /* break */ 38 #define USTAT_TXB_EMPTY 0x40 /* tx buffer empty */ 39 #define USTAT_RCV_ERR 0x80 /* receive error */ 40 41 #define BPS 115200 /* serial baudrate */ 42 43 #define UART_RX_BUFFER_SIZE 64 44 #define UART_TX_BUFFER_SIZE 64 45 46 /*For sep6200's uart have several secondary function*/ 47 /*we use union to decribe it*/ 48 49 union dlbl_fifo 50 { 51 rt_uint32_t dlbl; 52 rt_uint32_t rxfifo; 53 rt_uint32_t txfifo; 54 }; 55 56 union dlbh_ier 57 { 58 rt_uint32_t dlbh; 59 rt_uint32_t ier; 60 }; 61 62 union iir_fcr 63 { 64 rt_uint32_t iir; 65 rt_uint32_t fcr; 66 }; 67 68 struct serial_int_rx 69 { 70 rt_uint8_t rx_buffer[UART_RX_BUFFER_SIZE]; 71 rt_uint32_t read_index, save_index; 72 }; 73 74 struct serial_int_tx 75 { 76 rt_uint8_t tx_buffer[UART_TX_BUFFER_SIZE]; 77 rt_uint32_t write_index, save_index; 78 }; 79 80 typedef struct uartport 81 { 82 union dlbl_fifo dlbl_fifo; 83 union dlbh_ier dlbh_ier; 84 union iir_fcr iir_fcr; 85 rt_uint32_t lcr; 86 rt_uint32_t mcr; 87 rt_uint32_t lsr; 88 rt_uint32_t msr; 89 }uartport; 90 91 struct serial_device 92 { 93 uartport* uart_device; 94 95 /* rx structure */ 96 struct serial_int_rx* int_rx; 97 98 /* tx structure */ 99 struct serial_int_tx* int_tx; 100 }; 101 102 rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag, struct serial_device *serial); 103 104 void rt_hw_serial_isr(rt_device_t device); 105 106 #endif 107