summaryrefslogtreecommitdiff
path: root/windows
diff options
context:
space:
mode:
Diffstat (limited to 'windows')
-rw-r--r--windows/mpconfigport.h1
-rw-r--r--windows/msvc/sources.props1
-rw-r--r--windows/windows_mphal.c23
-rw-r--r--windows/windows_mphal.h3
4 files changed, 28 insertions, 0 deletions
diff --git a/windows/mpconfigport.h b/windows/mpconfigport.h
index da49bc0dc..88596977c 100644
--- a/windows/mpconfigport.h
+++ b/windows/mpconfigport.h
@@ -92,6 +92,7 @@
#define MICROPY_PY_UBINASCII (1)
#define MICROPY_PY_URANDOM (1)
#define MICROPY_PY_UTIME (1)
+#define MICROPY_PY_UTIME_MP_HAL (1)
#define MICROPY_PY_MACHINE (1)
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
diff --git a/windows/msvc/sources.props b/windows/msvc/sources.props
index 569f24c76..4ea917552 100644
--- a/windows/msvc/sources.props
+++ b/windows/msvc/sources.props
@@ -23,6 +23,7 @@
<ClCompile Include="$(PyBaseDir)extmod\modurandom.c" />
<ClCompile Include="$(PyBaseDir)extmod\modure.c" />
<ClCompile Include="$(PyBaseDir)extmod\moduzlib.c" />
+ <ClCompile Include="$(PyBaseDir)extmod\utime_mphal.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(PyBaseDir)py\*.h" />
diff --git a/windows/windows_mphal.c b/windows/windows_mphal.c
index 6cc4f6542..3ad693905 100644
--- a/windows/windows_mphal.c
+++ b/windows/windows_mphal.c
@@ -28,6 +28,7 @@
#include "py/mpstate.h"
#include "py/mphal.h"
+#include <sys/time.h>
#include <windows.h>
#include <unistd.h>
@@ -204,3 +205,25 @@ void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
void mp_hal_stdout_tx_str(const char *str) {
mp_hal_stdout_tx_strn(str, strlen(str));
}
+
+mp_uint_t mp_hal_ticks_ms(void) {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec * 1000 + tv.tv_usec / 1000;
+}
+
+mp_uint_t mp_hal_ticks_us(void) {
+ struct timeval tv;
+ 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
+}
diff --git a/windows/windows_mphal.h b/windows/windows_mphal.h
index dce248455..854e14a7a 100644
--- a/windows/windows_mphal.h
+++ b/windows/windows_mphal.h
@@ -31,3 +31,6 @@
void mp_hal_move_cursor_back(unsigned int pos);
void mp_hal_erase_line_from_cursor(unsigned int n_chars_to_erase);
+
+#undef mp_hal_ticks_cpu
+mp_uint_t mp_hal_ticks_cpu(void);