October 2017
Intermediate to advanced
586 pages
14h 8m
English
The standard timer example is as follows:
#include <linux/init.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/timer.h> static struct timer_list my_timer; void my_timer_callback(unsigned long data) { printk("%s called (%ld).\n", __FUNCTION__, jiffies); } static int __init my_init(void) { int retval; printk("Timer module loaded\n"); setup_timer(&my_timer, my_timer_callback, 0); printk("Setup timer to fire in 300ms (%ld)\n", jiffies); retval = mod_timer( &my_timer, jiffies + msecs_to_jiffies(300) ); if (retval) printk("Timer firing failed\n"); return 0; } static void my_exit(void) { int retval; retval = del_timer(&my_timer); /* Is timer still active (1) or no (0) */ if (retval) printk("The timer ...