Skip to content

Commit 4f3448c

Browse files
CopilotBernardXiong
andcommitted
[clock_time] Remove compatibility layers and refactor to direct implementation
- Removed cputime_compat.c and ktime_compat.c - Created clock_time_cputime.c for CPU time APIs (clock_cpu_*, rt_cputime_*) - Created clock_time_boottime.c for boottime APIs (rt_boottime_*) - Created stub cputime.h header for BSP compatibility - Removed all compatibility type definitions from clock_time.h - Removed compatibility Kconfig options - Updated SConscript to build new files - Replaced all rt_ktime_hrtimer_* calls with rt_clock_hrtimer_* in ctime.c - Replaced all rt_ktime_* functions with rt_clock_* equivalents - Simplified nanosleep() to use rt_clock_ndelay() directly Co-authored-by: BernardXiong <[email protected]>
1 parent 390112d commit 4f3448c

File tree

9 files changed

+191
-423
lines changed

9 files changed

+191
-423
lines changed

components/drivers/clock_time/Kconfig

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,6 @@ menuconfig RT_USING_CLOCK_TIME
1111
- High-resolution timers (hrtimer)
1212
- POSIX clock support
1313
- Boottime tracking
14+
- CPU time APIs (clock_cpu_*, rt_cputime_*)
15+
- Boottime APIs (rt_boottime_*)
1416

15-
if RT_USING_CLOCK_TIME
16-
config RT_CLOCK_TIME_COMPAT_KTIME
17-
bool "Enable compatibility layer for ktime APIs"
18-
default y
19-
help
20-
Provides backward compatibility wrappers for legacy ktime APIs.
21-
Enable this if existing code uses rt_ktime_* functions.
22-
23-
config RT_CLOCK_TIME_COMPAT_CPUTIME
24-
bool "Enable compatibility layer for cputime APIs"
25-
default y
26-
help
27-
Provides backward compatibility wrappers for legacy cputime APIs.
28-
Enable this if existing code uses clock_cpu_* or rt_cputimer_* functions.
29-
30-
config RT_CLOCK_TIME_COMPAT_HWTIMER
31-
bool "Enable compatibility layer for hwtimer device APIs"
32-
default y
33-
help
34-
Provides backward compatibility for legacy hwtimer device APIs.
35-
Enable this if BSP drivers use rt_device_hwtimer_* functions.
36-
endif

components/drivers/clock_time/SConscript

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ src = Split('''
66
src/clock_time.c
77
src/hrtimer.c
88
src/clock_time_tick.c
9+
src/clock_time_cputime.c
10+
src/clock_time_boottime.c
911
''')
1012

11-
if GetDepend('RT_CLOCK_TIME_COMPAT_KTIME'):
12-
src += ['src/ktime_compat.c']
13-
14-
if GetDepend('RT_CLOCK_TIME_COMPAT_CPUTIME'):
15-
src += ['src/cputime_compat.c']
16-
1713
CPPPATH = [cwd + '/include', cwd + '/../include']
1814

1915
LOCAL_CCFLAGS = ''
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2006-2024, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2024-12-04 RT-Thread Boottime implementation using clock_time
9+
*/
10+
11+
#include <rtdevice.h>
12+
#include <sys/time.h>
13+
14+
/**
15+
* @brief Get boottime in microsecond precision
16+
*
17+
* @param tv Output timeval structure
18+
* @return RT_EOK on success
19+
*/
20+
rt_err_t rt_boottime_get_us(struct timeval *tv)
21+
{
22+
return rt_clock_time_boottime_us(tv);
23+
}
24+
25+
/**
26+
* @brief Get boottime in second precision
27+
*
28+
* @param t Output time_t value
29+
* @return RT_EOK on success
30+
*/
31+
rt_err_t rt_boottime_get_s(time_t *t)
32+
{
33+
return rt_clock_time_boottime_s(t);
34+
}
35+
36+
/**
37+
* @brief Get boottime in nanosecond precision
38+
*
39+
* @param ts Output timespec structure
40+
* @return RT_EOK on success
41+
*/
42+
rt_err_t rt_boottime_get_ns(struct timespec *ts)
43+
{
44+
return rt_clock_time_boottime_ns(ts);
45+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 2006-2024, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2024-12-04 RT-Thread CPU time and legacy cputime API implementation
9+
*/
10+
11+
#include <rtdevice.h>
12+
#include <rthw.h>
13+
#include <sys/errno.h>
14+
15+
/**
16+
* @brief Get CPU time resolution
17+
*
18+
* @return Resolution in nanoseconds * 1000000
19+
*/
20+
uint64_t clock_cpu_getres(void)
21+
{
22+
return rt_clock_time_getres();
23+
}
24+
25+
/**
26+
* @brief Get current CPU time counter value
27+
*
28+
* @return Current counter value
29+
*/
30+
uint64_t clock_cpu_gettime(void)
31+
{
32+
return rt_clock_time_getcnt();
33+
}
34+
35+
/**
36+
* @brief Convert CPU ticks to microseconds
37+
*
38+
* @param cpu_tick CPU tick count
39+
* @return Microseconds
40+
*/
41+
uint64_t clock_cpu_microsecond(uint64_t cpu_tick)
42+
{
43+
return rt_clock_time_cnt_to_us(cpu_tick);
44+
}
45+
46+
/**
47+
* @brief Convert CPU ticks to milliseconds
48+
*
49+
* @param cpu_tick CPU tick count
50+
* @return Milliseconds
51+
*/
52+
uint64_t clock_cpu_millisecond(uint64_t cpu_tick)
53+
{
54+
return rt_clock_time_cnt_to_ms(cpu_tick);
55+
}
56+
57+
/**
58+
* @brief High-precision nanosecond delay
59+
*
60+
* @param ns Nanoseconds to delay
61+
* @return RT_EOK on success
62+
*/
63+
rt_err_t rt_cputime_ndelay(rt_uint64_t ns)
64+
{
65+
return rt_clock_ndelay((unsigned long)ns);
66+
}
67+
68+
/**
69+
* @brief High-precision microsecond delay
70+
*
71+
* @param us Microseconds to delay
72+
* @return RT_EOK on success
73+
*/
74+
rt_err_t rt_cputime_udelay(rt_uint64_t us)
75+
{
76+
return rt_clock_udelay((unsigned long)us);
77+
}
78+
79+
/**
80+
* @brief High-precision millisecond delay
81+
*
82+
* @param ms Milliseconds to delay
83+
* @return RT_EOK on success
84+
*/
85+
rt_err_t rt_cputime_mdelay(rt_uint64_t ms)
86+
{
87+
return rt_clock_mdelay((unsigned long)ms);
88+
}

components/drivers/clock_time/src/cputime_compat.c

Lines changed: 0 additions & 146 deletions
This file was deleted.

0 commit comments

Comments
 (0)