Linux中断下半部——工作队列

1 参考书籍
《Linux设备驱动开发详解》 宋宝华 机械工业出版社
《嵌入式Linux驱动开发教程》 华清远见嵌入式学院 电子工业出版社
2 工作队列
下面的代码用于定义一个工作队列和一个底半部执行函数

struct work_struct my_wq; /*定义一个工作队列*/
void my_wq_func(struct work_struct *work); /*定义一个处理函数*/

通过INIT_WORK()可以初始化这个工作队列并将工作队列与处理函数绑定

INIT_WORK(&my_wq,my_wq_func);

用于调度工作队列执行的函数为schedule_work()

    schedule_work(&my_wq);

工作队列使用模版

/*混杂设备驱动模型*/
/*使用工作队列改写按键中断*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/poll.h>
#include <linux/irq.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <linux/interrupt.h>
#include <asm/uaccess.h>
#include <mach/hardware.h>
#include <linux/platform_device.h>
#include <linux/cdev.h>
#include <linux/miscdevice.h>


#define GPNCON 0x7F008830

#define DEVICE_NAME     "my_buttons"
#define MISC_DYNAMIC_MINOR 200 /*次设备号*/

struct work_struct my_wq; /*定义一个工作队列*/
void my_wq_func(struct work_struct *work);



/*中断处理,下半部函数*/
void my_wq_func(struct work_struct *work)
{
    ... 
}

/*中断处理顶半部函数*/
static irqreturn_t buttons_interrupt(int irq, void *dev_id)
{
    ...
    schedule_work(&my_wq);
    ...
    return IRQ_HANDLED; 
}


/*模块加载函数*/
static int __init dev_init()
{
...
...
/*申请中断*/        err=request_irq(IRQ_EINT(0),buttons_interrupt,IRQF_TRIGGER_FALLING,"mykey",0);

    /*初始化工作队列*/
    INIT_WORK(&my_wq,my_wq_func);
    ...
    return 0;
}

/*设备驱动模块卸载函数*/
static void __exit dev_exit(void)
{
    ...
    /*释放中断*/
    ...

}


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值