mirror of
https://github.com/54shady/kernel_drivers_examples.git
synced 2025-08-15 02:39:36 +00:00
timer example
This commit is contained in:
33
debug/timer/Makefile
Normal file
33
debug/timer/Makefile
Normal file
@ -0,0 +1,33 @@
|
||||
# Makefile
|
||||
# Comment/uncomment the following line to disable/enable debugging
|
||||
# DEBUG = y
|
||||
|
||||
# Usage
|
||||
# make CC=<your_compiler_path> KERNELDIR=<your_kernel_dir>
|
||||
#
|
||||
# make CC=/home/zeroway/3288/src/3288_4.4/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-gcc KERNELDIR=/home/zeroway/3288/src/3288_4.4/kernel
|
||||
|
||||
# Add your debugging flag (or not) to CFLAGS
|
||||
ifeq ($(DEBUG),y)
|
||||
DEBFLAGS = -O -g -DSCULL_DEBUG # "-O" is needed to expand inlines
|
||||
else
|
||||
DEBFLAGS = -O2
|
||||
endif
|
||||
|
||||
obj-m := mytimer_test.o
|
||||
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
CC ?= gcc
|
||||
PWD := $(shell pwd)
|
||||
|
||||
modules:
|
||||
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
clean:
|
||||
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions modules.order Module.symvers
|
||||
|
||||
depend .depend dep:
|
||||
$(CC) $(CFLAGS) -M *.c > .depend
|
||||
|
||||
ifeq (.depend,$(wildcard .depend))
|
||||
include .depend
|
||||
endif
|
38
debug/timer/mytimer_test.c
Normal file
38
debug/timer/mytimer_test.c
Normal file
@ -0,0 +1,38 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/timer.h>
|
||||
|
||||
#define EXPIRES_PERIOD (5*HZ)
|
||||
|
||||
struct self_define_struct {
|
||||
struct timer_list timer;
|
||||
};
|
||||
|
||||
struct self_define_struct g_sds;
|
||||
|
||||
static void timeout_handler(unsigned long tdata)
|
||||
{
|
||||
printk("%s, %d\n", __FUNCTION__, __LINE__);
|
||||
del_timer(&g_sds.timer);
|
||||
}
|
||||
|
||||
static int mytimer_test_init(void)
|
||||
{
|
||||
printk("%s, %d\n", __FUNCTION__, __LINE__);
|
||||
init_timer(&g_sds.timer);
|
||||
g_sds.timer.expires = jiffies + EXPIRES_PERIOD;
|
||||
g_sds.timer.function = timeout_handler;
|
||||
add_timer(&g_sds.timer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void mytimer_test_exit(void)
|
||||
{
|
||||
printk("%s, %d\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
module_init(mytimer_test_init)
|
||||
module_exit(mytimer_test_exit)
|
Reference in New Issue
Block a user