简体   繁体   English

在内核中添加中断服务程序

[英]Adding Interrupt service routine in kernel

I am trying to add a switch/GPIO interrupt. 我正在尝试添加一个开关/ GPIO中断。 I want to write it as part of kernel source tree. 我想将其编写为内核源代码树的一部分。 After building the kernel image and deploying to my custom board it has to appear in proc/interrupts. 构建内核映像并部署到我的自定义板后,它必须以proc / interrupts的形式出现。 I have already written the module and it is working if do insmod. 我已经写了模块,如果执行insmod,它就可以正常工作。 Instead of compiling separately i want it to be a part of my kernel tree. 与其单独编译,我不希望它成为内核树的一部分。 What are the steps to add the irq to kernel source. 将irq添加到内核源代码的步骤是什么。

Actually if you have written the module inside the kernel tree, it is pretty straightforward: 实际上,如果您已在内核树中编写了模块,则非常简单:

Lets say you put the source code in drivers directory, so the hierarchy looks as follows: drivers/hello Kconfig Makefile hello.c 可以说您将源代码放置在drivers目录中,因此层次结构如下所示:drivers / hello Kconfig Makefile hello.c

In drivers/Makefile you should add the following: 在驱动程序/ Makefile中,应添加以下内容:

obj-$(CONFIG-HELLO) += hello/

In drivers/Kconfig you should add the following: 在drivers / Kconfig中,应添加以下内容:

source "drivers/hello/Kconfig"

Sample code for drivers/hello/Kconfig: 驱动程序/ hello / Kconfig的示例代码:

config HELLO
tristate "Hello world module"
default n
help
   Enable Hello world module support

Sample code for drivers/hello/Makefile: 驱动程序/ hello / Makefile的示例代码:

obj-$(CONFIG_HELLO) += hello.o

Sample code for drivers/hello.c: drivers / hello.c的示例代码:

#include <linux/module.h>
#include <linux/moduleparam.h>

...
...

static int __init hello_init(void)
{
   ...
}

static void __exit hello_exit(void)
{
   ...
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_AUTHOR("Obi One Kenoby");
MODULE_DESCRIPTION("Hello Driver");
MODULE_LICENSE("GPL");
MODULE_VERSION("1.0");

Now you should be able to see the hello module in make menuconfig - select 'm' for module and '*' for built in. the module_init/module_exit macros works with both options. 现在,您应该可以在make menuconfig中看到hello模块-为模块选择“ m”,为内置选择“ *”。module_init / module_exit宏可同时使用这两个选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在QNX中断服务程序? - interrupt service routine in qnx? 中断服务程序会发生什么? - What happens in an interrupt service routine? PIC的中断服务程序“不允许使用不完整的类型” - “incomplete type is not allowed” for interrupt service routine for PIC ISR(中断服务程序)中的信号量同步 - semaphore like synchronization in ISR (Interrupt service routine) STM32 Discovery上的看门狗定时器的中断服务程序 - Interrupt service routine for watchdog timer on STM32 Discovery 由中断服务程序触发的对 volatile 变量的更改未反映在 main() 中 - Changes to volatile variable toggled by interrupt service routine not reflected in main() Windows操作系统中C的软件中断服务例程 - software Interrupt Service routine in C for windows operating system 如何在8051中结束外部中断服务程序(ISR) - How to end external Interrupt Service Routine (ISR) in 8051 中断服务例程不会跳回到ARM Cortex M0上的中断处理程序 - Interrupt Service Routine doesn't jump back to Interrupt Handler on an ARM Cortex M0 如何使用中断服务例程来检测此MSP430代码上的按钮事件? - How can I use an interrupt service routine to detect button events on this MSP430 code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM