summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2018-10-22 17:41:06 -0700
committerGitHub <noreply@github.com>2018-10-22 17:41:06 -0700
commitdcb59178f8024a43175e96a8707e874c1eba5f61 (patch)
tree97d0594be8d1d7fd122cb50e805c9e1cd5bf4e15
parentb436666e852b0d75a970052997ea019af7411b45 (diff)
parentec1aec1921c55b7570403b2958dc0a8170fe78ab (diff)
Merge pull request #1290 from jepler/time-monotonic-ns
shared-bindings/time: introduce time.monotonic_ns
-rw-r--r--shared-bindings/time/__init__.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c
index 4d9554569..8a5e16c5e 100644
--- a/shared-bindings/time/__init__.c
+++ b/shared-bindings/time/__init__.c
@@ -206,6 +206,20 @@ STATIC mp_obj_t time_time(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
+//| .. method:: monotonic_ns(clk_id)
+//|
+//| Return the time of the specified clock clk_id in nanoseconds. Refer to
+//| Clock ID Constants for a list of accepted values for clk_id.
+//|
+//| :return: the current time
+//| :rtype: int
+//|
+STATIC mp_obj_t time_monotonic_ns(void) {
+ uint64_t time64 = common_hal_time_monotonic() * 1000000llu;
+ return mp_obj_new_int_from_ll((long long) time64);
+}
+MP_DEFINE_CONST_FUN_OBJ_0(time_monotonic_ns_obj, time_monotonic_ns);
+
//| .. method:: localtime([secs])
//|
//| Convert a time expressed in seconds since Jan 1, 1970 to a struct_time in
@@ -280,6 +294,7 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = {
#endif // MICROPY_PY_COLLECTIONS
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) },
+ { MP_ROM_QSTR(MP_QSTR_monotonic_ns), MP_ROM_PTR(&time_monotonic_ns_obj) },
#endif
};