time.h 3.1 KB

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