2021-07-22 11:25:32 +08:00
|
|
|
/*
|
2021-08-08 01:24:59 +08:00
|
|
|
* example_tasklet.c
|
2021-07-22 11:25:32 +08:00
|
|
|
*/
|
2021-07-22 06:35:24 +08:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/interrupt.h>
|
2021-07-22 06:58:13 +08:00
|
|
|
#include <linux/module.h>
|
2023-02-23 18:41:23 +08:00
|
|
|
#include <linux/printk.h>
|
2021-07-22 06:35:24 +08:00
|
|
|
|
2022-03-07 16:56:13 +08:00
|
|
|
/* Macro DECLARE_TASKLET_OLD exists for compatibility.
|
2021-08-23 21:30:43 +08:00
|
|
|
* See https://lwn.net/Articles/830964/
|
|
|
|
*/
|
|
|
|
#ifndef DECLARE_TASKLET_OLD
|
|
|
|
#define DECLARE_TASKLET_OLD(arg1, arg2) DECLARE_TASKLET(arg1, arg2, 0L)
|
|
|
|
#endif
|
|
|
|
|
2021-07-22 06:35:24 +08:00
|
|
|
static void tasklet_fn(unsigned long data)
|
|
|
|
{
|
|
|
|
pr_info("Example tasklet starts\n");
|
|
|
|
mdelay(5000);
|
|
|
|
pr_info("Example tasklet ends\n");
|
|
|
|
}
|
|
|
|
|
2021-09-04 17:53:29 +08:00
|
|
|
static DECLARE_TASKLET_OLD(mytask, tasklet_fn);
|
2021-07-22 06:35:24 +08:00
|
|
|
|
2023-07-05 09:44:21 +08:00
|
|
|
static int __init example_tasklet_init(void)
|
2021-07-22 06:35:24 +08:00
|
|
|
{
|
|
|
|
pr_info("tasklet example init\n");
|
|
|
|
tasklet_schedule(&mytask);
|
|
|
|
mdelay(200);
|
|
|
|
pr_info("Example tasklet init continues...\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-07-05 09:44:21 +08:00
|
|
|
static void __exit example_tasklet_exit(void)
|
2021-07-22 06:35:24 +08:00
|
|
|
{
|
|
|
|
pr_info("tasklet example exit\n");
|
|
|
|
tasklet_kill(&mytask);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(example_tasklet_init);
|
|
|
|
module_exit(example_tasklet_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Tasklet example");
|
|
|
|
MODULE_LICENSE("GPL");
|