代码如下:问题是程序运行起来后,程序就结束不了,而且别的程序也没反应了(如我再在用COMS采集视频,这个驱动运行后COMS也不动了),CTRL+C也结束不了,板子的触摸屏也不动了。现在就只有重启板子了,大家帮我看看是不是程序中什么地方干拢了系统的中断!
#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 <mach/regs-gpio.h>
#include <mach/regs-irq.h>
#include <plat/regs-timer.h>
#include <asm/io.h>
#include <linux/irq.h>
#include <linux/platform_device.h>
#define DEVICE_NAME "timer"
struct cdev *p_cdev; //声明一个指向字符设备结构体的指针
#define timer_irq IRQ_TIMER0
//#define DEVICE_MAJOR major
//#define DEVICE_MINOR 0 //次设备号一般为0
static irqreturn_t timer_interrupt(void)
{
printk("Timer0 interrupt occured!\n");
return IRQ_HANDLED;
}
static int timer_open(struct inode *inode,struct file *filp)
{
int ret;
unsigned long Ftclk,Fpclk=50000000; //s3c2440a的默认Fpclk为50MHz
outl(255,S3C2410_TCFG0); //设置预分频
outl(3,S3C2410_TCFG1); //设置分频和模式
Ftclk=Fpclk/(255+1)/16; //参考datasheet公式
outl(Ftclk,S3C2410_TCNTB(0)); //写入定时初值
outl(0,S3C2410_TCMPB(0)); //写入终点比较值
outl(S3C2410_TCON_T0MANUALUPD,S3C2410_TCON); //手动刷新一次,将数据装入TCNT和TCMP
outl(S3C2410_TCON_T0START|S3C2410_TCON_T0RELOAD,S3C2410_TCON); //设置自动装载初值,开始计数
ret=request_irq(timer_irq,&timer_interrupt,IRQF_DISABLED,DEVICE_NAME,NULL);
if(ret<0){
printk("Register IRQ_TIMER0 failed!\n");
return ret;
}
}
static int timer_close(struct inode *inode,struct file *filp)
{
free_irq(timer_irq,NULL);
return 0;
}
static struct file_operations timer_fops={
.owner=THIS_MODULE,
.open=timer_open,
.release=timer_close,
};
static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &timer_fops,
};
static int __init dev_init(void)
{
int ret;
ret = misc_register(&misc);
printk (DEVICE_NAME"\tinitialized\n");
return ret;
}
static void __exit dev_exit(void)
{
misc_deregister(&misc);
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("HJW");
module_init(dev_init);
module_exit(dev_exit);
测试程序如下:#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>
int main(void)
{
int fd;
fd=open("/dev/timer",0);
if(fd<0){
printf("Open /dev/timer failed!\n");
exit(1);
}
else printf("Open device successfully!\n");
while(1);
close(fd);
return 0;
}
代码如下:问题是程序运行起来后,程序就结束不了,而且别的程序也没反应了(如我再在用COMS采集视频,这个驱动运行后COMS也不动了),CTRL+C也结束不了,板子的触摸屏也不动了。现在就只有重启板子了,大家帮我看看是不是程序中什么地方干拢了系统的中断!