主题 : QtCreate2.7下编写硬件中断服务函数找不到中断相关头文件 复制链接 | 浏览器收藏 | 打印
级别: 侠客
UID: 90672
精华: 0
发帖: 71
金钱: 355 两
威望: 71 点
综合积分: 142 分
注册时间: 2013-04-22
最后登录: 2013-10-27
楼主  发表于: 2013-05-23 10:21

 QtCreate2.7下编写硬件中断服务函数找不到中断相关头文件

现在在micro2440开发板上开发,想在QtCreate下面使用PWM的硬件中断,我在main函数里面对PWM进行操作,编写了PWM定时器的中断服务函数,可是在编译的时候,提示用到的跟中断有关的头文件找不到,比如<linux/irq.h><asm/irq.h>等。我的编译环境是按照micro2440上面说的安装的,用到arm-linux-gcc4.4.3。哪位大侠帮我看看问题是在哪啊?
源码如下:
#include "smartdelaywidget.h"
#include <QApplication>
#include <QWSServer>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <asm/irq.h>
#include <fcntl.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
#include "sys/ioctl.h"

// PWM
#define PWM_IOCTL_SET_FREQ              1
#define PWM_IOCTL_STOP                  0

static int pwm_fd = -1;
static int pwm_irq_count = 0;

static irqreturn_t PWM_Interrupt(int irq, void *dev_id)      
{  
    pwm_irq_count++;
    if (pwm_irq_count % 5000 == 0)
        printk("500ms delay\n");
    
    if (pwm_irq_count % 10000 == 0)
        printk("1s delay\n");                                
                                                              
    return IRQ_RETVAL(IRQ_HANDLED);                          
}

static int open_pwm(void)
{
    pwm_fd = open("/dev/pwm", 0);
    if (pwm_fd < 0) {
        perror("open pwm device");
        exit(1);
    }
    
    int err;

    err = request_irq(IRQ_TIMER0, PWM_Interrupt, IRQ_TYPE_NONE, "pwm", NULL);

    if (err)
    {
        disable_irq(IRQ_TIMER0);
        free_irq(IRQ_TIMER0, NULL);

        return -EBUSY;
    }
}

static void close_pwm(void)
{
    if (pwm_fd >= 0) {
        ioctl(pwm_fd, PWM_IOCTL_STOP);
        close(pwm_fd);
        pwm_fd = -1;
    }
}

static void set_pwm_freq(int freq)
{
    // this IOCTL command is the key to set frequency
    int ret = ioctl(pwm_fd, PWM_IOCTL_SET_FREQ, freq);
    if(ret < 0) {
        perror("set the frequency of the buzzer");
        exit(1);
    }
}

static void stop_pwm(void)
{
    int ret = ioctl(pwm_fd, PWM_IOCTL_STOP);
    if(ret < 0) {
        perror("stop the buzzer");
        exit(1);
    }
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    SmartDelayWidget w;
    QWSServer::setCursorVisible(false); //hide the cursor
    w.setWindowFlags(Qt::FramelessWindowHint);  //hide the Window title
    w.show();

    open_pwm();
    set_pwm_freq(100);
  
    return a.exec();
}
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2013-05-23 12:25
想在QtCreate下面使用PWM的硬件中断

通常情况下,只有内核里的Linux设备驱动才能使用硬件中断。你代码里所用到的request_irq()这些接口只提供给硬件驱动程序。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 侠客
UID: 90672
精华: 0
发帖: 71
金钱: 355 两
威望: 71 点
综合积分: 142 分
注册时间: 2013-04-22
最后登录: 2013-10-27
2楼  发表于: 2013-05-25 22:32

 回 1楼(kasim) 的帖子

我知道,我现在想做的就是在Qt里面对Linux的设备进行操作,需要对硬件中断服务函数进行自定义,需要从上层传递值给底层的中断服务函数,所以我想把中断服务函数放到应用层来编写。这个应该是没有问题的吧?

或者有什么其他办法,从应用层传递参数到底层中断呢?
级别: 侠客
UID: 90672
精华: 0
发帖: 71
金钱: 355 两
威望: 71 点
综合积分: 142 分
注册时间: 2013-04-22
最后登录: 2013-10-27
3楼  发表于: 2013-05-28 11:03

 回 1楼(kasim) 的帖子

想请教一下,linux有没有回调函数之类的操作啊。

我以前是搞vxworks底层驱动的,一般来说如果上层应用需要在硬件中断中进行某个操作,我们会在底层的驱动中断服务函数里面提供一个回调函数,上层应用的操作就在回调函数里面执行。

现在刚开始接触linux,不知道linux里面是否可以执行类似的操作?
谢谢。
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
4楼  发表于: 2013-06-04 20:29

 回 3楼(zjun726) 的帖子

我想不出什么理由你需要这样做。应用程序不会比设备驱动程序更清楚应该如何响应中断。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 侠客
UID: 90672
精华: 0
发帖: 71
金钱: 355 两
威望: 71 点
综合积分: 142 分
注册时间: 2013-04-22
最后登录: 2013-10-27
5楼  发表于: 2013-06-05 10:55
因为应用层要对中断响应,中断服务函数是由应用层写。
比如:我现在这个项目,pwm是1ms进一次中断,应用层要求每隔N*1ms对某个IO口输出一个高电平,这个N由应用层来设置。

那这种情况下,应用层要写中断服务函数啊
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
6楼  发表于: 2013-06-05 13:47

 回 5楼(zjun726) 的帖子

这个是对设备驱动的配置,如果你愿意,可以让应用程序通过ioctl把1ms这个时间作为参数传递给驱动,在驱动程序里实现中断处理。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."