tiny6410_驱动程序_定时器_简单使用

来源:互联网 发布:ubuntu软件安装在哪里 编辑:程序博客网 时间:2024/05/18 17:58

drv_timer.c

/* * driver timer test */ #include <linux/init.h>#include <linux/kernel.h>#include <linux/module.h>#include <linux/timer.h>static struct timer_list my_timer;static void timer_func(unsigned long data){static int count = 0;printk("<0> args_val=%ld times=%d\n", data, ++count);if(count >= 3){/* delete timer */del_timer(&my_timer);return;}my_timer.expires  = jiffies + HZ*3;my_timer.function = timer_func;my_timer.data     = count;/* add and start timer*/add_timer(&my_timer);}static int drv_timer_init(void){/* init timer */init_timer(&my_timer);my_timer.expires  = jiffies + HZ*3;my_timer.function = timer_func;my_timer.data     = 5;/* add and start timer*/add_timer(&my_timer);printk("<0> Hello timer test!\n");return 0;}static void drv_timer_exit(void){printk("<0> Goodbye timer test!\n");}module_init(drv_timer_init);module_exit(drv_timer_exit);MODULE_LICENSE("GPL");MODULE_DESCRIPTION("timer test");

 

Makefile

KERNELDIR = /sdb/kernel/linux-2.6.38-tiny6410/linux-2.6.38/PWD := $(shell pwd)modules:$(MAKE) -C $(KERNELDIR) M=$(PWD) modulesclean:rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions.PHONY: modules  cleanobj-m := drv_timer.o


 

结果

原创粉丝点击