example_tasklet.c 976 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * example_tasklet.c
  3. */
  4. #include <linux/delay.h>
  5. #include <linux/interrupt.h>
  6. #include <linux/module.h>
  7. #include <linux/printk.h>
  8. /* Macro DECLARE_TASKLET_OLD exists for compatibility.
  9. * See https://lwn.net/Articles/830964/
  10. */
  11. #ifndef DECLARE_TASKLET_OLD
  12. #define DECLARE_TASKLET_OLD(arg1, arg2) DECLARE_TASKLET(arg1, arg2, 0L)
  13. #endif
  14. static void tasklet_fn(unsigned long data)
  15. {
  16. pr_info("Example tasklet starts\n");
  17. mdelay(5000);
  18. pr_info("Example tasklet ends\n");
  19. }
  20. static DECLARE_TASKLET_OLD(mytask, tasklet_fn);
  21. static int example_tasklet_init(void)
  22. {
  23. pr_info("tasklet example init\n");
  24. tasklet_schedule(&mytask);
  25. mdelay(200);
  26. pr_info("Example tasklet init continues...\n");
  27. return 0;
  28. }
  29. static void example_tasklet_exit(void)
  30. {
  31. pr_info("tasklet example exit\n");
  32. tasklet_kill(&mytask);
  33. }
  34. module_init(example_tasklet_init);
  35. module_exit(example_tasklet_exit);
  36. MODULE_DESCRIPTION("Tasklet example");
  37. MODULE_LICENSE("GPL");