diff options
| author | Damien George | 2020-08-01 23:50:23 +1000 |
|---|---|---|
| committer | Damien George | 2020-08-22 16:13:44 +1000 |
| commit | ee50a6effebf315c38d4a129dc9f65ee722eb5b6 (patch) | |
| tree | 16cfee569848d9d75fbb8eeacf39466f5b2b7319 /ports/esp32 | |
| parent | badd351150df70bea6644db98f48fbc3a1e5ffea (diff) | |
py/mphal.h: Introduce mp_hal_time_ns and implement on various ports.
This should return a 64-bit value being the number of nanoseconds since
1970/1/1.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'ports/esp32')
| -rw-r--r-- | ports/esp32/mphalport.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c index 99548ad62..5e526df66 100644 --- a/ports/esp32/mphalport.c +++ b/ports/esp32/mphalport.c @@ -28,6 +28,7 @@ #include <stdio.h> #include <string.h> +#include <sys/time.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -195,6 +196,12 @@ void mp_hal_delay_us(uint32_t us) { } } +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; +} + // Wake up the main task if it is sleeping void mp_hal_wake_main_task_from_isr(void) { BaseType_t xHigherPriorityTaskWoken = pdFALSE; |
