rt-thread/libcpu/unicore32/sep6200/serial.h

93 lines
2.0 KiB
C
Raw Normal View History

2013-07-17 13:37:31 +08:00
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
2013-07-17 13:37:31 +08:00
*
* SPDX-License-Identifier: Apache-2.0
2013-07-17 13:37:31 +08:00
*
* Change Logs:
* Date Author Notes
* 2006-03-13 Bernard first version
* 2009-04-20 yi.qiu modified according bernard's stm32 version
* 2010-10-6 wangmeng added sep4020 surpport
* 2013-7-15 Peng Fan Modified from sep4020
*/
#ifndef __SERIAL_H__
#define __SERIAL_H__
#include <sep6200.h>
2021-03-27 17:51:56 +08:00
#define USTAT_RCV_READY 0x01 /* receive data ready */
#define USTAT_OVERRUN 0x02 /* overrun */
#define USTAT_PARITY_ERR 0x04 /* parity error */
#define USTAT_FRAME_ERROR 0x08 /* frame error */
#define USTAT_BREAK 0x10 /* break */
#define USTAT_TXB_EMPTY 0x40 /* tx buffer empty */
#define USTAT_RCV_ERR 0x80 /* receive error */
2013-07-17 13:37:31 +08:00
2021-03-27 17:51:56 +08:00
#define BPS 115200 /* serial baudrate */
2013-07-17 13:37:31 +08:00
2021-03-27 17:51:56 +08:00
#define UART_RX_BUFFER_SIZE 64
#define UART_TX_BUFFER_SIZE 64
2013-07-17 13:37:31 +08:00
/*For sep6200's uart have several secondary function*/
/*we use union to decribe it*/
union dlbl_fifo
{
2021-03-27 17:51:56 +08:00
rt_uint32_t dlbl;
rt_uint32_t rxfifo;
rt_uint32_t txfifo;
2013-07-17 13:37:31 +08:00
};
union dlbh_ier
{
2021-03-27 17:51:56 +08:00
rt_uint32_t dlbh;
rt_uint32_t ier;
2013-07-17 13:37:31 +08:00
};
union iir_fcr
{
2021-03-27 17:51:56 +08:00
rt_uint32_t iir;
rt_uint32_t fcr;
2013-07-17 13:37:31 +08:00
};
struct serial_int_rx
{
2021-03-27 17:51:56 +08:00
rt_uint8_t rx_buffer[UART_RX_BUFFER_SIZE];
rt_uint32_t read_index, save_index;
2013-07-17 13:37:31 +08:00
};
struct serial_int_tx
{
2021-03-27 17:51:56 +08:00
rt_uint8_t tx_buffer[UART_TX_BUFFER_SIZE];
rt_uint32_t write_index, save_index;
2013-07-17 13:37:31 +08:00
};
typedef struct uartport
{
2021-03-27 17:51:56 +08:00
union dlbl_fifo dlbl_fifo;
union dlbh_ier dlbh_ier;
union iir_fcr iir_fcr;
rt_uint32_t lcr;
rt_uint32_t mcr;
rt_uint32_t lsr;
rt_uint32_t msr;
2013-07-17 13:37:31 +08:00
}uartport;
struct serial_device
{
2021-03-27 17:51:56 +08:00
uartport* uart_device;
2013-07-17 13:37:31 +08:00
2021-03-27 17:51:56 +08:00
/* rx structure */
struct serial_int_rx* int_rx;
2013-07-17 13:37:31 +08:00
2021-03-27 17:51:56 +08:00
/* tx structure */
struct serial_int_tx* int_tx;
2013-07-17 13:37:31 +08:00
};
rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag, struct serial_device *serial);
void rt_hw_serial_isr(rt_device_t device);
#endif