1 /* 2 * Copyright (c) 2006-2018, 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 */ 12 13 #ifndef __SERIAL_H__ 14 #define __SERIAL_H__ 15 16 #include <sep4020.h> 17 18 #define USTAT_RCV_READY 0x01 /* receive data ready */ 19 #define USTAT_TXB_EMPTY 0x40 /* tx buffer empty */ 20 #define BPS 115200 /* serial baudrate */ 21 22 #define UART_RX_BUFFER_SIZE 64 23 #define UART_TX_BUFFER_SIZE 64 24 25 /*For sep4020's uart have several secondary function*/ 26 /*we use union to decribe it*/ 27 28 union dlbl_fifo 29 { 30 rt_uint32_t dlbl; 31 rt_uint32_t rxfifo; 32 rt_uint32_t txfifo; 33 }; 34 35 union dlbh_ier 36 { 37 rt_uint32_t dlbh; 38 rt_uint32_t ier; 39 }; 40 41 union iir_fcr 42 { 43 rt_uint32_t iir; 44 rt_uint32_t fcr; 45 }; 46 47 struct serial_int_rx 48 { 49 rt_uint8_t rx_buffer[UART_RX_BUFFER_SIZE]; 50 rt_uint32_t read_index, save_index; 51 }; 52 53 struct serial_int_tx 54 { 55 rt_uint8_t tx_buffer[UART_TX_BUFFER_SIZE]; 56 rt_uint32_t write_index, save_index; 57 }; 58 59 typedef struct uartport 60 { 61 union dlbl_fifo dlbl_fifo; 62 union dlbh_ier dlbh_ier; 63 union iir_fcr iir_fcr; 64 rt_uint32_t lcr; 65 rt_uint32_t mcr; 66 rt_uint32_t lsr; 67 rt_uint32_t msr; 68 }uartport; 69 70 struct serial_device 71 { 72 uartport* uart_device; 73 74 /* rx structure */ 75 struct serial_int_rx* int_rx; 76 77 /* tx structure */ 78 struct serial_int_tx* int_tx; 79 }; 80 81 rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag, struct serial_device *serial); 82 83 void rt_hw_serial_isr(rt_device_t device); 84 85 86 #endif 87