°ïÎÒ¿´¿´ÎÒµÄ2410ÍⲿÖжÏ5µÄ³ÌÐò
Ò»¡¢Çý¶¯³ÌÐò#ifdef MODULE
#include <linux/module.h>
#include <linux/version.h>
#else
#define MOD_INC_USE_COUNT
#define MOD_DEC_USE_COUNT
#endif
//#define __KERNEL__
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/fs.h>
//#include <linux/poll.h>
//#include <linux/slab.h>
#include <linux/ioport.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/irq.h> //including irq number
#include <S3C2410.h>
//#define INT_EXTINT1 1
//#define INT_EXTINT0 0
static void xint1_interrupt(int irq, void *id, struct pt_regs *regs);
static int hpi_open(struct inode *,struct file *);
static int hpi_release(struct inode *,struct file *);
static int hpi_read(struct file*,char*,int,loff_t*);
static int hpi_ioctl(struct inode* s_node,struct file* s_file,unsigned int cmd,unsigned long arg);
/*driver's file operations*/
struct file_operations xint3_fops=
{
read :(void(*)) hpi_read,
ioctl :(void(*)) hpi_ioctl,
open :(void(*)) hpi_open,
release:(void(*)) hpi_release,
};
static int inter3_num=0; //¼ÆËãxinter3·¢ÉúÖжϵĴÎÊý
static int major=245;//;
char hpi_name[]="hpidrv";
//xint3ÖжϷþÎñ³ÌÐò
static void xint3_interrupt(int irq, void *id, struct pt_regs *regs)
{
printk("<1>xint3 interrupt program entered %d times\n",inter0_num);
printk("<1>interrupt3 out!\n");
disable_irq(IRQ_EINT3);
INTPND|=0x08;//½«intpndµÚ3λÖÃ1ÒÔÇå³ýÖжÏ3±ê֧λ
inter3_num+=1;
// GPFDAT=~GPFDAT;
enable_irq(IRQ_EINT3);
return;
}
/*this function be called when driver is install*/
//Çý¶¯³ÌÐòµÄ×¢²áºÍ×¢ÏúÊÇÀûÓÃÖ÷É豸ºÅ
static int __init hpi_init_module(void)
{
int retv;
retv=register_chrdev(major,hpi_name,&xint3_fops);//É豸ע²á
if(retv<0)
{
printk("<1>Register Fail!\n");
return retv;
}
if(major==0) major=retv;
printk("<1> hpidrv device reginstered ok!\n");
return 0;
}
/*this function be called when driver is uninstall*/
static void __exit hpi_cleanup_module(void)
{
int retv;
retv=unregister_chrdev(major,hpi_name);
if(retv<0)
{
printk("<1>UnRegister Fail!\n");
return ;
}
printk("<1>HPIDRV:Good Bye!\n");
}
module_init(hpi_init_module);
module_exit(hpi_cleanup_module);
/*open and initialize it*/
//ÔÚopenº¯ÊýÖнøÐÐÇý¶¯³ÌÐòµÄ³õʼ»¯£¬ÖжÏÒ²Ôڴ˽øÐÐ
static int hpi_open(struct inode * hpi_node,struct file * hpi_file)
{
int retv;
char *short_head;
GPFCON=(GPFCON&0xffffff3f)+0x80;
EXTINT0=(EXTINT0&0xfffff1ff);
INTMOD=(INTMOD&0xfffffff7);
INTMSK=(INTMSK&0xfffffff7);
retv=request_irq(IRQ_EINT3,xint3_interrupt,SA_SHIRQ,"hpi_xinter3",NULL);//×¢²áÖжÏ
if(retv==-1)
{
printk("<1>Request IRQ%d error!\n",IRQ_EINT3);
return -EBUSY;
}
printk("<1>interrupt3 register ok! retv=%d\n",retv);
enable_irq(IRQ_EINT3);
printk("IRQ_EINT3=%d\n",IRQ_EINT3);
printk("GPFCON=%x\n",GPFCON);
printk("INTMSK=%x\n",INTMSK);
return 0;
}
//this will be called when the device is closed
static int hpi_release(struct inode * s_node,struct file * s_file)
{
INTMSK|=0x08;// ¹ØÖжÏint3
disable_irq(IRQ_EINT3);
printk("<1>interrupt3 is released ok!\n");
free_irq(IRQ_EINT3, NULL);//ÊÍ·ÅÖжÏ3
printk("<1>interrupt3 is released ok!\n");
return 0;
}
/*driver's read function*/
static int hpi_read(struct file*s_file,char *buf,int len,loff_t* loff)
{
return 0;
}
static int hpi_ioctl(struct inode* hpi_node,struct file* hpi_file,unsigned int cmd,unsigned long arg)
{
return 0;
}
/*end of extint3.c*/
Ó¦ÓóÌÐò
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ioctl.h>
int main(void)
{
int fd;
if((fd=open("/dev/hpidrv",O_RDWR))==-1) //´ò¿ªÉ豸
{
perror("open error");
exit(1);
}
printf("open hpidrv ok!\n");
sleep(10); &n bsp; &n bsp; //ϵͳ˯Ãß10ÃëÖÓ£¬¿ÉÓÃÕâ¶Îʱ¼ä°´¼ü²âÊÔÖжÏ
printf("sleep finished !\n");
//system("more interrupts");
close(fd);
printf("file closed!\n");
return 0;
}
²âÊÔ¹ý³Ì
# insmod extint3_drv.o
hpidrv device reginstered ok!
# mknod /dev/hpidrv c 245 0
# ./extint3_drv_user
interrupt3 register ok! retv=-22
IRQ_EINT3=3
GPFCON=55aa
INTMSK=29f79fd2
open hpidrv ok!
//ÔÚ´ËÆÚ¼äÎÒ¸øGPF3¼ÓµÍµçƽ£¬Ã»Óз´Ó¦,ºóÀ´¿´µ½request_irq£¨£©µÄ·µ»ØÖµ·ÇÁ㣬ÊÇ£22£¬È»ºóÎҾʹËÊÔÁ˺ܶàÆäËûµÄÇý¶¯£¬¿ÉÊÇÿ´Î¶¼ÎÞ·¨ÉêÇëµ½Öжϣ¬×ÔÈÏΪµ×²ã¼Ä´æÆ÷µÄÉèÖö¼ÕýÈ·£¬À§»ó°¡£¡£¡£¡
Çë¸ßÊÖÖ¸µãһϣ¡
sleep finished !
interrupt3 is released ok!
Trying to free IRQ3
Function entered at [<c0019150>] from [<c49b0328>]
r4 = C03840A0
Function entered at [<c49b02e8>] from [<c0048208>]
Function entered at [<c0048170>] from [<c0046d70>]
r7 = 00000006 r6 = C3FAF860 r5 = 00000000 r4 = C03840A0
Function entered at [<c0046cf0>] from [<c0046e08>]
r6 = 00008310 r5 = C03840A0 r4 = C3FAF860
Function entered at [<c0046d7c>] from [<c0018640>]
r5 = BFFFFE14 r4 = 00000648
interrupt3 is released ok!
file closed!
<!-- Message body ''"" --><!-- Message body ''"" --> ±êÌâÓеãÎÊÌ⣬ÊÇÍⲿÖжÏ3 ÇëÎÊÄãµÄÎÊÌâ½â¾öÁËÂð?
Çë¸æËßÎÒÈçºÎ½â¾ö
ÒòΪÎÒÒ²Óöµ½Í¬ÑùµÄÎÊÌâ.
лл!
Ò³:
[1]