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

📄 uart2.c

📁 嵌入式下实验的新的驱动设计源代码
💻 C
字号:
#include <linux/config.h>#include <linux/utsname.h>#include <linux/kernel.h>#include <linux/major.h>#include <linux/string.h>#include <linux/fcntl.h>#include <linux/slab.h>#include <linux/timer.h>#include <linux/module.h>#include <linux/init.h>#include <linux/poll.h>#include <asm/irq.h>#include <asm/arch/io.h>#include <asm/arch/hardware.h>#include <asm/hardware/clps7111.h>#define barrier()               __asm__ __volatile__("": : :"memory")#define __raw_readl(p)          (*(unsigned long *)(p))#define __raw_writel(v,p)       (*(unsigned long *)(p) = (v))#define SYSFLGx2 SYSFLG2#define UARTDRx2 UARTDR2//#  define copy_to_user(t,f,n)         (memcpy_tofs(t,f,n), 0)#define UART2_MAJOR		62static DECLARE_WAIT_QUEUE_HEAD(Uart2Wait);void uart2_putc(char c);//int serial_getc(void);int uart2_readc(void);char data = 0x00;static void delay2(int n){	int i, j;	for(i = 0; i < 1000; i++)		for(j = 0; j < n; j++)			;}static int Uart2Close(struct inode * inode, struct file * file){	return 0;}static int Uart2Open(struct inode * inode, struct file * file){	return 0;}static int Uart2Read(struct file * file, char * buf, size_t count, loff_t *ppos){	char Value;	*(unsigned long *)0xfc000000 = 0x0;	Value = *(unsigned char *)0xfc000000;	printk("value : 0x%02x\n", Value);	delay2(2000);	copy_to_user(buf, &Value, sizeof Value);		return 1;}int ReadthenPut(void){	int i = 0;	while (1)	{	i = uart2_readc( );	if (1 == i)	{	uart2_putc( data );	i = 0;	}	       }      return 0;	}/* * select for mouse input */static unsigned int Uart2Select(	struct file *file, 	struct poll_table_struct *wait){    	//if (Ready)	//	return 1;	poll_wait(file, &Uart2Wait, wait);	return 0;}static int Uart2Ioctl(        struct inode *inode,        struct file *file,        unsigned int cmd,        unsigned long arg){//	char c;	        switch(cmd) {		case 0:	{		       // Uart2Read(inode,file, (char *)arg, 1);						        Uart2Read(file, (char *)arg, 1,0);							 return 1;		}				case 1:		{			uart2_putc('O');			break;		}		case 2:		{			//c = serial_getc();		        //uart2_putc(c);			ReadthenPut();			break;		}		                default:                return -EINVAL;        }      return 1;	}struct file_operations Uart2_fops = {	read:	Uart2Read,	poll:	Uart2Select, 	/* select */	open:	Uart2Open,	ioctl:	Uart2Ioctl,	release:	Uart2Close,};void  uart2_putc(char c){	int tmo = 0;	while((*(volatile unsigned long*)0xff001140 & (1 << 23))){		tmo++;		if (tmo == 5000)			break;	}	                *(volatile unsigned char *)0xff001480 = c;}/*int serial_getc(void){	while (SYSFLGx2 & SYSFLG_URXFE)		          ;	return *(volatile unsigned char *)0xff001480 & 0xff;}*/int uart2_readc(void){		int tmo = 0;				while(((*(volatile unsigned long *)0xff001140) & (1 << 22)))		{					tmo++;			if (tmo == 5000)			break;		}		if (tmo < 5000)		{		data = ( (*(volatile unsigned char *)0xff001480)  & 0xff);	      	return   1;	       }               return 0;}int Uart2_Init(void){        int     rc;	        printk("Uart2 Support \n");		*(volatile unsigned long *)0xff0014C0 = 0x00070001;        *(volatile unsigned long *)0xff001100 = (*(volatile unsigned long *)0xff001100) | 0x0100;	delay2(10000);        rc = register_chrdev(UART2_MAJOR, "uart2", &Uart2_fops);        if (rc < 0) {                printk(KERN_WARNING "uart2: can't get Major %d\n",                        UART2_MAJOR);                return rc;         }        	return 0;}void Uart2_Cleanup(void){	unregister_chrdev(UART2_MAJOR, "uart2");        return;}module_init(Uart2_Init);module_exit(Uart2_Cleanup);

⌨️ 快捷键说明

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