Skip to content
Snippets Groups Projects
Verified Commit 8926fd02 authored by rahix's avatar rahix
Browse files

feat(utime): Implement ticks_ms() and ticks_us()


Implement the hal functions necessary for utime.ticks_ms() and
utime.ticks_us().  This enables much more accurate measurements of time
taken in Pycardium (useful for profiling).

Please note that the tick counter will reset whenever a new app is
loaded.

Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 020050f4
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,20 @@ alarm.
.. versionadded:: 1.11
.. py:function:: ticks_ms()
Return processor ticks (converted to milliseconds) since Pycardium startup.
This function should be the preferred method for timing and profiling
because it does not need an API call and thus is very fast.
.. py:function:: ticks_us()
Return processor ticks (converted to microseconds) since Pycardium startup.
This function should be the preferred method for timing and profiling
because it does not need an API call and thus is very fast.
.. py:function:: unix_time()
Return the current unix time as seconds since the epoch.
......
......@@ -202,6 +202,8 @@ static const mp_rom_map_elem_t time_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) },
{ MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) },
{ MP_ROM_QSTR(MP_QSTR_alarm), MP_ROM_PTR(&time_alarm_obj) },
#if 0
/* TODO: Implement those */
......
......@@ -271,7 +271,12 @@ void mp_hal_delay_us(mp_uint_t us)
mp_uint_t mp_hal_ticks_ms(void)
{
return 0;
return (mp_uint_t)(systick_get_us() / 1000);
}
mp_uint_t mp_hal_ticks_us(void)
{
return (mp_uint_t)systick_get_us();
}
/******************************************************************************
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment