测试用的中断驱动程序
来源:互联网 发布:软件开发 证 编辑:程序博客网 时间:2024/06/05 21:01
中断驱动程序
#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/platform_device.h>#include <linux/fb.h>#include <linux/backlight.h>#include <linux/err.h>#include <linux/pwm.h>#include <linux/slab.h>#include <linux/miscdevice.h>#include <linux/delay.h>#include <linux/gpio.h>#include <mach/gpio.h>#include <linux/timer.h> /*timer*/#include <asm/uaccess.h> /*jiffies*/#include <linux/delay.h>#include <linux/interrupt.h>#include <linux/workqueue.h>//#define IRQF_TRIGGER_HIGH 0x00000004#define gpio 94struct tasklet_struct task_t ; struct workqueue_struct *mywor ;//定义一个工作队列结构体struct work_struct wor;static void task_fuc(unsigned long data){ if(in_interrupt()){ printk("1111111111111111111111111111111111111\n"); }}//工作队列处理函数static void mywork_fuc(struct wor_struct *wor){ if(in_interrupt()){ printk("2222222222222222222222222222\n"); } msleep(2); printk("33333333333333333333333333333\n");}//中断处理函数static irqreturn_t irq_fuction(int irq, void *dev_id){ if(gpio_get_value(gpio) == 0) { tasklet_schedule(&task_t); //调度工作 schedule_work(&wor); if(in_interrupt()){ printk("44444444444444444444444444444\n"); } printk("555555555555555555555555555\n"); return IRQ_HANDLED ; } else{ return IRQ_NONE ; }}static int __init irq_test_init(void) { int err = 0 ; int irq_num1 ; int data_t = 100 ; gpio_direction_input(gpio); //设置为输入 //创建新队列和新工作者线程 mywor = create_singlethread_workqueue("my work"); //初始化DECLARE_WORK宏用于静态定义一个work_struct。而INIT_WORK宏用于动态初始化一个work_struct。延时任务使用INIT_DELAYED_WORK宏初始化。 INIT_WORK(&wor,mywork_fuc); //将任务提交到工作队列 queue_work(mywor,&wor); tasklet_init(&task_t,task_fuc,data_t); printk("irq_key init\n"); irq_num1 = gpio_to_irq(gpio); err = request_irq(irq_num1,irq_fuction,IRQF_TRIGGER_FALLING,"gpio94",(void *)"key1"); if(err != 0){ free_irq(irq_num1,(void *)"key1"); return -1 ; } return 0 ;}static void __exit irq_test_exit(void) { int irq_num1 ; printk("irq_key exit\n"); irq_num1 = gpio_to_irq(gpio); //销毁一条工作队列 destroy_workqueue(mywor); free_irq(irq_num1,(void *)"key1");}module_init(irq_test_init);module_exit(irq_test_exit);MODULE_LICENSE("GPL");
阅读全文
0 0
- 测试用的中断驱动程序
- 驱动程序的开发经验:中断与中断
- 基于中断的LED驱动程序
- LED驱动程序的测试
- 中断-----按键中断驱动程序
- Linux驱动开发⑤--在驱动程序中测试CPU中断
- 中断的BLCR测试
- 中断字符驱动程序
- Hi3515按键中断驱动程序
- 第一个中断驱动程序
- linux 驱动程序 中断机制
- ok6410按键中断驱动程序
- 按键中断驱动程序
- 中断和网络驱动程序
- 中断按键驱动程序
- Hi3515按键中断驱动程序
- Linux 驱动程序 中断管理
- linux2.6内核下的一个按键中断驱动程序示例
- 二手房交易陷阱坑人无数,避免就等于省钱几十万
- bug修复之takePicture failed
- 欢迎使用CSDN-markdown编辑器
- Android popuWindow 点击控件外不消失问题
- 快速上手MQ之activeMQ(1)--Demo
- 测试用的中断驱动程序
- Android 简单EventBus登录界面与传值(粘性事件)
- keypress, keydown, keyup的区别
- Java | 存储
- 两个日期类相减得到相差天数的小函数
- eclise 连接es5.0.2报错ERROR StatusLogger Could not reconfigure JMX java.lang.NoClassDefFoundError: org/a
- 政府牵头,中国要造强大AI芯片挑战英伟达地位
- 初步认识Tomcat优化
- [bzoj1061][Noi2008]志愿者招募