8000 shared-bindings/time: introduce time.monotonic_ns by jepler · Pull Request #1290 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content
Dismiss alert

shared-bindings/time: introduce time.monotonic_ns #1290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions shared-bindings/time/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
};

Expand Down
0