Linux内核的中断处理:work_struct && 定时处理delayed_work

       TP中断的处理,一般有种固定模式,两种实现方法,采用work_struct和work_struct workqueue_struct混合都可以处理。

(1)work_struct

定义报点函数

static struct work_struct    msg21xx_wq;

static int touch_event_handler(void *unused)
probe中初始化

INIT_WORK( &msg21xx_wq, touch_event_handler );

注册TP中断的handler

mt65xx_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_DEBOUNCE_EN, CUST_EINT_TOUCH_PANEL_POLARITY, tpd_eint_interrupt_handler, 1); 
中断handler中通过调用到msg21xx_wq来调用报点函数
 static void tpd_eint_interrupt_handler(void)
 {
	 mt65xx_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
	 schedule_work( &msg21xx_wq );
 }

注销work_struct用

cancel_work_sync(&msg21xx_wq)
(2)work_struct workqueue_struct跟上面类似,只不过调用work_struct的方式换了一种而已

定义报点函数

struct work_struct  work;
static void tpd_work_func(struct work_struct *work)

static struct workqueue_struct *mtk_tpd_wq;
probe中初始化

mtk_tpd_wq = create_singlethread_workqueue("mtk_tpd_wq");

INIT_WORK(&work, tpd_work_func);
注册TP中断的handler

mt65xx_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_DEBOUNCE_EN, CUST_EINT_TOUCH_PANEL_POLARITY, tpd_eint_handler, 1); 
中断handler中通过调用到work_struct work结合queue_struct来调用报点函数

static void tpd_eint_handler(void)
{
	queue_work(mtk_tpd_wq, &work);
}

在模块exit函数中,注销workqueue_struct

destroy_workqueue(mtk_tpd_wq);
===================定时处理delayed_work===================

        delayed_work是在work_struct的基础上加了个timer_list,用于做时间上调度处理。
typedef struct {
	.....
	struct delayed_work x_work;	//for PPR, HRV
	.....
} ofn_data_t;
static  ofn_data_t ofndata;
初始化:
INIT_DELAYED_WORK(&ofndata.x_work, ofn_x_work_func);
首次调用的地方,20ms后执行:
schedule_delayed_work(&ofndata.x_work, msecs_to_jiffies(20));

首次调用之后,该函数开始循环间隔40ms时间执行,即自己调用自己:

static void ofn_x_work_func(struct work_struct *work)
{	
		ofn_ppg();
		schedule_delayed_work(&ofndata.x_work, msecs_to_jiffies(40));
}
需要终止执行时

cancel_delayed_work_sync(&ofndata.x_work);

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值