forked from manishkjain21/Kernel_Modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer3.c~
67 lines (51 loc) · 1.68 KB
/
timer3.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/timer.h>
#include <linux/delay.h>
MODULE_LICENSE("GPL");
static struct timer_list my_timer;
short count = 0;
bool timer_flag=0;
void my_timer_callback( unsigned long data )
{
printk( "my_timer_callback called (%ld).\n", jiffies );
count++;
if (count <= 3) mod_timer( &my_timer, jiffies + msecs_to_jiffies(1000) );
}
int init_module( void )
{
int ret;
unsigned int end_120, end_60, start_t;
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 );
start_t = jiffies;
ret = mod_timer( &my_timer, jiffies + msecs_to_jiffies(1000) ); //Function to modify the already running time
if (ret) printk("Error in mod_timer\n");
end_120 = start_t + 120*HZ;
end_60 = start_t + 60*HZ;
printk("This is the test for In between Time Modules\n");
while(jiffies <= end_60) // This code works but creates cpu stalling
{
printk("\nHello This is a Test");
mdelay_interruptible(1000);
}
printk("We can run functions in between program delays\n");
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 Timer3 module");