Timer

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; //never touch
struct timer_list* prev; //never touch
unsigned long expires; //the timeout, in jiffies
unsigned long data; //argument to handler
void (*function)(unsigned long); //handler of the timeout
volatile int running; //dont't touch
};
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; //after 1sec
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;
}