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

来源:互联网 发布:沧澜网络代练真的假的 编辑:程序博客网 时间:2024/06/05 11:04

       TP中断的处理,一般有种固定模式,采用work_struct就可以处理。

struct work_struct  tpd_work;static struct workqueue_struct *mtk_tpd_wq;     //线程workqueue_struct标识static void tpd_work_func(struct work_struct *work)    //是中断处理过程在TP初始化中,完成:mtk_tpd_wq = create_singlethread_workqueue("mtk_tpd_wq");INIT_WORK(&tpd_work, tpd_work_func);mt65xx_eint_registration(......, tpd_eint_handler, 1);   //注册中断处理handler点击TP,当中断触发时static void tpd_eint_handler(void){      queue_work(mtk_tpd_wq, &tpd_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);