time.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 <sys/types.h>
  15. #include <stdint.h>
  16. #include <time.h>
  17. #ifdef _WIN32
  18. #include <winsock.h> /* for struct timeval */
  19. #endif
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /* timezone */
  24. #define DST_NONE 0 /* not on dst */
  25. #define DST_USA 1 /* USA style dst */
  26. #define DST_AUST 2 /* Australian style dst */
  27. #define DST_WET 3 /* Western European dst */
  28. #define DST_MET 4 /* Middle European dst */
  29. #define DST_EET 5 /* Eastern European dst */
  30. #define DST_CAN 6 /* Canada */
  31. #define DST_GB 7 /* Great Britain and Eire */
  32. #define DST_RUM 8 /* Rumania */
  33. #define DST_TUR 9 /* Turkey */
  34. #define DST_AUSTALT 10 /* Australian style with shift in 1986 */
  35. struct timezone
  36. {
  37. int tz_minuteswest; /* minutes west of Greenwich */
  38. int tz_dsttime; /* type of dst correction */
  39. };
  40. #if !defined(_TIMEVAL_DEFINED) && !defined(_WIN32)
  41. #define _TIMEVAL_DEFINED
  42. struct timeval
  43. {
  44. time_t tv_sec; /* seconds */
  45. suseconds_t tv_usec; /* and microseconds */
  46. };
  47. #endif
  48. #if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && \
  49. !(defined(__ICCARM__) && (__VER__ >= 8010001)) && \
  50. !defined(_WIN32)
  51. struct timespec
  52. {
  53. time_t tv_sec; /* seconds */
  54. long tv_nsec; /* and nanoseconds */
  55. };
  56. #endif
  57. int stime(const time_t *t);
  58. time_t timegm(struct tm * const t);
  59. int gettimeofday(struct timeval *tv, struct timezone *tz);
  60. int settimeofday(const struct timeval *tv, const struct timezone *tz);
  61. #if defined(__ARMCC_VERSION) || defined (__ICCARM__)
  62. struct tm *gmtime_r(const time_t *timep, struct tm *r);
  63. #elif defined(_WIN32)
  64. struct tm* gmtime_r(const time_t* timep, struct tm* r);
  65. struct tm* gmtime(const time_t* t);
  66. struct tm* localtime_r(const time_t* t, struct tm* r);
  67. struct tm* localtime(const time_t* t);
  68. time_t mktime(struct tm* const t);
  69. char* asctime_r(const struct tm* t, char* buf);
  70. char* ctime_r(const time_t* tim_p, char* result);
  71. char* ctime(const time_t* tim_p);
  72. time_t time(time_t* t);
  73. #endif
  74. #ifdef RT_USING_POSIX_DELAY
  75. int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
  76. #endif /* RT_USING_POSIX_DELAY */
  77. #ifdef RT_USING_POSIX_CLOCK
  78. /* POSIX clock and timer */
  79. #define MILLISECOND_PER_SECOND 1000UL
  80. #define MICROSECOND_PER_SECOND 1000000UL
  81. #define NANOSECOND_PER_SECOND 1000000000UL
  82. #define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
  83. #define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
  84. #define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
  85. #ifndef CLOCK_REALTIME
  86. #define CLOCK_REALTIME 1
  87. #endif
  88. #define CLOCK_CPUTIME_ID 2
  89. #ifndef CLOCK_PROCESS_CPUTIME_ID
  90. #define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
  91. #endif
  92. #ifndef CLOCK_THREAD_CPUTIME_ID
  93. #define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
  94. #endif
  95. #ifndef CLOCK_MONOTONIC
  96. #define CLOCK_MONOTONIC 4
  97. #endif
  98. int clock_getres (clockid_t clockid, struct timespec *res);
  99. int clock_gettime (clockid_t clockid, struct timespec *tp);
  100. int clock_settime (clockid_t clockid, const struct timespec *tp);
  101. int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, struct timespec *rmtp);
  102. int rt_timespec_to_tick(const struct timespec *time);
  103. #endif /* RT_USING_POSIX_CLOCK */
  104. /* timezone */
  105. void tz_set(int8_t tz);
  106. int8_t tz_get(void);
  107. int8_t tz_is_dst(void);
  108. #ifdef __cplusplus
  109. }
  110. #endif
  111. #endif /* _SYS_TIME_H_ */