ua_clock.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  3. *
  4. * Copyright 2018 (c) Stephan Kantelberg
  5. */
  6. #ifdef UA_ARCHITECTURE_WEC7
  7. #ifndef _BSD_SOURCE
  8. # define _BSD_SOURCE
  9. #endif
  10. #include <open62541/types.h>
  11. #include <time.h>
  12. /* Backup definition of SLIST_ENTRY on mingw winnt.h */
  13. # ifdef SLIST_ENTRY
  14. # pragma push_macro("SLIST_ENTRY")
  15. # undef SLIST_ENTRY
  16. # define POP_SLIST_ENTRY
  17. # endif
  18. # include <windows.h>
  19. /* restore definition */
  20. # ifdef POP_SLIST_ENTRY
  21. # undef SLIST_ENTRY
  22. # undef POP_SLIST_ENTRY
  23. # pragma pop_macro("SLIST_ENTRY")
  24. # endif
  25. UA_DateTime UA_DateTime_now(void) {
  26. /* Windows filetime has the same definition as UA_DateTime */
  27. FILETIME ft;
  28. SYSTEMTIME st;
  29. GetSystemTime(&st);
  30. SystemTimeToFileTime(&st, &ft);
  31. ULARGE_INTEGER ul;
  32. ul.LowPart = ft.dwLowDateTime;
  33. ul.HighPart = ft.dwHighDateTime;
  34. return (UA_DateTime)ul.QuadPart;
  35. }
  36. UA_Int64 UA_DateTime_localTimeUtcOffset(void) {
  37. return 0;
  38. }
  39. UA_DateTime UA_DateTime_nowMonotonic(void) {
  40. LARGE_INTEGER freq, ticks;
  41. QueryPerformanceFrequency(&freq);
  42. QueryPerformanceCounter(&ticks);
  43. UA_Double ticks2dt = UA_DATETIME_SEC / (UA_Double)freq.QuadPart;
  44. return (UA_DateTime)(ticks.QuadPart * ticks2dt);
  45. }
  46. #endif /* UA_ARCHITECTURE_WEC7 */