diff options
| author | Damien George | 2020-09-24 12:37:02 +1000 |
|---|---|---|
| committer | Damien George | 2020-10-01 14:20:42 +1000 |
| commit | d4b61b00172ccc231307e3ef33f66f28cb6b051f (patch) | |
| tree | 193b39ce0aa2a542d6f3ea6c96aadbe8f523858b /extmod/utime_mphal.c | |
| parent | 905a18aafefbe04aa2beceb84885c29aa156b975 (diff) | |
extmod/utime_mphal: Add generic utime.time_ns() function.
It requires mp_hal_time_ns() to be provided by a port. This function
allows very accurate absolute timestamps.
Enabled on unix, windows, stm32, esp8266 and esp32.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/utime_mphal.c')
| -rw-r--r-- | extmod/utime_mphal.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/extmod/utime_mphal.c b/extmod/utime_mphal.c index 6aff2cac7..d053cf128 100644 --- a/extmod/utime_mphal.c +++ b/extmod/utime_mphal.c @@ -99,4 +99,10 @@ STATIC mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) { } MP_DEFINE_CONST_FUN_OBJ_2(mp_utime_ticks_add_obj, time_ticks_add); +// Returns the number of nanoseconds since the Epoch, as an integer. +STATIC mp_obj_t time_time_ns(void) { + return mp_obj_new_int_from_ull(mp_hal_time_ns()); +} +MP_DEFINE_CONST_FUN_OBJ_0(mp_utime_time_ns_obj, time_time_ns); + #endif // MICROPY_PY_UTIME_MP_HAL |
