serial.h 1.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#ifndef __RT_HW_SERIAL_H__
#define __RT_HW_SERIAL_H__

#include <rthw.h>
#include <rtthread.h>

#include "s3c24x0.h"

#define	USTAT_RCV_READY		0x01   	/* receive data ready */ 
#define	USTAT_TXB_EMPTY		0x02   	/* tx buffer empty */
#define BPS					115200	/* serial baudrate */

#define UART_RX_BUFFER_SIZE		64
#define UART_TX_BUFFER_SIZE		64

struct serial_int_rx
{
	rt_uint8_t  rx_buffer[UART_RX_BUFFER_SIZE];
	rt_uint32_t read_index, save_index;
};

struct serial_int_tx
{
	rt_uint8_t  tx_buffer[UART_TX_BUFFER_SIZE];
	rt_uint32_t write_index, save_index;
};

typedef struct uartport
{
30 31 32 33 34 35 36 37 38 39 40
	volatile rt_uint32_t ulcon;
	volatile rt_uint32_t ucon;
	volatile rt_uint32_t ufcon;
	volatile rt_uint32_t umcon;
	volatile rt_uint32_t ustat;
	volatile rt_uint32_t urxb;
	volatile rt_uint32_t ufstat;
	volatile rt_uint32_t umstat;
	volatile rt_uint32_t utxh;	
	volatile rt_uint32_t urxh;	
	volatile rt_uint32_t ubrd;
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
}uartport;

struct serial_device
{
	uartport* uart_device;
	
	/* rx structure */
	struct serial_int_rx* int_rx;

	/* tx structure */
	struct serial_int_tx* int_tx;
};

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