1 声明一个delayed_work
DECLARE_DELAYED_WORK(work,work_fun);
2 schedule delayed_work,需要指明延迟时间.
schedule_delayed_work(&work,1);
以下是代码演示:
#include <linux/uaccess.h>
#include <linux/fs.h>
#include <linux/stat.h>
#include <linux/cdev.h>
#include <linux/io.h>
#include <linux/gpio.h>
#include <linux/gpio/machine.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/slab.h>
#include <linux/irq.h>
#include <linux/mutex.h>
#include <linux/interrupt.h>
#include <linux/bug.h> /* For BUG_ON. */
#include <linux/cpu.h>
#include <linux/init.h> /* Needed for the macros */
#include <linux/kernel.h> /* Needed for pr_info() */
#include <linux/module.h> /* Needed by all modules */
#include <linux/delay.h>
#include <linux/smp.h>
#include <linux/kernel_stat.h>
#include <linux/sched.h>
#include <linux/percpu-defs.h>
#include <linux/wait.h>
#include <linux/gpio/driver.h>
#include <linux/atomic.h>
#include <linux/platform_device.h>
#include <linux/poll.h>
#include <linux/kfifo.h>
#include <linux/workqueue.h>
void work_fun(struct work_struct *unused)
{
pr_info("work queue called\n");
}
DECLARE_DELAYED_WORK(work,work_fun);
static irqreturn_t key_handler(int irq, void *dev_id) {
pr_info("key_handler \n");
schedule_delayed_work(&work,1);
return IRQ_HANDLED;
}
int myprobe(struct platform_device *pdev) {
int ret;
int irq_pin;
int irq_flags;
int irq;
struct device_node *np = pdev->dev.of_node;
pr_err("jiffies %ld\n",jiffies);
pr_err("HZ %d\n",HZ);
irq_pin = of_get_named_gpio_flags(np, "touch-gpio", 0,
(enum of_gpio_flags*) (&irq_flags));
if (irq_pin < 0) {
pr_err("of_get_named_gpio_flags failed \n");
return irq_pin;
}
irq = gpio_to_irq(irq_pin);
pr_info("irq_flags:%d\n", irq_flags);
ret = devm_request_irq(&pdev->dev, irq, key_handler, irq_flags,
"my_key_driver",
NULL);
if (ret < 0) {
pr_err("request_irq failed \n");
return ret;
}
return 0;
}
int myremove(struct platform_device *pdev) {
pr_info("myplatformdriver myremove \n");
return 0;
}
struct of_device_id my_of_match_table =
{ .compatible = "my_platform_device_003", };
struct platform_driver my_platform_driver = { .driver =
{ .of_match_table = &my_of_match_table, .name = "my-platform-driver",
.owner = THIS_MODULE, }, .probe = myprobe, .remove = myremove, };
module_platform_driver(my_platform_driver);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Andy");
MODULE_DESCRIPTION("andy one-key driver");
MODULE_ALIAS("one-key");