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

📄 netdaqdev.c.bak

📁 at91rm9200双端口RAM驱动及测试程序
💻 BAK
字号:
#ifndef __KERNEL__#  define	__KERNEL__#endif#ifndef MODULE#  define	  MODULE#endif#include <linux/module.h>#include <linux/kernel.h>#include <linux/version.h>#include <linux/init.h>#include <linux/fs.h>#include <asm/uaccess.h>#include <linux/sched.h>#include <linux/types.h>#include <linux/fcntl.h>#include <linux/interrupt.h>#include <linux/ioport.h>#include <linux/slab.h>#include <linux/vmalloc.h>#include <linux/mm.h>#include <linux/string.h>#include <asm/io.h>#include <linux/errno.h>#include <linux/tqueue.h>#include <linux/wait.h>#include <asm/irq.h>#include <asm/delay.h>#include <asm/arch/hardware.h>#include <asm/fiq.h>#include <asm/arch/AT91RM9200_SYS.h>//#include <linux/slab.h>#include "NetDaqDev.h"void high_pb27(){	sys->PIOB_SODR = PB27;}void low_pb27(){	sys->PIOB_CODR = PB27;}static loff_t DaqDev_llseek(struct file *filp,loff_t offset,int orig){		cur_pos = base_map + offset;		return 0;}static ssize_t DaqDev_read(struct file *filp, char *buf, size_t count, loff_t *f_pos){	int i;		int cont = 0;		u16 * data_buf;		data_buf = (u16 *)kmalloc(9000,GFP_KERNEL);		for(i=0;i<count/2;i++){		*(data_buf + i) = readw(cur_pos + i);		printk("Kernel Data: %x\n",*(data_buf + i));		cont += 2;	}		copy_to_user(buf,data_buf,count);		kfree((void*)data_buf);		return cont;}static ssize_t DaqDev_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos){			int i;		int cont = 0;			u32 * data_buf;		u16 * temp_ptr = NULL;	u16 * temp_pos = NULL;		data_buf = (u32 *)kmalloc(9000,GFP_KERNEL);		copy_from_user(data_buf,buf,count);		if(count%4 == 0){		for(i=0;i<count;i+=4){			writel(*(data_buf + i/4),(cur_pos + i/2));			cont += 4;		}	}	else{		printk("i skip to here!\n");		for(i=0;i<(count-2);i+=4){			writel(*(data_buf + i/4),(cur_pos + i/2));			cont += 4;		}		printk("i: %d\n",i);		temp_ptr = (u16 *)data_buf;		printk("temp_ptr: %x\n",temp_ptr);		temp_ptr = temp_ptr + i/2 + 1;		printk("temp_ptr: %x\n",temp_ptr);		//temp_pos = temp_ptr + i + 1;		temp_pos = cur_pos + i/2 + 1;		printk("cur_pos: %x\n",cur_pos);		printk("temp_pos: %x\n",temp_pos);		*(temp_ptr) = readl(temp_pos);		printk("Data Read Back: %x\n",*temp_ptr);		printk("PIN Data: %x\n",*(((u32 *)data_buf) + i/4));		writel(*(((u32 *)data_buf) + i/4),(cur_pos + i/2));		cont += 2;	}				kfree((void*)data_buf);			return cont;}static int DaqDev_ioctl(struct inode *inode, struct file *filp, unsigned int ioctl_num, unsigned long ioctl_param){		return 0;}static int DaqDev_open(struct inode *inode, struct file *filp){	MOD_INC_USE_COUNT;	printk("Daq device opened.\n");	return 0;}static int DaqDev_release(struct inode *inode, struct file *filp){	MOD_DEC_USE_COUNT;	printk("Daq device closed.\n");	return 0;}static int __init DaqDev_init(void){	int ret;		sys->EBI_SMC2_CSR[2] = (AT91C_SMC2_TDF & 0x000) | AT91C_SMC2_BAT | AT91C_SMC2_DBW_16 | AT91C_SMC2_WSEN | 1;//(AT91C_SMC2_NWS & 0xff);	base_map = (u16 *)ioremap(NCS2, 0x1000*2);	ret = register_chrdev(MAJOR_NUM, DEV_NAME, &DaqDev_fops);	if (ret < 0)	{		printk("Error in register_chrdev with: %d!\n", ret);		return ret;	}	printk("Registered the daq device succeed with major number: %d!\n", MAJOR_NUM);	return 0;	//	sys->PIOB_PER 	|= PB27;//	sys->PIOB_OER 	|= PB27;//	sys->PIOB_PPUER |= PB27;//	sys->PIOB_MDER 	|= PB27;//	//	low_pb27();}static void __exit DaqDev_cleanup(void){	int ret;	iounmap((u16 *)base_map);	ret = unregister_chrdev(MAJOR_NUM, DEV_NAME);	if (ret < 0) 		printk("Error in unregister_chrdev: %d!\n", ret);	else 		printk("Leave daq device!\n");		}module_init(DaqDev_init);module_exit(DaqDev_cleanup);

⌨️ 快捷键说明

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