time.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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)/*GCC*/) && !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. #if defined(__ARMCC_VERSION) || defined (__ICCARM__)
  52. struct tm *gmtime_r(const time_t *timep, struct tm *r);
  53. #endif
  54. #ifdef RT_USING_POSIX
  55. #include <sys/types.h>
  56. /* posix clock and timer */
  57. #define MILLISECOND_PER_SECOND 1000UL
  58. #define MICROSECOND_PER_SECOND 1000000UL
  59. #define NANOSECOND_PER_SECOND 1000000000UL
  60. #define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
  61. #define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
  62. #define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
  63. #ifndef CLOCK_REALTIME
  64. #define CLOCK_REALTIME 1
  65. #endif
  66. #define CLOCK_CPUTIME_ID 2
  67. #ifndef CLOCK_PROCESS_CPUTIME_ID
  68. #define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
  69. #endif
  70. #ifndef CLOCK_THREAD_CPUTIME_ID
  71. #define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
  72. #endif
  73. #ifndef CLOCK_MONOTONIC
  74. #define CLOCK_MONOTONIC 4
  75. #endif
  76. int clock_getres (clockid_t clockid, struct timespec *res);
  77. int clock_gettime (clockid_t clockid, struct timespec *tp);
  78. int clock_settime (clockid_t clockid, const struct timespec *tp);
  79. int clock_time_to_tick(const struct timespec *time);
  80. #endif /* RT_USING_POSIX */
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84. #endif /* _SYS_TIME_H_ */