time.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #define DST_NONE 0 /* not on dst */
  19. #define DST_USA 1 /* USA style dst */
  20. #define DST_AUST 2 /* Australian style dst */
  21. #define DST_WET 3 /* Western European dst */
  22. #define DST_MET 4 /* Middle European dst */
  23. #define DST_EET 5 /* Eastern European dst */
  24. #define DST_CAN 6 /* Canada */
  25. #define DST_GB 7 /* Great Britain and Eire */
  26. #define DST_RUM 8 /* Rumania */
  27. #define DST_TUR 9 /* Turkey */
  28. #define DST_AUSTALT 10 /* Australian style with shift in 1986 */
  29. #ifndef _TIMEVAL_DEFINED
  30. #define _TIMEVAL_DEFINED
  31. /*
  32. * Structure returned by gettimeofday(2) system call,
  33. * and used in other calls.
  34. */
  35. #if !(defined(_WIN32))
  36. struct timeval {
  37. long tv_sec; /* seconds */
  38. long tv_usec; /* and microseconds */
  39. };
  40. #endif
  41. #endif /* _TIMEVAL_DEFINED */
  42. #if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !(defined(__ICCARM__) && (__VER__ >= 8010001)) && !defined(_WIN32)
  43. struct timespec {
  44. time_t tv_sec; /* seconds */
  45. long tv_nsec; /* and nanoseconds */
  46. };
  47. #endif
  48. struct timezone {
  49. int tz_minuteswest; /* minutes west of Greenwich */
  50. int tz_dsttime; /* type of dst correction */
  51. };
  52. int stime(const time_t *t);
  53. time_t timegm(struct tm * const t);
  54. int gettimeofday(struct timeval *tv, struct timezone *tz);
  55. int settimeofday(const struct timeval *tv, const struct timezone *tz);
  56. #if defined(__ARMCC_VERSION) || defined (__ICCARM__)
  57. struct tm *gmtime_r(const time_t *timep, struct tm *r);
  58. #endif
  59. #ifdef RT_USING_POSIX
  60. #include <sys/types.h>
  61. /* posix clock and timer */
  62. #define MILLISECOND_PER_SECOND 1000UL
  63. #define MICROSECOND_PER_SECOND 1000000UL
  64. #define NANOSECOND_PER_SECOND 1000000000UL
  65. #define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
  66. #define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
  67. #define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
  68. #ifndef CLOCK_REALTIME
  69. #define CLOCK_REALTIME 1
  70. #endif
  71. #define CLOCK_CPUTIME_ID 2
  72. #ifndef CLOCK_PROCESS_CPUTIME_ID
  73. #define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
  74. #endif
  75. #ifndef CLOCK_THREAD_CPUTIME_ID
  76. #define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
  77. #endif
  78. #ifndef CLOCK_MONOTONIC
  79. #define CLOCK_MONOTONIC 4
  80. #endif
  81. int clock_getres (clockid_t clockid, struct timespec *res);
  82. int clock_gettime (clockid_t clockid, struct timespec *tp);
  83. int clock_settime (clockid_t clockid, const struct timespec *tp);
  84. int clock_time_to_tick(const struct timespec *time);
  85. #endif /* RT_USING_POSIX */
  86. #ifdef __cplusplus
  87. }
  88. #endif
  89. #endif /* _SYS_TIME_H_ */