使用workqueue

/*
*解决问题:使用过程中TP失灵;
*发现原因:TP失灵后读取TP firmware版本号不对;但是硬reset可以恢复正常;
*解决方法:在resume函数使用delayed_work检查TP firmware版本号,firmware版本号不对就reset;
*/
//(1)定义
+static int clk_tick_cnt = 200;
+static struct delayed_work tp_status_check_work;
+static struct workqueue_struct *tp_status_check_workqueue = NULL;
+static void tp_status_check_func(struct work_struct *);

//(2)初始化
+clk_tick_cnt = 1 * HZ;
+// HZ: clock ticks in 1 second generated by system
+INIT_DELAYED_WORK(&tp_status_check_work, tp_status_check_func);
+tp_status_check_workqueue = create_workqueue("tp_status_check");

//delayed_work的执行函数:
+static void tp_status_check_func(struct work_struct *work)
+{
+	unsigned char buf[64]={0};
+	// read protocol version
+	if(ilitek_i2c_read_info(i2c.client, ILITEK_TP_CMD_GET_PROTOCOL_VERSION, buf, 2) < 0){
+		return;
+	}
+	i2c.protocol_ver = (((int)buf[0]) << 8) + buf[1];
+	if((i2c.protocol_ver & 0xFF00) != 0x200){
+				ilitek_reset(i2c.reset_gpio);
+				printk("\n%s@%d: error reset_gpio\n",__func__,__LINE__);
+				queue_delayed_work(tp_status_check_workqueue, &tp_status_check_work, clk_tick_cnt);
+			}
+		return;
+}

//(3)执行工作队列
+queue_delayed_work(tp_status_check_workqueue, &tp_status_check_work, clk_tick_cnt);

//(4)销毁工作队列
+	destroy_workqueue(tp_status_check_workqueue);

猜你喜欢

转载自blog.csdn.net/houyizi337825770/article/details/86076590
今日推荐