windows: Implement mp_hal_ticks_cpu in terms of QueryPerformanceCounter

This commit is contained in:
stijn 2016-11-01 10:25:13 +01:00
parent 0b9ed55026
commit 3272afe57f
3 changed files with 13 additions and 2 deletions

View File

@ -152,6 +152,7 @@ STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mod_time_time_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_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) },
{ MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) },
{ MP_ROM_QSTR(MP_QSTR_strftime), MP_ROM_PTR(&mod_time_strftime_obj) },

View File

@ -217,3 +217,13 @@ mp_uint_t mp_hal_ticks_us(void) {
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000 + tv.tv_usec;
}
mp_uint_t mp_hal_ticks_cpu(void) {
LARGE_INTEGER value;
QueryPerformanceCounter(&value);
#ifdef _WIN64
return value.QuadPart;
#else
return value.LowPart;
#endif
}

View File

@ -32,5 +32,5 @@
void mp_hal_move_cursor_back(unsigned int pos);
void mp_hal_erase_line_from_cursor(unsigned int n_chars_to_erase);
// TODO: Implement.
#define mp_hal_ticks_cpu() 0
#undef mp_hal_ticks_cpu
mp_uint_t mp_hal_ticks_cpu(void);