-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathboottime.c
More file actions
49 lines (36 loc) · 1.15 KB
/
boottime.c
File metadata and controls
49 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-07-10 xqyjlj The first version.
*/
#include "ktime.h"
rt_weak rt_err_t rt_ktime_boottime_get_us(struct timeval *tv)
{
RT_ASSERT(tv != RT_NULL);
rt_tick_t cnt = rt_ktime_cputimer_getcnt();
rt_uint32_t freq = rt_ktime_cputimer_getfrq();
tv->tv_sec = (time_t)(cnt / freq);
tv->tv_usec = rt_muldiv_u32((rt_uint32_t)(cnt % freq), MICROSECOND_PER_SECOND, freq, NULL);
return RT_EOK;
}
rt_weak rt_err_t rt_ktime_boottime_get_s(time_t *t)
{
RT_ASSERT(t != RT_NULL);
rt_tick_t cnt = rt_ktime_cputimer_getcnt();
rt_uint32_t freq = rt_ktime_cputimer_getfrq();
*t = (time_t)(cnt / freq);
return RT_EOK;
}
rt_weak rt_err_t rt_ktime_boottime_get_ns(struct timespec *ts)
{
RT_ASSERT(ts != RT_NULL);
rt_tick_t cnt = rt_ktime_cputimer_getcnt();
rt_uint32_t freq = rt_ktime_cputimer_getfrq();
ts->tv_sec = (time_t)(cnt / freq);
ts->tv_nsec = rt_muldiv_u32((rt_uint32_t)(cnt % freq), NANOSECOND_PER_SECOND, freq, NULL);
return RT_EOK;
}