example_tasklet.c 762 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * example_tasklet.c
  3. */
  4. #include <linux/delay.h>
  5. #include <linux/interrupt.h>
  6. #include <linux/kernel.h>
  7. #include <linux/module.h>
  8. static void tasklet_fn(unsigned long data)
  9. {
  10. pr_info("Example tasklet starts\n");
  11. mdelay(5000);
  12. pr_info("Example tasklet ends\n");
  13. }
  14. DECLARE_TASKLET(mytask, tasklet_fn, 0L);
  15. static int example_tasklet_init(void)
  16. {
  17. pr_info("tasklet example init\n");
  18. tasklet_schedule(&mytask);
  19. mdelay(200);
  20. pr_info("Example tasklet init continues...\n");
  21. return 0;
  22. }
  23. static void example_tasklet_exit(void)
  24. {
  25. pr_info("tasklet example exit\n");
  26. tasklet_kill(&mytask);
  27. }
  28. module_init(example_tasklet_init);
  29. module_exit(example_tasklet_exit);
  30. MODULE_DESCRIPTION("Tasklet example");
  31. MODULE_LICENSE("GPL");