time.h 2.3 KB

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