主题 : 关于Tiny4412关于pwm_timer中断的问题 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 61237
精华: 0
发帖: 5
金钱: 25 两
威望: 5 点
综合积分: 10 分
注册时间: 2011-12-25
最后登录: 2015-12-20
楼主  发表于: 2015-09-11 21:33

 关于Tiny4412关于pwm_timer中断的问题

问题描述:pwm timer1 中断申请始终返回 -22,各位大侠帮忙分析一下,为什么始终申请不成功,已经卡很久了,还望版主费心了!以下附注为源代码:

ret1=request_irq(TIMER_IRQ_ID,&TimerIrqHandler,0,DEVICE_NAME,NULL);

#include <linux/module.h>
#include <linux/errno.h>  
#include <linux/miscdevice.h>
#include <linux/fcntl.h>

#include <linux/init.h>      
#include <linux/delay.h>  
#include <linux/proc_fs.h>
#include <linux/workqueue.h>

#include <asm/uaccess.h>
#include <asm/system.h>
#include <asm/io.h>    

/**********************************************/
#include <linux/module.h>    
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <mach/hardware.h>
#include <linux/cdev.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/poll.h>
#include <asm/uaccess.h>
#include <asm/ioctl.h>    

#include <asm/io.h>
#include <linux/irq.h>
#include <linux/platform_device.h>
          

//config GPIO
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/pci.h>
#include <linux/gpio.h>
#include <asm/atomic.h>
#include <asm/unistd.h>

      
#include <linux/sched.h>      


#define DEVICE_NAME "Tiny4412_Timer"


void __iomem *RegTimerBase;  
void __iomem *RegGpioBase;        
void __iomem *RegGICBase;

#define TIMER_IRQ_ID   70                

#define PWM_TIMER_BASE  0x139D0000
#define GPIO_BASE     0x11000000
#define GIC_CONFIG_BASE   0x10480000  

#define GPIO_GPM4CON             (*(volatile unsigned int*)(RegGpioBase + 0x02E0))  
#define GPIO_GPM4DAT                 (*(volatile unsigned int*)(RegGpioBase + 0x02E4))  
#define GPIO_GPM4PUD             (*(volatile unsigned int*)(RegGpioBase + 0x02E8))
#define GPIO_GPM4DRV             (*(volatile unsigned int*)(RegGpioBase + 0x02EC))
#define GPIO_GPM4CONPDN          (*(volatile unsigned int*)(RegGpioBase + 0x02F0))
#define GPIO_GPM4PUDPDN             (*(volatile unsigned int*)(RegGpioBase + 0x02F4))



#define  TIMER_TCFG0                (*(volatile unsigned int*)(RegTimerBase + 0x0000))  
#define  TIMER_TCFG1                  (*(volatile unsigned int*)(RegTimerBase + 0x0004))    
#define  TIMER_TCON                   (*(volatile unsigned int*)(RegTimerBase + 0x0008))  
#define TIMER_TCNTB1                 (*(volatile unsigned int*)(RegTimerBase + 0x0018))
#define TIMER_TCMPB1                 (*(volatile unsigned int*)(RegTimerBase + 0x001C))
#define TIMER_TCNTO1             (*(volatile unsigned int*)(RegTimerBase + 0x001C))  
#define TIMER_TINT_CSTAT        (*(volatile unsigned int*)(RegTimerBase + 0x0044))  


#define GIC_ICCICR_CPU0            (*(volatile unsigned int*)(RegGICBase + 0x0000))  
#define GIC_ICCPMR_CPU0          (*(volatile unsigned int*)(RegGICBase + 0x0004))  
#define GIC_ICDDCR                    (*(volatile unsigned int*)(RegGICBase + 0x10000))  

#define GIC_ICDIPR0_CPU0          (*(volatile unsigned int*)(RegGICBase + 0x10400))  
#define GIC_ICDIPTR0_CPU0        (*(volatile unsigned int*)(RegGICBase + 0x10800))  
    


unsigned int IRQ_cnt = 0x00;

static irqreturn_t TimerIrqHandler(void)
{                
    static unsigned int irq_cnt = 0x00;
        unsigned char timer_irq_cnt = 0x00;      

    TIMER_TINT_CSTAT = 1<<6;  

    IRQ_cnt++;
    if(IRQ_cnt % 2 == 0x00)
    {
        GPIO_GPM4DAT |= 0x01;
    }
    else    
    {
        GPIO_GPM4DAT &= 0xFE;      
    }


    return IRQ_HANDLED;            
}




