QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1153|回复: 2

可以帮我看看我的2410的外部终端3的程序吗?

[复制链接]
发表于 2005-11-24 21:37:12 | 显示全部楼层 |阅读模式
可以帮我看看我的2410的外部终端3的程序吗?外部终端0123我都试了,都出现同样的问题

一、驱动程序
#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,
        releasevoid(*)) 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*/
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);                          //系统睡眠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加低电平,没有反应

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!
 楼主| 发表于 2005-12-1 20:06:48 | 显示全部楼层
问题已解决
回复

使用道具 举报

发表于 2006-1-4 13:20:25 | 显示全部楼层
[quote:e8ff8a85d3="lht9"]问题已解决[/quote]

可以说一下是怎样解决的吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-2 22:36 , Processed in 0.042033 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表