现在要在Qt的main函数中对PWM的中断进行处理,源码如下:
#include "smartdelaywidget.h"
#include <QApplication>
#include <QWSServer>
#include <linux/interrupt.h>
#include <linux/irq.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_int_count = 0;
static irqreturn_t PWM_Interrupt(int irq, void *dev_id)       
{   
    pwm_int_count++;
    if (pwm_int_count % 5000 == 0)                                                          
        printk("500ms delay\n");
    
    if (pwm_int_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();
}
编译时,提示<linux/interrupt.h><linux/irq.h><asm/irq.h> no such file or directory,这些头文件都是linux系统自带的啊,怎么会提示找不到呢?