//timer编写: //嵌入到某个设备结构体里面去
#include <linux/timer.h>
struct timer_list
{
struct list_head entry; //定时器列表
unsigned long expires;//定时器到时时间
void (*function)(unsigned long);
unsigned long data; //
struct time_base_s*base;
};
#define VBUS_POLL_TIMEOUT msecs_to_jiffies(500)
struct s3c2410_udc {
struct timer_list vbus_timer;
};
//return container_of(gadget, struct s3c2410_udc, gadget);
static void s3c2410__vbus_timer(struct timer_list *t)
{
struct s3c2410_udc *udc = container_of(t,struct s3c2410_udc,vbus_timer);
mod_timer(&udc->vbus_timer, jiffies + VBUS_POLL_TIMEOUT);
}
static int s3c2410_udc_probe(struct platform_device*pdev)
{
timer_setup(&udc->vbus_timer, s3c2410__vbus_timer, 0);//初始化定时器并赋值其成员
//static inline void setup_timer(struct timer_list*timer,void(*function)(unsigned long),unsigned long data);
mod_timer(&udc->vbus_timer, jiffies + VBUS_POLL_TIMEOUT);//int mod_timer(struct timer_list*timer,unsigned long expires); //修改定时器的expire
return 0;
}
static int s3c2410_udc_remove(struct platform_device*pdev)
{
// int del_timer(struct timer_list*timer);
del_timer_sync(&udc->vbus_timer); // int del_timer(struct timer_list*timer);
return 0;
}
linux内核定时器的编写实例
最新推荐文章于 2023-02-13 16:00:36 发布