Skip to content

Commit 6d7e185

Browse files
authored
Fix Arduino with POSIX (#48)
Signed-off-by: Pablo Garrido <pablogs9@gmail.com> Signed-off-by: Pablo Garrido <pablogs9@gmail.com>
1 parent b256be9 commit 6d7e185

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

‎platform_code/arduino/clock_gettime.cpp‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
#include <sys/time.h>
44
#define micro_rollover_useconds 4294967295
55

6+
#ifndef WITH_POSIX
7+
68
extern "C" int clock_gettime(clockid_t unused, struct timespec *tp)
79
{
8-
(void)unused;
9-
static uint32_t rollover = 0;
10-
static uint32_t last_measure = 0;
10+
(void)unused;
11+
static uint32_t rollover = 0;
12+
static uint32_t last_measure = 0;
13+
14+
uint32_t m = micros();
15+
rollover += (m < last_measure) ? 1 : 0;
1116

12-
uint32_t m = micros();
13-
rollover += (m < last_measure) ? 1 : 0;
17+
uint64_t real_us = (uint64_t) (m + rollover * micro_rollover_useconds);
18+
tp->tv_sec = real_us / 1000000;
19+
tp->tv_nsec = (real_us % 1000000) * 1000;
20+
last_measure = m;
1421

15-
uint64_t real_us = (uint64_t) (m + rollover * micro_rollover_useconds);
16-
tp->tv_sec = real_us / 1000000;
17-
tp->tv_nsec = (real_us % 1000000) * 1000;
18-
last_measure = m;
22+
return 0;
23+
}
1924

20-
return 0;
21-
}
25+
#endif // ifndef WITH_POSIX

0 commit comments

Comments
 (0)