forked from manishkjain21/Kernel_Modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer2.c
50 lines (37 loc) · 1.25 KB
/
timer2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/timer.h>
MODULE_LICENSE("GPL");
static struct timer_list my_timer;
void my_timer_callback( unsigned long data )
{
printk( "my_timer_callback called (%ld).\n", jiffies );
}
int init_module( void )
{
int ret;
printk("Timer module installing\n");
// my_timer.function, my_timer.data
// my_timer_callback function called when timer expires
setup_timer( &my_timer, my_timer_callback, 0 );
//add_timer(&my_timer); //To activate the timer
printk( "Starting timer to fire in 2 s (%ld)\n", jiffies );
ret = mod_timer( &my_timer, jiffies + msecs_to_jiffies(2000) ); //Function to modify the already running time
if (ret) printk("Error in mod_timer\n");
printk("This is the test for In between Time Modules");
printk("We can run functions in between program delays");
return 0;
}
void cleanup_module( void )
{
int ret;
// delete the expired timer synchronously so as to avoid race conditions
ret = del_timer_sync( &my_timer );
if (ret) printk("The timer is still in use...\n");
printk("Timer module uninstalling\n");
return;
}
//module_init(init_module);
//module_exit(cleanup_module);
MODULE_AUTHOR("Manish Jain");
MODULE_DESCRIPTION("A Simple Timer2 module");