时间管理 4> 动态定时器

3800阅读 0评论2015-06-17 lsxuan驱动
分类:嵌入式

0> 固定步骤:

1步:定义定时器:
            struct timer_list   my_time;
2步:初始化:
            init_time(&my_time);
3步:实例化:
            my_timer.expirex = jiffies + delay;               /*期望定时值*/
            my_timer.date  =  0;                                /*传给定时器处理函数的参数,不用时写0*/
            my_timer.function = my_fun;                  /*定时器处理函数*/
4步:启动:
            add_timer(&my_timer);                         /*这句话后,定时器开始工作*/
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

1> 小简化操作:
        将2, 3步合并:setup_time(&my_time, my_fun, 0);
                                        my_timer.expirex = jiffies + delay;
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

2> 大简化操作:
           将1,2,3步合并:DEFINE_TIMER(my_time, my_fun, jiffies+delay, 0);
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

4> 更新定时器时刻:
            int mod_timer(struct timer_list *timer, unsigned long expires);

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
5> 移除定时器:
           int del_timer_sync(struct timer_list  *timer);





                 
上一篇:时间管理 3> 短延迟
下一篇:获取硬件资源方法