⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s3c44b0_uart.h

📁 基于s3c44b0串口uart的驱动程序源代码
💻 H
字号:
/*======================================================
*   File Name: s3c44b0_uart.h  
*
*   Author:gong
*
*   Email:gongyanlei@msn.com
*
*   QQ & MSN:6213599, gongyanlei@msn.com

*   Modification History: 2008-05 gong, created.
*
*   Debug History: 2008-05
*
======================================================*/

#ifndef	 _S3C44B0_UART_H_
#define	 _S3C44B0_UART_H_

/*===================================================*/
/*                                         gereneral                                                           */
/*===================================================*/

/*=================device number=========================*/

#define 	S3C44B0_UART_NAME 		"s3c44b0_uart"	/*device name of s3c44b0_uart*/
#define 	S3C44B0_UART_MAJOR 	125			/*the major device number of s3c44b0_uart*/



/* =================for LoopQueue=========================*/

#define   MAX_ITEM_NUM		20			/*number of  items in LoopQueue*/
#define   MAX_MSG_LEN		100			/*byte number of each item in LoopQueue*/

/*=================buad rate related=======================*/

#define 	XTALL						12288000	/*Hz*/
#define 	DESIRED_BAUD_RATE		9600    //768000		/*bps*/

/*===================================================*/
/*                                         S3C44B0_UART                                                           */
/*===================================================*/

/*================s3c44b0_uart Registers========================*/

#define	S3C44B0_UART_BASE_ADDR			0x06000000	/*nGCS3 of ARM*/
#define	S3C44B0_UART_FIFO				*(volatile unsigned char *)(S3C44B0_UART_BASE_ADDR+0x00)
#define   S3C44B0_UART_IER				*(volatile unsigned char *)(S3C44B0_UART_BASE_ADDR+0x01)
#define   S3C44B0_UART_IIR				*(volatile unsigned char *)(S3C44B0_UART_BASE_ADDR+0x02)
#define   S3C44B0_UART_FCR				*(volatile unsigned char *)(S3C44B0_UART_BASE_ADDR+0x02)
#define   S3C44B0_UART_LCR				*(volatile unsigned char *)(S3C44B0_UART_BASE_ADDR+0x03)
#define   S3C44B0_UART_MCR				*(volatile unsigned char *)(S3C44B0_UART_BASE_ADDR+0x04)
#define   S3C44B0_UART_LSR				*(volatile unsigned char *)(S3C44B0_UART_BASE_ADDR+0x05)
#define   S3C44B0_UART_MSR				*(volatile unsigned char *)(S3C44B0_UART_BASE_ADDR+0x06)
#define   S3C44B0_UART_SR				*(volatile unsigned char *)(S3C44B0_UART_BASE_ADDR+0x07)
#define   S3C44B0_UART_DLSB				*(volatile unsigned char *)(S3C44B0_UART_BASE_ADDR+0x00)
#define   S3C44B0_UART_DMSB				*(volatile unsigned char *)(S3C44B0_UART_BASE_ADDR+0x01)

/*================FIFO control register======================*/

#define  	FCR_FIFO_ENALBE			0x01
#define   FCR_CLR_RX_FIFO			0x02
#define   FCR_CLR_TX_FIFO			0x03
#define   FCR_64_BYTE_MODE 			0x20
#define   FCR_1_TRIGGER_LEVEL_16 	0x00
#define   FCR_4_TRIGGER_LEVEL_16 	0x40
#define   FCR_8_TRIGGER_LEVEL_16 	0x80
#define   FCR_14_TRIGGER_LEVEL_16 	0xC0
#define   FCR_1_TRIGGER_LEVEL_64 	0x00
#define   FCR_16_TRIGGER_LEVEL_64 	0x40
#define   FCR_32_TRIGGER_LEVEL_64 	0x80
#define   FCR_56_TRIGGER_LEVEL_64 	0xC0

/*================interrupt enalbe register===================*/

#define 	IER_EN_RDA_INT			0x01
#define   IER_EN_THRE_INT			0x02
#define   IER_EN_RLS_INT				0x04
#define   IER_EN_MS_INT				0x08
#define 	IER_EN_SLEEP_MODE			0x10
#define 	IER_EN_LPWR_MODE			0x20
#define 	IER_DISEN_ALL				0x00

/*================interrupt identify register==================*/

#define 	IIR_RLS_INT					0x06	/*receiver line status*/
#define   IIR_RDA_INT				0x04	/*receiver data available*/
#define 	IIR_CTOI_INT				0x0C	/*char time out indicater*/
#define 	IIR_THRE_INT				0x02	/*transmitter holding register empty*/
#define	IIR_MS_INT					0x00	/*modem status*/

/*==================line control register===================*/

