ua_clock.c 1.2 KB

1234567891011121314151617181920212223242526272829303132
  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 2016-2017 (c) Julius Pfrommer, Fraunhofer IOSB
  5. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  6. * Copyright 2017 (c) Thomas Stalder
  7. */
  8. #ifdef UA_ARCHITECTURE_FREERTOSLWIP
  9. #include <open62541/types.h>
  10. #include <task.h>
  11. /* The current time in UTC time */
  12. UA_DateTime UA_DateTime_now(void) {
  13. UA_DateTime microSeconds = ((UA_DateTime)xTaskGetTickCount()) * (1000000 / configTICK_RATE_HZ);
  14. return ((microSeconds / 1000000) * UA_DATETIME_SEC) + ((microSeconds % 1000000) * UA_DATETIME_USEC) + UA_DATETIME_UNIX_EPOCH;
  15. }
  16. /* Offset between local time and UTC time */
  17. UA_Int64 UA_DateTime_localTimeUtcOffset(void) {
  18. return 0; //TODO: this is set to zero since UA_DateTime_now() is just the local time, and not UTC.
  19. }
  20. /* CPU clock invariant to system time changes. Use only to measure durations,
  21. * not absolute time. */
  22. UA_DateTime UA_DateTime_nowMonotonic(void) {
  23. return (((UA_DateTime)xTaskGetTickCount()) * 1000 / configTICK_RATE_HZ) * UA_DATETIME_MSEC;
  24. }
  25. #endif /* UA_ARCHITECTURE_FREERTOSLWIP */