Created
July 8, 2013 07:37
-
-
Save maggocnx/5946907 to your computer and use it in GitHub Desktop.
Timer example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> | |
#include <linux/kernel.h> | |
#include <linux/hrtimer.h> | |
#include <linux/ktime.h> | |
unsigned long timer_interval_ns = 1e6; | |
static struct hrtimer hr_timer; | |
enum hrtimer_restart timer_callback( struct hrtimer *timer_for_restart ) | |
{ | |
ktime_t currtime , interval; | |
currtime = ktime_get(); | |
interval = ktime_set(0,timer_interval_ns); | |
hrtimer_forward(timer_for_restart, currtime , interval); | |
// set_pin_value(PIO_G,9,(cnt++ & 1)); //Toggle LED | |
return HRTIMER_RESTART; | |
} | |
static int __init timer_init(void) { | |
ktime = ktime_set( 0, timer_interval_ns ); | |
hrtimer_init( &hr_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL ); | |
hr_timer.function = &timer_callback; | |
hrtimer_start( &hr_timer, ktime, HRTIMER_MODE_REL ); | |
return 0; | |
} | |
static void __exit timer_exit(void) { | |
int ret; | |
ret = hrtimer_cancel( &hr_timer ); | |
if (ret) printk("The timer was still in use...\n"); | |
printk("HR Timer module uninstalling\n"); | |
} | |
module_init(timer_init); | |
module_exit(timer_exit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add "ktime_t ktime ;" inside "timer_init" function