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

📄 dac0832.c

📁 Linux下基于EP7312
💻 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/malloc.h>#include <linux/timer.h>#include <linux/init.h>#include <asm/irq.h>#include <asm/io.h>#  define copy_to_user(t,f,n)         (memcpy_tofs(t,f,n), 0)#define Dac0832Major 	57 static short Ready;static void CloseDac0832(struct inode * inode, struct file * file){	//close interrupt	printk("dac0832 is closed\n");	return ;}static int OpenDac0832(struct inode * inode, struct file * file){	Ready = 0;	printk("dac0832 is open\n");		*(volatile unsigned char *)0xff000000 = 0x00;		return 0;}/* * read mouse data.  Currently never blocks. */static int ReadDac0832(struct file * file, char * buf, size_t count, loff_t *ppos){	return 0;}static int Dac0832Ioctl(	struct inode *inode, 	struct file * file, 	unsigned int cmd, 	unsigned long arg){        int i;	//	printk("enter ioctl.........\n");        switch(cmd) {		case 0:			{			unsigned char ch = *(unsigned char *)arg;			long val = 0x00000000;					val |= ch;			val |= ch << 8;			val |= ch << 16;			val |= ch << 24;									*(volatile unsigned long *)0xf6000000 = val; 			*(volatile unsigned long *)0xf6000000 = val; 			for(i = 0; i < 10000; i++);			return 1;						}                case 1:                        i = ReadDac0832(file, (char *)arg, 1, 0);                        return i;                default:                        return -EINVAL;        }        return 1;}static struct file_operations Dac0832fops = {	read:	ReadDac0832,     /* read */	ioctl:	Dac0832Ioctl,           /* ioctl */	open:	OpenDac0832,    /* just a selector for the real open */	release:	CloseDac0832,           /* release */};int dac0832_init(void){        int     rc;        rc = register_chrdev(Dac0832Major, "dac0832", &Dac0832fops);        if (rc < 0) {		printk(KERN_WARNING "Dac0832: can't get Major %d\n", Dac0832Major);		return rc;            }		*(unsigned long *)0xff000180 |= 0x00120000;		*(unsigned long *)0xf6000000 = 0x80808080;	*(unsigned long *)0xf6000000 = 0x80808080;		printk("dac0832------------support.\n");	return 0;}void dac0832_cleanup(void){		 unregister_chrdev(Dac0832Major, "dac0832");  	 return;}module_init(dac0832_init);module_exit(dac0832_cleanup);

⌨️ 快捷键说明

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