Chinaunix

标题: 关于一个中断驱动,请求帮忙,谢!!!! [打印本页]

作者: fineshang    时间: 2010-01-13 21:38
标题: 关于一个中断驱动,请求帮忙,谢!!!!
写了一个模拟SPI驱动,里面嵌入了中断,静态编译进内核2.4,发现中断没有响应,也不会调试。那位大侠指点一下,感激不尽!!!!比较急,谢谢!!!
static int major = 229;
static volatile int dataSPI = 0;

static int spi_drv_open(struct inode* inode, struct file *file)
{
        MOD_INC_USE_COUNT;
        return 0;
}

static int spi_drv_release(struct inode* inode, struct file *file)
{
        MOD_DEC_USE_COUNT;
        return 0;
}

static int spi_drv_ioctl(struct inode* inode, struct file *file, int DEVICE_SPI, unsigned int arg)
{
这个函数操作起来没有问题!
}

static int spi_drv_read(struct file *filp, int *buff, size_t count, loff_t *offp)
{
        buff = &(dataSPI);
        printk("dataSPI = %d\n", *buff);
        return 0;
}

static int spi_drv_interrupt(int irq, void *dev_id)
{
        volatile int temp = 0;
        int power = 1;
        int i = 7;
        printk("here is in interrupt\n");
        for (; i >= 0; i--){
                while ((GPEDAT & (1 << 13)) == 0){;};

                if ((GPEDAT & (1 << 13)) != 0){
                        printk("here is in loop\n");
                        temp = temp + power;
                        power = power * 2;
                        }

                while ((GPEDAT & (1 << 13)) != 0){;};
                }

        dataSPI = temp;
        enable_irq(IRQ_EINT2);
        return 0;
}

static struct file_operations spi_drv_fops =
{
        ioctl: spi_drv_ioctl,
        open: spi_drv_open,
        release: spi_drv_release,
        read: spi_drv_read,
};

static int __init spi_drv_init(void)

{
        int ret;
        unsigned int eint_irq;
        int ret_val;
        GPFCON = (GPFCON | 0x0030) & 0xFFEF;
        printk("SPI Driver.\n");
        ret = register_chrdev(major, NAME, &spi_drv_fops);
        if (ret<0) {
                printk("Unable to register character device!\n");
                return ret;
        }

        eint_irq = IRQ_EINT2;
        enable_irq(IRQ_EINT2);
        set_external_irq(eint_irq, EXT_RISING_EDGE, GPIO_PULLUP_DIS);

          ret_val = request_irq(eint_irq, spi_drv_interrupt, 0, "READ_SPI", 0);

        if (ret_val < 0) {

                return ret_val;

          }


        GPGCON = (GPGCON | 0x0000FC30) & 0xFFFF57DF;

        GPGUP |= 0x00E4;
        GPECON &= 0xF0FFFFFF;

        GPEUP |= 0x3000;
        printk("SPI Driver init completed!");

        return 0;
}



module_init(spi_drv_init);

module_exit(spi_drv_release); 可能风格不是很好,谢大家
作者: emmoblin    时间: 2010-01-14 10:25
你是如何触发的中断?
看看cat /proc/interupt
作者: fineshang    时间: 2010-01-14 15:06
cat /proc/interrupts 里面有
2:          0   READ_SPI  
中断2,上升沿触发,没有什么问题阿




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2