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

📄 uart2.old.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		61

static short Ready;
static DECLARE_WAIT_QUEUE_HEAD(Uart2Wait);
int uart2_putc(char c);
int serial_getc(void);



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;
}
/*
 * 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('U');
			break;
		}
		case 2:
		{
			c = serial_getc();
		        uart2_putc(c);
			break;
		}
		
                default:
                return -EINVAL;
        }
      return 1;	
}

struct file_operations Uart2_fops = {
	read:	Uart2Read,
	poll:	Uart2Select, 	/* select */
	open:	Uart2Open,
	ioctl:	Uart2Ioctl,
	release:	Uart2Close,
};

int uart2_putc(char c)
{
	int tmo = 0;
	while((*(volatile unsigned long*)0xff001140 & (1 << 23))){
		tmo++;
		if (tmo == 5000)
			break;
	}
	        
        *(volatile unsigned char *)0xff001480 = c;
	return 1; 
}

int serial_getc(void)
{
	while (SYSFLGx2 & SYSFLG_URXFE)
		          ;

	return *(volatile unsigned char *)0xff001480 & 0xff;
}


int Uart2_Init(void)
{
        int     rc;
	
        Ready = 0;

	*(volatile unsigned long *)0xff0014C0 = 0x00070001;
        *(volatile unsigned long *)0xff001100 = (*(volatile unsigned long *)0xff001100) | 0x0100;

	//printk("0xff001100 : 0x%08x\n", *(unsigned long *)0xff001100);
	//printk("0xff0014c0 : 0x%08x\n", *(unsigned long *)0xff0014c0);
	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; 
        }
        printk("uart2............Support, by soso, 2002.10\n");

	return 0;
}

void Uart2_Cleanup(void)
{
	unregister_chrdev(UART2_MAJOR, "ep7312-uart2");
        return;
}

module_init(Uart2_Init);
module_exit(Uart2_Cleanup);




⌨️ 快捷键说明

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