linux平台程序高精度延时问题select-usleep等

前言

微秒级别的延时。。。

1.能用

   #include <unistd.h>
 int usleep(useconds_t usec);              微秒级:1/10^-6

2.不能使用,每次使用的话,在CAN分析平台接收不到数据;

头文件:#include “sys/time.h”

struct timeval delay;
delay.tv_sec = 0;
delay.tv_usec = 20 * 1000; // 20 ms
select(0, NULL, NULL, NULL, &delay);

3.还没有试。。。

void microseconds_sleep(unsigned long uSec){
    struct timeval tv;
    tv.tv_sec=uSec/1000000;
    tv.tv_usec=uSec%1000000;
    int err;
    do{
        err=select(0,NULL,NULL,NULL,&tv);
    }while(err<0 && errno==EINTR);
}

参考

1.https://www.cnblogs.com/tdyizhen1314/p/4140643.html

2.https://www.cnblogs.com/longbiao831/p/4556246.html

3.https://blog.csdn.net/u010487568/article/details/52043136

猜你喜欢

转载自www.cnblogs.com/happyamyhope/p/8944492.html