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);