time.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_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. #endif /* RT_USING_POSIX */
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif /* _SYS_TIME_H_ */