#define 	LCR_5_CHR_BIT				0x00
#define 	LCR_6_CHR_BIT				0x01
#define 	LCR_7_CHR_BIT				0x02
#define 	LCR_8_CHR_BIT				0x03
#define   LCR_1_STOP_BIT				0x00
#define   LCR_2_STOP_BIT				0x04
#define   LCR_EN_PARITY				0x08
#define 	LCR_EN_EVEN_PARITY		0x10
#define   LCR_EN_STICK_PARITY		0x20
#define   LCR_EN_BREAK_CONTRL		0x40
#define   LCR_DLAB					0x80

/*==================line status register===================*/

#define  	LSR_DATA_READY 			0x01	/*the data ready (DR) indicator for the receiver.*/
#define   LSR_OVER_RUN_ERROR		0x02	/*the overrun error (OE) indicator.*/
#define   LSR_PARITY_ERROR			0x04	/*the parity error (PE) indicator.*/
#define   LSR_FRAME_ERROR			0x08	/*the framing error (FE) indicator.*/
#define   LSR_BREAK_INT				0x10	/*the break interrupt (BI) indicator.*/
#define   LSR_THRE					0x20	/*the transmitter holding register empty indicator.*/
#define   LSR_TEMT					0x40	/*the transmitter empty (TEMT) indicator.*/
#define   LSR_FIFO_ERR				0x80	/*In the FIFO mode, LSR7 isset when there is at least */
											/*one parity, framing, or break error in the FIFO.*/

/*=================modem control register================*/

#define  	MCR_DTR_OUT				0x01
#define   MCR_RTS_OUT				0x02
#define   MCR_OUT1					0x04
#define   MCR_OUT2					0x08
#define   MCR_LOOP_BACK				0x10
#define   MCR_EN_AUTO_FLOW			0x22
#define   MCR_EN_AUTO_CTS			0x20
#define   MCR_EN_AUTO_RTS			0x00

/*===================================================*/
/*                               protocol bewteen host and arm                                       */
/*===================================================*/

/*=================TrCode======================*/

#define   TC_RESPONSE				0x10		/*response*/
#define   TC_CMD_REQUEST			0x00		/*command request*/
#define   TC_CMD_REPORT			0x02		/*command report*/
#define   TC_STS_REPORT				0x03		/*status report*/

#define   RESPONSE_LEN				4			/*the length of struct--response*/

/*==============operation code====================*/

#define  OP_CODE_INITIALIZE			0x00
#define  OP_CODE_RESET				0x01
#define  OP_CODE_STATUS_REQUEST	0x02

#define  OP_CODE_START_JOB			0x10
#define  OP_CODE_END_JOB			0x11
#define  OP_CODE_START_PAGE		0x12
#define  OP_CODE_END_PAGE			0x13
#define  OP_CODE_ABORT_JOB		0x14

/*==========error code in the struct of response ==========*/

#define 	ERR_CODE_NO				0x00		/*NO error(ACK)*/
#define 	ERR_CODE_OVERRUN		0x01		/*Overrun Error (NACK)*/
#define 	ERR_CODE_PARITY			0x02		/*Parity Error (NACK)*/
#define 	ERR_CODE_FRAME			0x03		/*Framing Error (NACK)*/
#define 	ERR_CODE_CHR_TIMEOUT	0x04		/*Character Timeout Error (NACK)*/
#define 	ERR_CODE_CHKSUM			0x05		/*CheckSum Error (NACK)*/
#define 	ERR_CODE_SN				0x06		/*Sequence Number Error (NACK)*/

/*=================report code===================*/

#define 	REPORT_CODE_COMPLETE			0x00
#define	REPORT_CODE_CMD_REJECTED		0x01
#define	REPORT_CODE_UNDEF_CMD			0x02
#define	REPORT_CODE_PARA_ERR			0x03
#define	REPORT_CODE_CMD_TIMEOUT		0x04
#define	REPORT_CODE_HADRDWARE_ERR		0x05
#define	REPORT_CODE_MEM_NOT_ENOUGH	0x06

/*=================header forma==================t*/

#define	HEADER_FORMAT_JOB_HEADER		0x00
#define	HEADER_FORMAT_JOB_FOOTER		0x01
#define	HEADER_FORMAT_PAGE_HEADER		0x02
#define	HEADER_FORMAT_PAGE_FOOTER		0x03

/*==================jet freq=====================*/

#define	JET_FREQ_5K			0x00
#define	JET_FREQ_10K			0x01
#define	JET_FREQ_15K			0x02
#define	JET_FREQ_20K			0x03

/*==================job type=====================*/

#define	JOB_TYPE_NORMAL		0x00
#define	JOB_TYPE_MAINTENANCE		0x01

/*=================gradation=====================*/

#define	GRADATION_1B			0x01
#define	GRADATION_2B			0x02
#define	GRADATION_4B			0x04
#define	GRADATION_8B			0x08

/*=================resolution=====================*/

