time.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-09-07 Meco Man combine gcc armcc iccarm
  9. * 2021-02-12 Meco Man move all definitions located in <clock_time.h> to this file
  10. */
  11. #ifndef _SYS_TIME_H_
  12. #define _SYS_TIME_H_
  13. #include <rtconfig.h>
  14. #include <time.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /*
  19. * Skip define timespec for IAR version over 8.10.1 where __VER__ is 8010001.
  20. */
  21. #if defined ( __ICCARM__ ) && (__VER__ >= 8010001)
  22. #define _TIMESPEC_DEFINED
  23. #endif
  24. #ifndef _TIMEVAL_DEFINED
  25. #define _TIMEVAL_DEFINED
  26. /*
  27. * Structure returned by gettimeofday(2) system call,
  28. * and used in other calls.
  29. */
  30. #if !(defined(_WIN32))
  31. struct timeval {
  32. long tv_sec; /* seconds */
  33. long tv_usec; /* and microseconds */
  34. };
  35. #endif
  36. #endif /* _TIMEVAL_DEFINED */
  37. #if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)) && !defined (__ICCARM__) && !defined (_WIN32)
  38. struct timespec {
  39. time_t tv_sec; /* seconds */
  40. long tv_nsec; /* and nanoseconds */
  41. };
  42. #endif
  43. struct timezone {
  44. int tz_minuteswest; /* minutes west of Greenwich */
  45. int tz_dsttime; /* type of dst correction */
  46. };
  47. int stime(const time_t *t);
  48. time_t timegm(struct tm * const t);
  49. int gettimeofday(struct timeval *tv, struct timezone *tz);
  50. int settimeofday(const struct timeval *tv, const struct timezone *tz);
  51. #ifdef RT_USING_POSIX
  52. #include <sys/types.h>
  53. /* posix clock and timer */
  54. #define MILLISECOND_PER_SECOND 1000UL
  55. #define MICROSECOND_PER_SECOND 1000000UL
  56. #define NANOSECOND_PER_SECOND 1000000000UL
  57. #define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
  58. #define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
  59. #define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
  60. #ifndef CLOCK_REALTIME
  61. #define CLOCK_REALTIME 1
  62. #endif
  63. #define CLOCK_CPUTIME_ID 2
  64. #ifndef CLOCK_PROCESS_CPUTIME_ID
  65. #define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
  66. #endif
  67. #ifndef CLOCK_THREAD_CPUTIME_ID
  68. #define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
  69. #endif
  70. #ifndef CLOCK_MONOTONIC
  71. #define CLOCK_MONOTONIC 4
  72. #endif
  73. int clock_getres (clockid_t clockid, struct timespec *res);
  74. int clock_gettime (clockid_t clockid, struct timespec *tp);
  75. int clock_settime (clockid_t clockid, const struct timespec *tp);
  76. int clock_time_to_tick(const struct timespec *time);
  77. #endif /* RT_USING_POSIX */
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif /* _SYS_TIME_H_ */