Skip to content
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

Are all time.tick_xxx() functions bound to 30 bits? #421

Closed
microbit-carlos opened this issue Apr 3, 2024 · 2 comments
Closed

Are all time.tick_xxx() functions bound to 30 bits? #421

microbit-carlos opened this issue Apr 3, 2024 · 2 comments

Comments

@microbit-carlos
Copy link
Collaborator

Looking at time.tick_cpu() and the values returned, it looks like this functions overflows at the 30-bit limit of a MicroPython "small int".
Would this be true for all time.tick_xxx()? If that's the case, it's something we could add to the docs.

@microbit-carlos
Copy link
Collaborator Author

microbit-carlos commented Apr 3, 2024

Ah, looking at the upstream code it's more clear that this is the case:
https://github.com/micropython/micropython/blob/v1.22.0/extmod/modtime.c#L151-L164

STATIC mp_obj_t time_ticks_ms(void) {
    return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_TIME_TICKS_PERIOD - 1));
}
MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_ms_obj, time_ticks_ms);

STATIC mp_obj_t time_ticks_us(void) {
    return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_us() & (MICROPY_PY_TIME_TICKS_PERIOD - 1));
}
MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_us_obj, time_ticks_us);

STATIC mp_obj_t time_ticks_cpu(void) {
    return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_cpu() & (MICROPY_PY_TIME_TICKS_PERIOD - 1));
}
MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_cpu_obj, time_ticks_cpu);

And https://github.com/bbcmicrobit/micropython/blob/v1.1.1/source/extmod/utime_mphal.c#L67-L80.

We can update the micro:bit MicroPython docs for V1 and V2 to reflect this.

@microbit-carlos microbit-carlos added the documentation Improvements or additions to documentation label Apr 3, 2024
@microbit-carlos
Copy link
Collaborator Author

Ups, wrong repo, moved to microbit-foundation/micropython-microbit-v2#178

@microbit-carlos microbit-carlos closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2024
@microbit-carlos microbit-carlos removed the documentation Improvements or additions to documentation label Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant