kopia lustrzana https://github.com/micropython/micropython
unix,windows: Implement mp_hal_time_ns using gettimeofday.
This provides microsecond accuracy. Signed-off-by: Damien George <damien@micropython.org>pull/6479/head
rodzic
98182a97c5
commit
905a18aafe
|
@ -216,6 +216,7 @@ mp_uint_t mp_hal_ticks_us(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t mp_hal_time_ns(void) {
|
uint64_t mp_hal_time_ns(void) {
|
||||||
time_t now = time(NULL);
|
struct timeval tv;
|
||||||
return (uint64_t)now * 1000000000ULL;
|
gettimeofday(&tv, NULL);
|
||||||
|
return (uint64_t)tv.tv_sec * 1000000000ULL + (uint64_t)tv.tv_usec * 1000ULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,3 +255,9 @@ mp_uint_t mp_hal_ticks_cpu(void) {
|
||||||
return value.LowPart;
|
return value.LowPart;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t mp_hal_time_ns(void) {
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
return (uint64_t)tv.tv_sec * 1000000000ULL + (uint64_t)tv.tv_usec * 1000ULL;
|
||||||
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue