mirror of
https://github.com/sysprog21/lkmpg.git
synced 2024-11-22 09:52:45 +08:00
befbaf085b
Close #207
45 lines
990 B
C
45 lines
990 B
C
/*
|
|
* example_tasklet.c
|
|
*/
|
|
#include <linux/delay.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/module.h>
|
|
#include <linux/printk.h>
|
|
|
|
/* Macro DECLARE_TASKLET_OLD exists for compatibility.
|
|
* See https://lwn.net/Articles/830964/
|
|
*/
|
|
#ifndef DECLARE_TASKLET_OLD
|
|
#define DECLARE_TASKLET_OLD(arg1, arg2) DECLARE_TASKLET(arg1, arg2, 0L)
|
|
#endif
|
|
|
|
static void tasklet_fn(unsigned long data)
|
|
{
|
|
pr_info("Example tasklet starts\n");
|
|
mdelay(5000);
|
|
pr_info("Example tasklet ends\n");
|
|
}
|
|
|
|
static DECLARE_TASKLET_OLD(mytask, tasklet_fn);
|
|
|
|
static int __init example_tasklet_init(void)
|
|
{
|
|
pr_info("tasklet example init\n");
|
|
tasklet_schedule(&mytask);
|
|
mdelay(200);
|
|
pr_info("Example tasklet init continues...\n");
|
|
return 0;
|
|
}
|
|
|
|
static void __exit example_tasklet_exit(void)
|
|
{
|
|
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");
|