#define	RESOLUTION_H_300		0x00
#define	RESOLUTION_H_360		0x01
#define	RESOLUTION_H_480		0x02
#define	RESOLUTION_H_600		0x03
#define	RESOLUTION_H_720		0x04
#define	RESOLUTION_H_1200		0x05
#define	RESOLUTION_H_1440		0x06
#define	RESOLUTION_H_2400		0x07

#define	RESOLUTION_L_300		0x00
#define	RESOLUTION_L_360		0x10
#define	RESOLUTION_L_480		0x20
#define	RESOLUTION_L_600		0x30
#define	RESOLUTION_L_720		0x40
#define	RESOLUTION_L_1200		0x50
#define	RESOLUTION_L_1440		0x60
#define	RESOLUTION_L_2400		0x70

/*===============image setting=====================*/

#define	COLOR_MODE_K			0x01
#define	COLOR_MODE_C			0x02
#define	COLOR_MODE_M			0x04
#define	COLOR_MODE_Y			0x08

#define   DUPLEX_MODE_SIMPLE		x00
#define	DUPLEX_MODE_DUPLEX		x10

/*=================color========================*/

#define	COLOR_K			0x01
#define	COLOR_C			0x02
#define	COLOR_M			0x04
#define	COLOR_Y			0x08

/*===============basic status=====================*/

#define	BASIC_STATUS_ERR				0x01
#define	BASIC_STATUS_WAIT				0x02
#define	BASIC_STATUS_OPERATOR_CALL	0x04
#define	BASIC_STATUS_MAINTENANCE	0x08
#define	BASIC_STATUS_PRINTER_BUSY	0x10
#define	BASIC_STATUS_JET_FREQ			0x20

/*============operator call status====================*/

#define	OPERATOR_CALL_NO_PAPER		0x01
#define	OPERATOR_CALL_PAPER_JAM		0x02
#define	OPERATOR_CALL_C_INK_EMPTY	0x04
#define	OPERATOR_CALL_M_INK_EMPTY	0x08
#define	OPERATOR_CALL_Y_INK_EMPTY	0x10
#define	OPERATOR_CALL_K_INK_EMPTY	0x20

/*==============wait status=======================*/

#define  	WAIT_STATUS_SLEEPING				0x01
#define  	WAIT_STATUS_WARMING				0x02
#define  	WAIT_STATUS_MEM_NOT_ENOUGH	0x04

/*==for the number of array--response, used in interrupt handler===*/

#define 	RSP_CHK_SUM				0			/*check sum*/
#define	RSP_TR_CODE				1			/*Trcode*/
#define   RSP_SN						2			/*Sequence Number*/
#define   RSP_ERR_CODE				3			/*error code*/


/*===================================================*/
/*                    typedefs                        */
/*===================================================*/
typedef struct loop_queue
	{
		unsigned char	  	data[MAX_ITEM_NUM][MAX_MSG_LEN];		/*the data queue*/

		unsigned char		front;				/*the position of first added item, which can */
											/*be used to read next item*/
		unsigned char		rear;				/*the position of newly added item*/

		unsigned char  		len[MAX_ITEM_NUM];	/*the length (bytes) of each item*/
	} LOOP_QUEUE;	/*the loop queue for rx interrupt handler*/
						/*to store the receiced data*/
						
/*===================================================*/
/*                functions                            */
/*===================================================*/
/*======================queue=========================*/

static void 	reset_queue(LOOP_QUEUE * pQueue );

static int 	query_queue_empty ( LOOP_QUEUE * pQueue ) ;
static int 	query_queue_full ( LOOP_QUEUE * pQueue  );

static void	in_queue ( LOOP_QUEUE * pQueue  ) ;
static void	out_queue ( LOOP_QUEUE * pQueue   ); 
//static unsigned char member_of_queue( LOOP_QUEUE * pQueue, unsigned char sn );
/*======================s3c44b0_uart=======================*/

static void      enable_s3c44b0_uart_thre_int(void);
static void 	disable_s3c44b0_uart_thre_int(void);

static void 	config_s3c44b0_uart(void);

/*====================file opterations====================*/

static ssize_t 	s3c44b0_uart_read(struct file *filp, char *buf, size_t count, loff_t *l);
static ssize_t 	s3c44b0_uart_write(struct file *filp, const char *buf, size_t count, loff_t *l);
static int 	s3c44b0_uart_open(struct inode *inode, struct file *filp);
static int 	s3c44b0_uart_release(struct inode *inode, struct file *filp);
static void 	s3c44b0_uart_handler(int irq, void *dev_idkp, struct pt_regs *regs);
int __init 	s3c44b0_uart_init(void);
void __exit 	s3c44b0_uart_cleanup(void);	
static struct file_operations s3c44b0_uart_fops =
{	read:	 s3c44b0_uart_read,	
	write:   s3c44b0_uart_write,
	open:	 s3c44b0_uart_open,
	release: s3c44b0_uart_release
}; 			/*  the file operations structure.*/

	

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -