time.h 2.2 KB

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