1 year ago
#311120
Justin Bob
how to use interrupt function in Ubuntu 20?
I am a beginner with linux interrupt function, I try to run the program below in Ubuntu 20, but there is always red wave line with the "#include <linux/interrupt.h>", I search the file and copy it into the directory. But after that, I get other warning messages with headers, such like "linux/bitops.h" , "linux/bits.h", or "asm/xxx.h". I try to copy them one by one into the include folder, but it seems like not the correct way to solve the problem.
I tried to correct the problem, with documents and videos, etc., but it is not easy to find something on this topic. Thanks for you help, appreciate.
#include <linux/interrupt.h>
#include <linux/irqreturn.h>
MODULE_LICENSE("GPL");
#define DPRINT(x) printk("<%s>" #x " = 0x%x\n", __func__, (int)x);
void beep(void)
{
volatile int i = 0;
printk("beep on\n");
for (i = 0; i<800000000; i++);
printk("beep off\n");
}
irqreturn_t myhandler(int irq, void * p)
{
int tmp;
//printk("irqhandler called!\n");
DPRINT(irq);
DPRINT(&tmp);
beep();
return IRQ_HANDLED;
}
static __init int interrupt_init(void)
{
int ri;
int btn_irq;
btn_irq = 160;
ri = request_irq(btn_irq, myhandler, IRQF_TRIGGER_FALLING, "btn k1 interrupt", NULL);
ri = request_irq(btn_irq+1, myhandler, IRQF_TRIGGER_FALLING, "btn k2 interrupt", NULL);
DPRINT(ri);
return 0;
}
static __exit void interrupt_exit(void)
{
DPRINT(interrupt_exit);
free_irq(160,NULL);
free_irq(161,NULL);
return;
}
module_init(interrupt_init);
module_exit(interrupt_exit);
new edited: Thanks a lot for help, sorry I still don't know what to do with it exactly, I need to download kernel source to support this function? or the source code is already on my computer but the target directory is not correct? Is there a document or a video that something like a tutorial? with "apt-cache search linux-source", I got a list below:
linux-source - Linux kernel source with Ubuntu patches
linux-source-5.4.0 - Linux kernel source for version 5.4.0 with Ubuntu patches
linux-gkeop-source-5.4.0 - Linux kernel source for version 5.4.0 with Ubuntu patches
linux-hwe-5.11-source-5.11.0 - Linux kernel source for version 5.11.0 with Ubuntu patches
linux-hwe-5.13-source-5.13.0 - Linux kernel source for version 5.13.0 with Ubuntu patches
linux-hwe-5.8-source-5.8.0 - Linux kernel source for version 5.8.0 with Ubuntu patches
linux-intel-5.13-source-5.13.0 - Linux kernel source for version 5.13.0 with Ubuntu patches
linux-source-4.10.0 - Linux kernel source for version 4.10.0 with Ubuntu patches
linux-source-4.11.0 - Linux kernel source for version 4.11.0 with Ubuntu patches
linux-source-4.13.0 - Linux kernel source for version 4.13.0 with Ubuntu patches
linux-source-4.15.0 - Linux kernel source for version 4.15.0 with Ubuntu patches
linux-source-4.4.0 - Linux kernel source for version 4.4.0 with Ubuntu patches
linux-source-4.8.0 - Linux kernel source for version 4.8.0 with Ubuntu patches
NEW EDITED: I tried as below, it was just the same like days ago when I copied files to a folder:
gcc irq.c -include /usr/src/linux-hwe-5.13-headers-5.13.0-35/include/linux/interrupt.h /usr/src/linux-hwe-5.13-headers-5.13.0-35/include/linux/irqreturn.h
In file included from <command-line>:32:
/usr/src/linux-hwe-5.13-headers-5.13.0-35/include/linux/interrupt.h:7:10: fatal error: linux/bitops.h: No such file or directory
7 | #include <linux/bitops.h>
| ^~~~~~~~~~~~~~~~
compilation terminated.
In file included from <command-line>:31:
/usr/include/stdc-predef.h:1: fatal error: can’t create precompiled header /usr/src/linux-hwe-5.13-headers-5.13.0-35/include/linux/irqreturn.h.gch: Permission denied
1 | /* Copyright (C) 1991-2020 Free Software Foundation, Inc.
|
compilation terminated.
c
linux
linux-kernel
interrupt
irq
0 Answers
Your Answer