LoginSignup
3
3

More than 5 years have passed since last update.

小さな割り込みハンドラメモ

Last updated at Posted at 2017-08-24

前提

  • ただprintkするだけ
  • ネットワークデバイス(ens33,12番)への割り込みを拾う

コード

irq.c
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>

MODULE_LICENSE("Dual BSD/GPL");
const int IRQ_NUM = 12;
void *irq_dev_id = (void *)&IRQ_NUM;

irqreturn_t kure_isr(int irq, void *dev_instance){
        printk("kure_isr: %s: irq, %d dev_instance, %p \n", __func__, irq, dev_instance);
        return IRQ_NUM;
}

static int kure_init(void){
        printk("kure_init\n");
        int ret;
        ret = request_irq(IRQ_NUM, kure_isr, IRQF_SHARED, "kure", irq_dev_id);
        if(ret){
                printk("error\n");
        }
        return 0;
}

static void kure_exit(void){
        printk("kure_exit\n");
        free_irq(IRQ_NUM, irq_dev_id);
}

module_init(kure_init);
module_exit(kure_exit);
Makefile
KERNEL_DIR = /lib/modules/$(shell uname -r)/build
BUILD_DIR := $(shell pwd)
VERBOSE   := 0
obj-m := irq.o
all:
        make -C $(KERNEL_DIR) SUBDIRS=$(BUILD_DIR) KBUILD_VERBOSE=$(VERBOSE) modules
clean:
        rm -rf  *.o *.ko *.mod.c *.symvers *.order .tmp_versions .helloworld.*

実行

# make
# insmod irq.ko
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3