-
Notifications
You must be signed in to change notification settings - Fork 1
/
time.c
56 lines (53 loc) · 1.12 KB
/
time.c
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
51
52
53
54
55
56
/**
* @file time.c
* Linux time delay functions based on select
*
* @copyright
* Copyright (C) 2017 Real Flight Systems
* @author James F Dougherty <[email protected]>
*/
/**
* @defgroup time
* @addtogroup time
* @{
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <sys/select.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <errno.h>
/**
* @brief microsecond delay
*
* Delay specified number of microseconds, the processor will wait
* this amount of time before continuing execution.
*
* @param[in] usecs the number of microseconds to sleep
*/
void us_delay(unsigned int usecs)
{
int rv;
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = usecs;
do {
rv = select(1,NULL,NULL,NULL,&tv);
} while( (rv == -1) && (errno == EINTR) );
}
/**
* @brief millisecond delay
*
* Delay specified number of milliseconds, the processor will wait
* this amount of time before continuing execution.
*
* @param[in] usecs the number of milliseconds to sleep
*/
void ms_delay(unsigned int usecs)
{
return us_delay(usecs*1000);
}
/** @}*/