init_timer()- timer 초기화
add_timer()- timer 함수 등록
del_timer()- timer 함수 제거
void init_timer(struct timer_list* timer);
void add_timer(struct timer_list* timer);
int del_timer(struct timer_list* timer);
struct timer_list{
struct timer_list* next;
struct timer_list* prev;
unsigned long expires;
unsigned long data;
void (*function)(unsigned long);
volatile int running;
};
c source file_device driver
struct timer_list hex_timer;
void init_add_timer(void){
init_timer(&hex_timer);
hex_timer.function=hex_timer_function;
hex_timer.expires=jiffies+HZ;
hex_timer.data=0;
add_timer(&hex_timer);
}
void remove_timer(void){
del_timer(&hex_timer);
}
void hex_timer_function(unsigned long ptr){
if(!(mode&BLINK))return;
turnoff=!turnoff;
if(turnoff){
iowrite32(0, hex0_addr);
iowrite32(0, hex1_addr);
}else{
iowrite32(hex0, hex0_addr);
iowrite32(hex1, hex1_addr);
}
init_add_timer();
}
static long hex_ioctl(struct file* file, unsigned int cmd, unsigned long* arg){
unsigned int newcmd;
newcmd=cmd;
if((mode&BLINK)&&!(newcmd&BLINK))remove_timer();
mode=newcmd;
if(mode&BLINK){
init_add_timer();
}
return 0;
}