xref: /DragonOS/kernel/src/common/time.h (revision be63f3b2b6b472daa3ee17180aa607409cb9d182)
1 #pragma once
2 
3 #include "stddef.h"
4 
5 // 操作系统定义时间以ns为单位
6 #define CLOCKS_PER_SEC 1000000
7 
8 struct tm
9 {
10     int tm_sec;   /* Seconds.	[0-60] (1 leap second) */
11     int tm_min;   /* Minutes.	[0-59] */
12     int tm_hour;  /* Hours.	[0-23] */
13     int tm_mday;  /* Day.		[1-31] */
14     int tm_mon;   /* Month.	[0-11] */
15     int tm_year;  /* Year	- 1900.  */
16     int tm_wday;  /* Day of week.	[0-6] */
17     int tm_yday;  /* Days in year.[0-365]	*/
18     int tm_isdst; /* DST.		[-1/0/1]*/
19 
20     long int __tm_gmtoff;  /* Seconds east of UTC.  */
21     const char *__tm_zone; /* Timezone abbreviation.  */
22 };
23 
24 struct timespec
25 {
26     int64_t tv_sec;  // 秒
27     int64_t tv_nsec; // 纳秒
28 };
29 
30 /**
31  * @brief 休眠指定时间
32  *
33  * @param rqtp 指定休眠的时间
34  * @param rmtp 返回的剩余休眠时间
35  * @return int
36  */
37 extern int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
38 
39 /**
40  * @brief 睡眠指定时间
41  *
42  * @param usec 微秒
43  * @return int
44  */
45 extern int usleep(useconds_t usec);
46 
47 /**
48  * @brief 获取当前的CPU时间
49  *
50  * @return uint64_t timer_jiffies
51  */
52 extern uint64_t rs_clock();