1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| int jiffies_to_msecs(const unsigned long j) 将 jiffies 类型的参数 j 分别转换为对应的毫秒、微秒、纳秒。 int jiffies_to_usecs(const unsigned long j) u64 jiffies_to_nsecs(const unsigned long j) long msecs_to_jiffies(const unsigned int m) 将毫秒、微秒、纳秒转换为 jiffies 类型。 long usecs_to_jiffies(const unsigned int u) unsigned long nsecs_to_jiffies(u64 n) ```
## 内核定时器 ```c #include <linux/timer.h> struct timer_list timer;
void function(unsigned long arg) {
mod_timer(&dev->timertest, jiffies + msecs_to_jiffies(2)); }
void init(void) { init_timer(&timer);
timer.function = function; timer.expires=jffies + msecs_to_jiffies(2); timer.data = (unsigned long)&dev;
add_timer(&timer); }
void exit(void) { del_timer(&timer); del_timer_sync(&timer); } ```
## 内核短延时函数 ```c void ndelay(unsigned long nsecs) 纳秒、微秒和毫秒延时函数。 void udelay(unsigned long usecs) void mdelay(unsigned long mseces)
|