linux定时器0驱动进入定时器中断29次就重起!!而在这29次中其它的程序都死了,请楼主,和知道的朋友帮我看下什么原因!!下面是定时器的初始化代码》谢谢了!!
static int init_timer0(void)
{
// printk("timer init is on!");
unsigned long tcon=0;
unsigned long tcnt;
unsigned long tcfg1;
unsigned long tcfg0;
// unsigned long prescaler0;
// unsigned long timer_mux0;
struct clk *clk_p;
unsigned long pclk;
printk("timer init is on!");
tcfg1= __raw_readl(S3C2410_TCFG0);//读取定时器配置寄存器1的值
tcfg0=__raw_readl(S3C2410_TCFG0); //读取定时器配置寄存器0的值
//prescaler = 50
tcfg0&=~S3C2410_TCFG_PRESCALER0_MASK;
tcfg0 |=49; //设置tcfg0的值为49
//mux = 1/16
tcfg1 &=~S3C2410_TCFG1_MUX0_MASK;
tcfg1 |=S3C2410_TCFG1_MUX0_DIV16; //设置tcfg1的值为0x0011即:1/16
__raw_writel(tcfg1,S3C2410_TCFG1);// 将值tcfg1写入定时器配置寄存器1中
__raw_writel(tcfg0,S3C2410_TCFG0); //将值tcfg0写入定时器配置寄存器0中
clk_p=clk_get(NULL,"pclk");
pclk=clk_get_rate(clk_p); //从系统平台时钟队列中获取pclk的时钟频率,在include/linux/clk.h中定义
tcnt=(pclk/50/16); //计算定时器0的输出时钟频率(pclk/(prescaler0+1))/divider value
if(tcnt&(~0xffff))
{
printk("tcnt setting error\n");
// return;
}
printk("tcnt=%ld\n",tcnt);
__raw_writel(tcnt, S3C2410_TCNTB(0));//设置定时器0的计数缓存寄存器的值
__raw_writel(tcnt/10,S3C2410_TCMPB(0));//设置定时器0比较缓存寄存器的值
tcon &= __raw_readl(S3C2410_TCON); //读取定时器控制寄存器的值
tcon &=(~0x1f);
tcon |=0x1b;
__raw_writel(tcon, S3C2410_TCON);
tcon &=~2; //clear manual updata bit
tcon |=S3C2410_TCON_T0RELOAD; //设置定时器0为自动重装0x04
// tcon |=S3C2410_TCON_T0MANUALUPD; // 0x02设置定时器0 Updata TCNTB0&TCMPB0
// tcon |=S3C2410_TCON_T0START; //启动时器开始计数0x01
__raw_writel(tcon, S3C2410_TCON);
return 0;
}
int isp;
static irqreturn_t timer0_irq(void)
{ isp++;
printk("into the ISR=%d\n",isp);
return IRQ_RETVAL (IRQ_HANDLED);
}
static int analog_freq_input_open(struct inode *inode, struct file *file)
{
int err;
if(!down_trylock(&lock))
{
init_timer0();
printk("init timer0 finish\n");
err=request_irq(IRQ_TIMER0, (void*)&timer0_irq,IRQF_DISABLED,"S3C2410_timer0", NULL);
if(err==0)
printk("timeri init irq finish\n");
return 0;
}
else
return -EBUSY;
} |