time.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. {
  47. time_t tv_sec; /* seconds */
  48. suseconds_t tv_usec; /* and microseconds */
  49. };
  50. #endif
  51. #endif /* _TIMEVAL_DEFINED */
  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. #if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !(defined(__ICCARM__) && (__VER__ >= 8010001)) && !defined(_WIN32)
  62. struct timespec {
  63. time_t tv_sec; /* seconds */
  64. long tv_nsec; /* and nanoseconds */
  65. };
  66. #endif
  67. /* POSIX clock and timer */
  68. #define MILLISECOND_PER_SECOND 1000UL
  69. #define MICROSECOND_PER_SECOND 1000000UL
  70. #define NANOSECOND_PER_SECOND 1000000000UL
  71. #define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
  72. #define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
  73. #define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
  74. #ifndef CLOCK_REALTIME
  75. #define CLOCK_REALTIME 1
  76. #endif
  77. #define CLOCK_CPUTIME_ID 2
  78. #ifndef CLOCK_PROCESS_CPUTIME_ID
  79. #define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
  80. #endif
  81. #ifndef CLOCK_THREAD_CPUTIME_ID
  82. #define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
  83. #endif
  84. #ifndef CLOCK_MONOTONIC
  85. #define CLOCK_MONOTONIC 4
  86. #endif
  87. int clock_getres (clockid_t clockid, struct timespec *res);
  88. int clock_gettime (clockid_t clockid, struct timespec *tp);
  89. int clock_settime (clockid_t clockid, const struct timespec *tp);
  90. int rt_timespec_to_tick(const struct timespec *time);
  91. #endif /* RT_USING_POSIX */
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif /* _SYS_TIME_H_ */