#include <linux/interrupt.h> … //定义与绑定tasklet函数 void test_tasklet_action(unsigned long t); DECLARE_TASKLET(test_tasklet, test_tasklet_action, 0);
void test_tasklet_action(unsigned long t) { printk("tasklet is executing\n"); }
…
ssize_t globalvar_write(struct file *filp, const char *buf, size_t len, loff_t *off) { … if (copy_from_user(&global_var, buf, sizeof(int))) { return - EFAULT; }
//调度tasklet执行 tasklet_schedule(&test_tasklet); return sizeof(int); } |
由于中断与真实的硬件息息相关,脱离硬件而空谈中断是毫无意义的,我们还是来举一个简单的例子。这个例子来源于SAMSUNG S3C2410嵌入式系统实例,看看其中实时钟的驱动中与中断相关的部分:
static struct fasync_struct *rtc_async_queue; static int __init rtc_init(void) { misc_register(&rtc_dev); create_proc_read_entry("driver/rtc", 0, 0, rtc_read_proc, NULL);
#if RTC_IRQ if (rtc_has_irq == 0) goto no_irq2;
init_timer(&rtc_irq_timer); rtc_irq_timer.function = rtc_dropped_irq; spin_lock_irq(&rtc_lock); /* Initialize periodic freq. to CMOS reset default, which is 1024Hz */ CMOS_WRITE(((CMOS_READ(RTC_FREQ_SELECT) &0xF0) | 0x06), RTC_FREQ_SELECT); spin_unlock_irq(&rtc_lock); rtc_freq = 1024; no_irq2: #endif
printk(KERN_INFO "Real Time Clock Driver v" RTC_VERSION "\n"); return 0; }
static void __exit rtc_exit(void) { remove_proc_entry("driver/rtc", NULL); misc_deregister(&rtc_dev);
release_region(RTC_PORT(0), RTC_IO_EXTENT); if (rtc_has_irq) free_irq(RTC_IRQ, NULL); }
|
|