static int TimerCtrlTest(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
    
    unsigned int __user *argp = (unsigned int __user*)arg;
            
    return 0;                    
}    


void GIC_Config(void)
{
    __asm__ volatile ("cpsie i\n");    

    GIC_ICCICR_CPU0 = 0x01;
    GIC_ICCPMR_CPU0 = 0xff;
    GIC_ICDDCR = 0x01;

    GIC_ICDIPR0_CPU0 = 0;

    GIC_ICDIPTR0_CPU0 = 0x01;
}



int TimerOpen(struct inode * inode, struct file * file)
{      
    int ret1;
    int i;
                                        
  
   GIC_Config();                                  
  
   TIMER_TCFG0 |=  0xff;
   TIMER_TCFG1 |= 0x04;  

   TIMER_TCNTB1 = 48828;
   TIMER_TCMPB1 = 24414;  

   TIMER_TCON  |= (1<<8) | (1<<9) | (1<<10);  

   TIMER_TINT_CSTAT |= 1<<1;  

     /*配置GPM4_0  为LED1*/  
   GPIO_GPM4CON |= 0x01;  

   ret1=request_irq(TIMER_IRQ_ID,&TimerIrqHandler,0,DEVICE_NAME,NULL);
   printk("IRQ requeset error %d \n",ret1);    

    mdelay(500);
    GPIO_GPM4DAT &= 0xFE;            
    mdelay(500);
    GPIO_GPM4DAT |= 0x01;
    mdelay(500);
    GPIO_GPM4DAT &= 0xFE;
    mdelay(500);
    GPIO_GPM4DAT |= 0x01;
    mdelay(500);
    GPIO_GPM4DAT &= 0xFE;    
    mdelay(500);
    GPIO_GPM4DAT |= 0x01;
    
   return 0 ;            
}          



int TimerClose(struct inode * inode, struct file * file)
{      
    int ret;
    
   return 0 ;  
}  





static struct file_operations Timer_stFops = {
    .owner      = THIS_MODULE,    
    .compat_ioctl =   TimerCtrlTest,      
    .open       = TimerOpen,      
    .release    = TimerClose,      
};  

static struct miscdevice Timer_stDev = {
   .minor   = MISC_DYNAMIC_MINOR,        
   .name    = DEVICE_NAME,
   .fops    =  &Timer_stFops,      
};            
    
            
/* module init and exit                                                     */

static int __init TimerInit(void)    
{        
    int     ret;                                
    
    ret = misc_register(&Timer_stDev);
    
    RegTimerBase = ioremap_nocache(PWM_TIMER_BASE, 0x10000);
    RegGpioBase =  ioremap_nocache(GPIO_BASE,0x10000);    
    RegGICBase = ioremap_nocache(GIC_CONFIG_BASE,0x20000);      
    
    if(ret != 0)                              
    {
        printk("register gp_timer failed with %#x!\n", ret);
        return -1;              
    }
        else    
     {
         printk("gp_timer init ok!\n");            
     }
    
    return 0;    
}  

static void __exit TimerExit(void)
{          
   misc_deregister(&Timer_stDev);    
}



module_init(TimerInit);
module_exit(TimerExit);


MODULE_DESCRIPTION("Tiny4412 module");
MODULE_AUTHOR("Tiny4412");
MODULE_LICENSE("GPL");










智能智能
级别: 新手上路
UID: 106960
精华: 0
发帖: 18
金钱: 95 两
威望: 19 点
综合积分: 36 分
注册时间: 2014-08-09
最后登录: 2016-12-28
1楼  发表于: 2016-01-13 16:11
定时器已经被占用了,你继续申请,那就不对了
级别: 新手上路
UID: 112456
精华: 0
发帖: 16
金钱: 80 两
威望: 16 点
综合积分: 32 分
注册时间: 2015-01-27
最后登录: 2016-04-28
2楼  发表于: 2016-01-20 18:28

 回 1楼(蒸汽铁罐头) 的帖子

我也遇到这样的问题,要怎么样才能共用中断或删掉原有的中断?