Skip to content

Commit 143b863

Browse files
committed
zephyr/modutime: Use extmod version of time module.
API change: time.time_ns() is added, but it just returns 0. No API or functional change to existing time functions. Signed-off-by: Damien George <[email protected]>
1 parent fa8a81a commit 143b863

File tree

3 files changed

+4
-35
lines changed

3 files changed

+4
-35
lines changed

ports/zephyr/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ set(MICROPY_SOURCE_PORT
4444
modbluetooth_zephyr.c
4545
modmachine.c
4646
modusocket.c
47-
modutime.c
4847
modzephyr.c
4948
modzsensor.c
5049
mphalport.c

ports/zephyr/modutime.c

+2-33
Original file line numberDiff line numberDiff line change
@@ -25,45 +25,14 @@
2525
* THE SOFTWARE.
2626
*/
2727

28-
#include "py/mpconfig.h"
29-
#if MICROPY_PY_UTIME
30-
3128
#include <zephyr/zephyr.h>
3229

33-
#include "py/runtime.h"
34-
#include "py/smallint.h"
35-
#include "py/mphal.h"
36-
#include "extmod/modutime.h"
30+
#include "py/obj.h"
3731

38-
STATIC mp_obj_t mod_time_time(void) {
32+
STATIC mp_obj_t mp_utime_time_get(void) {
3933
/* The absence of FP support is deliberate. The Zephyr port uses
4034
* single precision floats so the fraction component will start to
4135
* lose precision on devices with a long uptime.
4236
*/
4337
return mp_obj_new_int(k_uptime_get() / 1000);
4438
}
45-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_time_obj, mod_time_time);
46-
47-
STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = {
48-
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) },
49-
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) },
50-
{ MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) },
51-
{ MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) },
52-
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mod_time_time_obj) },
53-
{ MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) },
54-
{ MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) },
55-
{ MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) },
56-
{ MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) },
57-
{ MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) },
58-
};
59-
60-
STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table);
61-
62-
const mp_obj_module_t mp_module_time = {
63-
.base = { &mp_type_module },
64-
.globals = (mp_obj_dict_t *)&mp_module_time_globals,
65-
};
66-
67-
MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_time);
68-
69-
#endif // MICROPY_PY_UTIME

ports/zephyr/mpconfigport.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@
8787
#define MICROPY_PY_UHASHLIB (1)
8888
#define MICROPY_PY_UOS (1)
8989
#define MICROPY_PY_UTIME (1)
90-
#define MICROPY_PY_UTIME_MP_HAL (1)
90+
#define MICROPY_PY_UTIME_TIME_TIME_NS (1)
91+
#define MICROPY_PY_UTIME_INCLUDEFILE "ports/zephyr/modutime.c"
9192
#define MICROPY_PY_ZEPHYR (1)
9293
#define MICROPY_PY_ZSENSOR (1)
9394
#define MICROPY_PY_SYS_MODULES (0)

0 commit comments

Comments
 (0)