time.h 3.1 KB

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