From 2baeb59e61b110e86a468b0b37c0fadf9dfe003c Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Fri, 20 Nov 2020 13:27:12 +0100 Subject: [PATCH] - added Hal_getTimeInNs function for windows --- .../iec61850_9_2_LE_example.c | 2 ++ hal/time/win32/time.c | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/examples/iec61850_9_2_LE_example/iec61850_9_2_LE_example.c b/examples/iec61850_9_2_LE_example/iec61850_9_2_LE_example.c index a7a016e6..34aba48e 100644 --- a/examples/iec61850_9_2_LE_example/iec61850_9_2_LE_example.c +++ b/examples/iec61850_9_2_LE_example/iec61850_9_2_LE_example.c @@ -27,6 +27,8 @@ #include #include #include + +#define _USE_MATH_DEFINES #include /* Include the generated header with the model access handles */ diff --git a/hal/time/win32/time.c b/hal/time/win32/time.c index af58793f..0b182d20 100644 --- a/hal/time/win32/time.c +++ b/hal/time/win32/time.c @@ -34,10 +34,26 @@ Hal_getTimeInMs() uint64_t now; static const uint64_t DIFF_TO_UNIXTIME = 11644473600000LL; - + GetSystemTimeAsFileTime(&ft); now = (LONGLONG)ft.dwLowDateTime + ((LONGLONG)(ft.dwHighDateTime) << 32LL); return (now / 10000LL) - DIFF_TO_UNIXTIME; } + +nsSinceEpoch +Hal_getTimeInNs() +{ + FILETIME ft; + + static const uint64_t DIFF_TO_UNIXTIME = 11644473600000000000LL; + + GetSystemTimeAsFileTime(&ft); + + nsSinceEpoch nsTime = (LONGLONG)ft.dwLowDateTime + ((LONGLONG)(ft.dwHighDateTime) << 32LL); + + nsTime = nsTime * 100LL - DIFF_TO_UNIXTIME; + + return nsTime; +}