time.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #ifndef _TIMEVAL_DEFINED
  19. #define _TIMEVAL_DEFINED
  20. /*
  21. * Structure returned by gettimeofday(2) system call,
  22. * and used in other calls.
  23. */
  24. #if !(defined(_WIN32))
  25. struct timeval {
  26. long tv_sec; /* seconds */
  27. long tv_usec; /* and microseconds */
  28. };
  29. #endif
  30. #endif /* _TIMEVAL_DEFINED */
  31. #if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !(defined(__ICCARM__) && (__VER__ >= 8010001)) && !defined(_WIN32)
  32. struct timespec {
  33. time_t tv_sec; /* seconds */
  34. long tv_nsec; /* and nanoseconds */
  35. };
  36. #endif
  37. struct timezone {
  38. int tz_minuteswest; /* minutes west of Greenwich */
  39. int tz_dsttime; /* type of dst correction */
  40. };
  41. int stime(const time_t *t);
  42. time_t timegm(struct tm * const t);
  43. int gettimeofday(struct timeval *tv, struct timezone *tz);
  44. int settimeofday(const struct timeval *tv, const struct timezone *tz);
  45. #if defined(__ARMCC_VERSION) || defined (__ICCARM__)
  46. struct tm *gmtime_r(const time_t *timep, struct tm *r);
  47. #endif
  48. #ifdef RT_USING_POSIX
  49. #include <sys/types.h>
  50. /* posix clock and timer */
  51. #define MILLISECOND_PER_SECOND 1000UL
  52. #define MICROSECOND_PER_SECOND 1000000UL
  53. #define NANOSECOND_PER_SECOND 1000000000UL
  54. #define MILLISECOND_PER_TICK (MILLISECOND_PER_SECOND / RT_TICK_PER_SECOND)
  55. #define MICROSECOND_PER_TICK (MICROSECOND_PER_SECOND / RT_TICK_PER_SECOND)
  56. #define NANOSECOND_PER_TICK (NANOSECOND_PER_SECOND / RT_TICK_PER_SECOND)
  57. #ifndef CLOCK_REALTIME
  58. #define CLOCK_REALTIME 1
  59. #endif
  60. #define CLOCK_CPUTIME_ID 2
  61. #ifndef CLOCK_PROCESS_CPUTIME_ID
  62. #define CLOCK_PROCESS_CPUTIME_ID CLOCK_CPUTIME_ID
  63. #endif
  64. #ifndef CLOCK_THREAD_CPUTIME_ID
  65. #define CLOCK_THREAD_CPUTIME_ID CLOCK_CPUTIME_ID
  66. #endif
  67. #ifndef CLOCK_MONOTONIC
  68. #define CLOCK_MONOTONIC 4
  69. #endif
  70. int clock_getres (clockid_t clockid, struct timespec *res);
  71. int clock_gettime (clockid_t clockid, struct timespec *tp);
  72. int clock_settime (clockid_t clockid, const struct timespec *tp);
  73. int clock_time_to_tick(const struct timespec *time);
  74. #endif /* RT_USING_POSIX */
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. #endif /* _SYS_TIME_H_ */