内核态延时和定时器

简介: 1、jiffiesHZ=100,jiffies=1 means 10ms。 2,延时unsigned long timeout = jiffies + (3*HZ);while (hwgroup->busy) {if (time_after(jiffies, timeout)) { ...
1、jiffies
HZ=100,jiffies=1 means 10ms。
 
2,延时
unsigned long timeout = jiffies + (3*HZ);
while (hwgroup->busy) {
if (time_after(jiffies, timeout)) {
 return -EBUSY;
 }
}
 
unsigned long timeout = HZ;
schedule_timeout(timeout); /* Allow other parts of the kernel to run */
 
短延时:mdelay, udelay, ndelay
 
3,时间
clock_settime, clock_gettime
do_gettimeofday
time()
localtime()
mktime()
gettimeofday()
 
 
3,定时器
#include <linux/timer.h>
struct timer_list my_timer;
init_timer(&my_timer); /* Also see setup_timer() */
my_timer.expire = jiffies + n*HZ; /* n is the timeout in number of seconds */
my_timer.function = timer_func; /* Function to execute after n seconds */
my_timer.data = func_parameter; /* Parameter to be passed to timer_func */
add_timer(&my_timer); /* Start the timer */
其他函数:mod_timer, del_timer
用户态:setitimer,getitimer
 
4、高精度定时器
void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, enum hrtimer_mode mode);
timer.function = hr_callback;
int hrtimer_start(struct hrtimer *timer, ktime_t tim,
 const enum hrtimer_mode mode);
int hrtimer_cancel(struct hrtimer *timer);
 
 
 
 
目录
相关文章
|
2月前
|
数据采集 调度 C语言
嵌入式系统中的定时器中断与任务调度
嵌入式系统中的定时器中断与任务调度
31 0
|
10月前
|
Linux 调度
按键消抖的两种方法--中断延迟工作与定时器
按键消抖的两种方法--中断延迟工作与定时器
362 0
|
2月前
|
传感器
单片机定时器中断
单片机定时器中断
|
7月前
|
传感器 算法
RTOS中相对延时和绝对延时的区别
RTOS中相对延时和绝对延时的区别
48 1
|
8月前
|
Linux
Linux驱动中断与时间篇——高精度定时器hrtimer
Linux驱动中断与时间篇——高精度定时器hrtimer
|
8月前
|
Linux
Linux驱动中断与时间篇——低分辨率定时器
Linux驱动中断与时间篇——低分辨率定时器
|
11月前
MSP430F5529库函数定时器A——定时中断
MSP430F5529库函数定时器A——定时中断
131 0
STM32:定时器定时中断
STM32:定时器定时中断
156 0
STM32:定时器定时中断
|
监控 物联网 芯片
看门狗定时器原理|学习笔记
快速学习看门狗定时器原理
163 0
看门狗定时器原理|学习笔记