例子一:
#include<linux/kernel.h>
init_timer(&transfer_timer);
transfer_timer.expires = jiffies + (2 * HZ);
transfer_timer.data = (unsigned long) 10;
transfer_timer.function = usb_light_timer_funcation;
add_timer(&transfer_timer);
void usb_light_timer_funcation(unsigned long p_data)
{
printk( "******* enter usb_light_timer_funcation! ********\n" );
if(timer_blink_flag == 1)
{
timer_blink_flag = 0;
del_timer(&transfer_timer);
// 这里一定要先删除再加新定时器,不然系统就有问题了。
init_timer(&transfer_timer);
transfer_timer.expires = jiffies + (2 * HZ);
transfer_timer.data = (unsigned long)10;
transfer_timer.function = usb_light_timer_funcation;
add_timer(&transfer_timer);
printk( "******* usb_light_timer_funcation: renew the timer ! ********\n" );
}
else
{
del_timer(&transfer_timer);
printk( "******* usb_light_timer_funcation: delete the timer ! ********\n" );
usb_flag = 0;
kerSysLedCtrl((BOARD_LED_NAME)( kLedUsb1), kLedStateOn);
}
}