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

📄 datasample_fifo_driver1.c

📁 打开s3c2410的外中断16
💻 C
字号:
#ifndef MODULE#define MODULE#endif#ifndef __KERNEL__#define __KERNEL__#endif#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/sched.h>#include <linux/spinlock.h>  //add 4.28#include <linux/interrupt.h>#include <linux/mm.h>#include <linux/wrapper.h>#include <linux/slab.h>#include <linux/proc_fs.h>#include <linux/ioport.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/arch/cpu_s3c2410.h>#include <linux/timer.h>#include <asm/irq.h>#include <asm/hardware.h>#include <asm/arch/irqs.h>#include <asm/semaphore.h> #include <linux/major.h>#include <linux/vmalloc.h>#include <linux/fs.h>#define EINT16_FIFO_MAJOR 253 #define DATA_SAMPLE_BASE  0x38000000;char data_256_from_INT16[256];static struct semaphore data_sem;devfs_handle_t devfs_eint16_FIFO;unsigned long  DATA_ADDR;static ssize_t EINT16_FIFO_read(struct inode *inode,char *buf, unsigned long count);static int  EINT16_FIFO_open(struct inode *inode,struct file *file);static int EINT16_FIFO_release(struct inode *inode,struct file *file);static void  datasample_clearirq(void);static void  datasample_initIO(void);static void eint16_irq(int irq, void *dev_id, struct pt_regs *regs);static struct file_operations fs2410_EINT16_FIFO_fops = {	read:		EINT16_FIFO_read,	open:		EINT16_FIFO_open,	release:	       EINT16_FIFO_release,};static void  datasample_clearirq(void){/*respond to EINT16*/	SRCPND &= (~0x00010000);  //bit 16	INTPND = INTPND;	EINTPEND &= (~0x00010000); //bit 16	}static void  datasample_initIO(void){	GPGCON=(GPGCON&(~(3<<16)))|(2<<16);		//GPG8 set EINT}//static ssize_t  GCS7_FIFO_read(struct inode *inode,char *buf, unsigned long count)static ssize_t EINT16_FIFO_read(struct inode *inode,char *buf, unsigned long count){	int cnt;	down_interruptible(&data_sem);	//printk("eint16 data read in datasample driver\n");	cnt=copy_to_user(buf,(void*)DATA_ADDR,256);	if(cnt<0)		return -EFAULT       return 1;}static int EINT16_FIFO_open(struct inode *inode,struct file *file){ 	//MOD_INC_USE_COUNT; //do nothing 	sema_init(&data_sem,0);	return 0;}static int EINT16_FIFO_release(struct inode *inode,struct file *file){       //MOD_DEC_USE_COUNT;	return 0;}static void eint16_irq(int irq, void *dev_id, struct pt_regs *regs){	//GPGCON=(GPGCON&(~(3<<16)))|(2<<16);		//GPG8 set EINT	int i;	GPGCON = (GPGCON & (~(3<<16))) | (0<<16);  //GPG8 set input        datasample_clearirq();	 if( (GPGDAT&(1<< 8)) == 0 ){		 up(&data_sem);		// for(i=0;i<256;i++)			//data_256_from_INT16[i]=(unsigned char*)(DATA_ADDR+i);	 }	datasample_initIO();	} /******4.27 do not use this way to identify the fifo*********************test if it is good in the usr function to sample the data*******int  init_Bit_GCS7(void){	if (check_mem_region(DATA_SAMPLE_BASE, DATA_SAMPLE_LEN)){            printk(MY_TEST_VERBOSE "Memory already in use\n");            return -EBUSY;       }       request_mem_region(DATA_SAMPLE_BASE, DATA_SAMPLE_LEN, "BANK7");       Data_Sample_base = ioremap(DATA_SAMPLE_BASE, DATA_SAMPLE_LEN);	   	printk(MY_TEST_VERBOSE  " initialized success \n");	printk("Data_Sample_base = 0x%08X\n",Data_Sample_base);	return 0;   }void  exit_Bit_GCS7(void){   	iounmap(Data_Sample_base);	release_mem_region(DATA_SAMPLE_BASE,DATA_SAMPLE_LEN);	printk(MY_TEST_VERBOSE "removed success");}*/int __init init_Datasample(void){             /****4.27 ****************          *******test if it is good in the usr function to sample the data*******          	  unsigned long DATA_SAMPLE_p;		  //4.14 alloc mem in kernel space and then map to usr space		           DATA_SAMPLE_p = __get_free_pages(GFP_KERNEL, 0);       //added 4.14                            SetPageReserved(virt_to_page(DATA_SAMPLE_p));  //added 4.14         printk("<1> DATA_SAMPLE_p = 0x%08x\n", DATA_SAMPLE_p);  //added 4.14         Data_for_Display_p=(unsigned char *)DATA_SAMPLE_p; //		              strcpy(DATA_SAMPLE_p, "Hello lily it is in the share mem!\n");  //added 4.14         //init_data_256_for_display();      	  if(!init_Bit_GCS7()==0){                 printk(MY_TEST_VERBOSE "Memory already in use\n");                 return -EBUSY;	  }	  	  */        //added 4.27                 	//  int result;	  	 int rc;		    //    result = register_chrdev(0,"Gcs7FifoDriver",&fs2410_GCS7_FIFO_fops);//	 if (result < 0) //	 {  //           printk(MY_GCS7_FIFO_VERBOSE  "Gcs7FifoDriver: can't get major number\n"); //            return result;  //       }      //   if (GCS7_FIFO_major == 0) //	     GCS7_FIFO_major = result; /* dynamic */        //    printk("GCS7 FIFO major is %d\n",GCS7_FIFO_major);			//   printk(MY_GCS7_FIFO_VERBOSE  "Gcs7FifoDriver: get major number successfully\n");       DATA_ADDR=phys_to_virt(0x38000);	 set_external_irq(IRQ_EINT16,EXT_RISING_EDGE, GPIO_PULLUP_EN);	rc=request_irq(IRQ_EINT16, eint16_irq, SA_INTERRUPT, "EINT16", NULL);	if (rc<0){		printk("<1>eint 16 irq not registered. Error: %d\n", rc);	}	devfs_eint16_FIFO= devfs_register(NULL,"EINT16_FIFO",DEVFS_FL_DEFAULT,EINT16_FIFO_MAJOR,                                                0, S_IFCHR |S_IRUSR |S_IWUSR |S_IRGRP |S_IWGRP,                                                              &fs2410_EINT16_FIFO_fops, NULL);	printk("<1>eint 16 irq registered success\n");         return 0;   }void __exit  exit_Datasample(void){      // s3c2410_Eint3_exit();      disable_irq(IRQ_EINT16);	free_irq(IRQ_EINT16, eint16_irq);	         /****4.27 ****************          *******test if it is good in the usr function to sample the data*******       exit_Bit_GCS7();	   	ClearPageReserved(virt_to_page(DATA_SAMPLE_p));  //added 4.14	free_pages(DATA_SAMPLE_p, 0);   //added 4.14         */      // 4.27      devfs_unregister(devfs_eint16_FIFO);}module_init(init_Datasample);module_exit(exit_Datasample);

⌨️ 快捷键说明

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