timer.c

来自「modbus rtu协议 linux 平台的实现.读取相关配置文件信息.通过串口」· C语言 代码 · 共 53 行

C
53
字号
/******************************************************************************
 *
 * Copyright (c) 2008 Shanghai IS Software
 *
 * All rights reserved
 *
 * $Revision$
 *
 * $LastChangedBy$:
 * 1. lcj
 *
 * $LastChangedData$:
 * 2008/09/25
 *
 * Description: timer  ( 10ms )
 *
 * Revision History:
 * 2008/09/25 14:33 by lcj
 * #1.created
 *
 *****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/select.h>
#include <errno.h>


void ms_sleep(unsigned long ms)
{
	int err;

	struct timeval tv;

	tv.tv_sec = ms/1000;
	tv.tv_usec = (ms%1000) * 1000;

	while ((-1 == select(0,0,0,0,&tv)) && (err == errno));
}

void timer(int sec,long usec)
{
	struct timeval tvselect;

	tvselect.tv_sec = sec;
	tvselect.tv_usec = usec;

	select(0,NULL,NULL,NULL,&tvselect);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?