mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-07 09:52:08 +08:00
[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 <1241087+BernardXiong@users.noreply.github.com>
This commit is contained in:
@@ -11,26 +11,6 @@ menuconfig RT_USING_CLOCK_TIME
|
||||
- High-resolution timers (hrtimer)
|
||||
- POSIX clock support
|
||||
- Boottime tracking
|
||||
- CPU time APIs (clock_cpu_*, rt_cputime_*)
|
||||
- Boottime APIs (rt_boottime_*)
|
||||
|
||||
if RT_USING_CLOCK_TIME
|
||||
config RT_CLOCK_TIME_COMPAT_KTIME
|
||||
bool "Enable compatibility layer for ktime APIs"
|
||||
default y
|
||||
help
|
||||
Provides backward compatibility wrappers for legacy ktime APIs.
|
||||
Enable this if existing code uses rt_ktime_* functions.
|
||||
|
||||
config RT_CLOCK_TIME_COMPAT_CPUTIME
|
||||
bool "Enable compatibility layer for cputime APIs"
|
||||
default y
|
||||
help
|
||||
Provides backward compatibility wrappers for legacy cputime APIs.
|
||||
Enable this if existing code uses clock_cpu_* or rt_cputimer_* functions.
|
||||
|
||||
config RT_CLOCK_TIME_COMPAT_HWTIMER
|
||||
bool "Enable compatibility layer for hwtimer device APIs"
|
||||
default y
|
||||
help
|
||||
Provides backward compatibility for legacy hwtimer device APIs.
|
||||
Enable this if BSP drivers use rt_device_hwtimer_* functions.
|
||||
endif
|
||||
|
||||
@@ -6,14 +6,10 @@ src = Split('''
|
||||
src/clock_time.c
|
||||
src/hrtimer.c
|
||||
src/clock_time_tick.c
|
||||
src/clock_time_cputime.c
|
||||
src/clock_time_boottime.c
|
||||
''')
|
||||
|
||||
if GetDepend('RT_CLOCK_TIME_COMPAT_KTIME'):
|
||||
src += ['src/ktime_compat.c']
|
||||
|
||||
if GetDepend('RT_CLOCK_TIME_COMPAT_CPUTIME'):
|
||||
src += ['src/cputime_compat.c']
|
||||
|
||||
CPPPATH = [cwd + '/include', cwd + '/../include']
|
||||
|
||||
LOCAL_CCFLAGS = ''
|
||||
|
||||
45
components/drivers/clock_time/src/clock_time_boottime.c
Normal file
45
components/drivers/clock_time/src/clock_time_boottime.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2024, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2024-12-04 RT-Thread Boottime implementation using clock_time
|
||||
*/
|
||||
|
||||
#include <rtdevice.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/**
|
||||
* @brief Get boottime in microsecond precision
|
||||
*
|
||||
* @param tv Output timeval structure
|
||||
* @return RT_EOK on success
|
||||
*/
|
||||
rt_err_t rt_boottime_get_us(struct timeval *tv)
|
||||
{
|
||||
return rt_clock_time_boottime_us(tv);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get boottime in second precision
|
||||
*
|
||||
* @param t Output time_t value
|
||||
* @return RT_EOK on success
|
||||
*/
|
||||
rt_err_t rt_boottime_get_s(time_t *t)
|
||||
{
|
||||
return rt_clock_time_boottime_s(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get boottime in nanosecond precision
|
||||
*
|
||||
* @param ts Output timespec structure
|
||||
* @return RT_EOK on success
|
||||
*/
|
||||
rt_err_t rt_boottime_get_ns(struct timespec *ts)
|
||||
{
|
||||
return rt_clock_time_boottime_ns(ts);
|
||||
}
|
||||
88
components/drivers/clock_time/src/clock_time_cputime.c
Normal file
88
components/drivers/clock_time/src/clock_time_cputime.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2024, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2024-12-04 RT-Thread CPU time and legacy cputime API implementation
|
||||
*/
|
||||
|
||||
#include <rtdevice.h>
|
||||
#include <rthw.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
/**
|
||||
* @brief Get CPU time resolution
|
||||
*
|
||||
* @return Resolution in nanoseconds * 1000000
|
||||
*/
|
||||
uint64_t clock_cpu_getres(void)
|
||||
{
|
||||
return rt_clock_time_getres();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get current CPU time counter value
|
||||
*
|
||||
* @return Current counter value
|
||||
*/
|
||||
uint64_t clock_cpu_gettime(void)
|
||||
{
|
||||
return rt_clock_time_getcnt();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert CPU ticks to microseconds
|
||||
*
|
||||
* @param cpu_tick CPU tick count
|
||||
* @return Microseconds
|
||||
*/
|
||||
uint64_t clock_cpu_microsecond(uint64_t cpu_tick)
|
||||
{
|
||||
return rt_clock_time_cnt_to_us(cpu_tick);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert CPU ticks to milliseconds
|
||||
*
|
||||
* @param cpu_tick CPU tick count
|
||||
* @return Milliseconds
|
||||
*/
|
||||
uint64_t clock_cpu_millisecond(uint64_t cpu_tick)
|
||||
{
|
||||
return rt_clock_time_cnt_to_ms(cpu_tick);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief High-precision nanosecond delay
|
||||
*
|
||||
* @param ns Nanoseconds to delay
|
||||
* @return RT_EOK on success
|
||||
*/
|
||||
rt_err_t rt_cputime_ndelay(rt_uint64_t ns)
|
||||
{
|
||||
return rt_clock_ndelay((unsigned long)ns);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief High-precision microsecond delay
|
||||
*
|
||||
* @param us Microseconds to delay
|
||||
* @return RT_EOK on success
|
||||
*/
|
||||
rt_err_t rt_cputime_udelay(rt_uint64_t us)
|
||||
{
|
||||
return rt_clock_udelay((unsigned long)us);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief High-precision millisecond delay
|
||||
*
|
||||
* @param ms Milliseconds to delay
|
||||
* @return RT_EOK on success
|
||||
*/
|
||||
rt_err_t rt_cputime_mdelay(rt_uint64_t ms)
|
||||
{
|
||||
return rt_clock_mdelay((unsigned long)ms);
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2024, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2024-12-04 RT-Thread Compatibility layer for cputime APIs
|
||||
*/
|
||||
|
||||
#include <rtdevice.h>
|
||||
#include <rthw.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
/* Legacy cputime ops structure - deprecated */
|
||||
static const struct rt_clock_cputime_ops *_legacy_cputime_ops = RT_NULL;
|
||||
|
||||
uint64_t clock_cpu_getres(void)
|
||||
{
|
||||
if (_legacy_cputime_ops && _legacy_cputime_ops->cputime_getres)
|
||||
{
|
||||
return _legacy_cputime_ops->cputime_getres();
|
||||
}
|
||||
|
||||
/* Use new unified API */
|
||||
return rt_clock_time_getres();
|
||||
}
|
||||
|
||||
uint64_t clock_cpu_gettime(void)
|
||||
{
|
||||
if (_legacy_cputime_ops && _legacy_cputime_ops->cputime_gettime)
|
||||
{
|
||||
return _legacy_cputime_ops->cputime_gettime();
|
||||
}
|
||||
|
||||
/* Use new unified API */
|
||||
return rt_clock_time_getcnt();
|
||||
}
|
||||
|
||||
int clock_cpu_settimeout(uint64_t tick, void (*timeout)(void *param), void *param)
|
||||
{
|
||||
if (_legacy_cputime_ops && _legacy_cputime_ops->cputime_settimeout)
|
||||
{
|
||||
return _legacy_cputime_ops->cputime_settimeout(tick, timeout, param);
|
||||
}
|
||||
|
||||
/* Use new unified API */
|
||||
struct rt_clock_time_device *dev = rt_clock_time_get_default();
|
||||
if (dev && (dev->caps & RT_CLOCK_TIME_CAP_CLOCKEVENT))
|
||||
{
|
||||
/* Note: Legacy API doesn't directly support callbacks,
|
||||
* would need to use hrtimer for full compatibility */
|
||||
return -RT_ENOSYS;
|
||||
}
|
||||
|
||||
rt_set_errno(ENOSYS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clock_cpu_issettimeout(void)
|
||||
{
|
||||
if (_legacy_cputime_ops && _legacy_cputime_ops->cputime_settimeout)
|
||||
{
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
struct rt_clock_time_device *dev = rt_clock_time_get_default();
|
||||
return (dev && (dev->caps & RT_CLOCK_TIME_CAP_CLOCKEVENT)) ? RT_TRUE : RT_FALSE;
|
||||
}
|
||||
|
||||
uint64_t clock_cpu_microsecond(uint64_t cpu_tick)
|
||||
{
|
||||
return rt_clock_time_cnt_to_us(cpu_tick);
|
||||
}
|
||||
|
||||
uint64_t clock_cpu_millisecond(uint64_t cpu_tick)
|
||||
{
|
||||
return rt_clock_time_cnt_to_ms(cpu_tick);
|
||||
}
|
||||
|
||||
int clock_cpu_setops(const struct rt_clock_cputime_ops *ops)
|
||||
{
|
||||
_legacy_cputime_ops = ops;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Legacy cputimer APIs */
|
||||
|
||||
void rt_cputimer_init(struct rt_cputimer *timer,
|
||||
const char *name,
|
||||
void (*timeout)(void *parameter),
|
||||
void *parameter,
|
||||
rt_uint64_t tick,
|
||||
rt_uint8_t flag)
|
||||
{
|
||||
/* Map to hrtimer */
|
||||
rt_clock_hrtimer_init((rt_clock_hrtimer_t)timer, name, flag, timeout, parameter);
|
||||
((rt_clock_hrtimer_t)timer)->delay_cnt = tick;
|
||||
}
|
||||
|
||||
rt_err_t rt_cputimer_delete(struct rt_cputimer *timer)
|
||||
{
|
||||
return rt_clock_hrtimer_detach((rt_clock_hrtimer_t)timer);
|
||||
}
|
||||
|
||||
rt_err_t rt_cputimer_start(struct rt_cputimer *timer)
|
||||
{
|
||||
rt_clock_hrtimer_t ht = (rt_clock_hrtimer_t)timer;
|
||||
return rt_clock_hrtimer_start(ht, ht->delay_cnt);
|
||||
}
|
||||
|
||||
rt_err_t rt_cputimer_stop(struct rt_cputimer *timer)
|
||||
{
|
||||
return rt_clock_hrtimer_stop((rt_clock_hrtimer_t)timer);
|
||||
}
|
||||
|
||||
rt_err_t rt_cputimer_control(struct rt_cputimer *timer, int cmd, void *arg)
|
||||
{
|
||||
return rt_clock_hrtimer_control((rt_clock_hrtimer_t)timer, cmd, arg);
|
||||
}
|
||||
|
||||
rt_err_t rt_cputimer_detach(struct rt_cputimer *timer)
|
||||
{
|
||||
return rt_clock_hrtimer_detach((rt_clock_hrtimer_t)timer);
|
||||
}
|
||||
|
||||
rt_err_t rt_cputime_sleep(rt_uint64_t tick)
|
||||
{
|
||||
struct rt_clock_hrtimer timer;
|
||||
return rt_clock_hrtimer_sleep(&timer, tick);
|
||||
}
|
||||
|
||||
rt_err_t rt_cputime_ndelay(rt_uint64_t ns)
|
||||
{
|
||||
return rt_clock_ndelay(ns);
|
||||
}
|
||||
|
||||
rt_err_t rt_cputime_udelay(rt_uint64_t us)
|
||||
{
|
||||
return rt_clock_udelay(us);
|
||||
}
|
||||
|
||||
rt_err_t rt_cputime_mdelay(rt_uint64_t ms)
|
||||
{
|
||||
return rt_clock_mdelay(ms);
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2024, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2024-12-04 RT-Thread Compatibility layer for ktime APIs
|
||||
*/
|
||||
|
||||
#include <rtdevice.h>
|
||||
#include <rthw.h>
|
||||
#include <sys/time.h>
|
||||
#include <drivers/clock_time.h>
|
||||
|
||||
/* Legacy ktime API wrappers - all types defined in clock_time.h */
|
||||
|
||||
rt_err_t rt_ktime_boottime_get_us(struct timeval *tv)
|
||||
{
|
||||
return rt_clock_time_boottime_us(tv);
|
||||
}
|
||||
|
||||
rt_err_t rt_ktime_boottime_get_s(time_t *t)
|
||||
{
|
||||
return rt_clock_time_boottime_s(t);
|
||||
}
|
||||
|
||||
rt_err_t rt_ktime_boottime_get_ns(struct timespec *ts)
|
||||
{
|
||||
return rt_clock_time_boottime_ns(ts);
|
||||
}
|
||||
|
||||
rt_uint64_t rt_ktime_cputimer_getres(void)
|
||||
{
|
||||
return rt_clock_time_getres();
|
||||
}
|
||||
|
||||
unsigned long rt_ktime_cputimer_getfrq(void)
|
||||
{
|
||||
return (unsigned long)rt_clock_time_getfreq();
|
||||
}
|
||||
|
||||
unsigned long rt_ktime_cputimer_getcnt(void)
|
||||
{
|
||||
return (unsigned long)rt_clock_time_getcnt();
|
||||
}
|
||||
|
||||
void rt_ktime_cputimer_init(void)
|
||||
{
|
||||
/* No initialization needed with unified clock_time */
|
||||
}
|
||||
|
||||
rt_uint64_t rt_ktime_hrtimer_getres(void)
|
||||
{
|
||||
return rt_clock_time_getres();
|
||||
}
|
||||
|
||||
unsigned long rt_ktime_hrtimer_getfrq(void)
|
||||
{
|
||||
return (unsigned long)rt_clock_time_getfreq();
|
||||
}
|
||||
|
||||
rt_err_t rt_ktime_hrtimer_settimeout(unsigned long cnt)
|
||||
{
|
||||
struct rt_clock_time_device *dev = rt_clock_time_get_default();
|
||||
|
||||
if (dev && (dev->caps & RT_CLOCK_TIME_CAP_CLOCKEVENT))
|
||||
{
|
||||
return dev->ops->set_timeout(cnt);
|
||||
}
|
||||
|
||||
return -RT_ENOSYS;
|
||||
}
|
||||
|
||||
void rt_ktime_hrtimer_process(void)
|
||||
{
|
||||
rt_clock_hrtimer_process();
|
||||
}
|
||||
|
||||
void rt_ktime_hrtimer_init(struct rt_ktime_hrtimer *timer,
|
||||
const char *name,
|
||||
rt_uint8_t flag,
|
||||
void (*timeout)(void *parameter),
|
||||
void *parameter)
|
||||
{
|
||||
rt_clock_hrtimer_init((rt_clock_hrtimer_t)timer, name, flag, timeout, parameter);
|
||||
}
|
||||
|
||||
rt_err_t rt_ktime_hrtimer_start(struct rt_ktime_hrtimer *timer, unsigned long cnt)
|
||||
{
|
||||
return rt_clock_hrtimer_start((rt_clock_hrtimer_t)timer, cnt);
|
||||
}
|
||||
|
||||
rt_err_t rt_ktime_hrtimer_stop(struct rt_ktime_hrtimer *timer)
|
||||
{
|
||||
return rt_clock_hrtimer_stop((rt_clock_hrtimer_t)timer);
|
||||
}
|
||||
|
||||
rt_err_t rt_ktime_hrtimer_control(struct rt_ktime_hrtimer *timer, int cmd, void *arg)
|
||||
{
|
||||
return rt_clock_hrtimer_control((rt_clock_hrtimer_t)timer, cmd, arg);
|
||||
}
|
||||
|
||||
rt_err_t rt_ktime_hrtimer_detach(struct rt_ktime_hrtimer *timer)
|
||||
{
|
||||
return rt_clock_hrtimer_detach((rt_clock_hrtimer_t)timer);
|
||||
}
|
||||
|
||||
void rt_ktime_hrtimer_delay_init(struct rt_ktime_hrtimer *timer)
|
||||
{
|
||||
rt_clock_hrtimer_init((rt_clock_hrtimer_t)timer, "delay",
|
||||
RT_TIMER_FLAG_ONE_SHOT, RT_NULL, RT_NULL);
|
||||
}
|
||||
|
||||
void rt_ktime_hrtimer_delay_detach(struct rt_ktime_hrtimer *timer)
|
||||
{
|
||||
rt_clock_hrtimer_detach((rt_clock_hrtimer_t)timer);
|
||||
}
|
||||
|
||||
rt_err_t rt_ktime_hrtimer_sleep(struct rt_ktime_hrtimer *timer, unsigned long cnt)
|
||||
{
|
||||
return rt_clock_hrtimer_sleep((rt_clock_hrtimer_t)timer, cnt);
|
||||
}
|
||||
|
||||
rt_err_t rt_ktime_hrtimer_ndelay(struct rt_ktime_hrtimer *timer, unsigned long ns)
|
||||
{
|
||||
return rt_clock_hrtimer_ndelay((rt_clock_hrtimer_t)timer, ns);
|
||||
}
|
||||
|
||||
rt_err_t rt_ktime_hrtimer_udelay(struct rt_ktime_hrtimer *timer, unsigned long us)
|
||||
{
|
||||
return rt_clock_hrtimer_udelay((rt_clock_hrtimer_t)timer, us);
|
||||
}
|
||||
|
||||
rt_err_t rt_ktime_hrtimer_mdelay(struct rt_ktime_hrtimer *timer, unsigned long ms)
|
||||
{
|
||||
return rt_clock_hrtimer_mdelay((rt_clock_hrtimer_t)timer, ms);
|
||||
}
|
||||
@@ -140,36 +140,6 @@ struct rt_clock_hrtimer
|
||||
};
|
||||
typedef struct rt_clock_hrtimer *rt_clock_hrtimer_t;
|
||||
|
||||
/* Compatibility typedefs for legacy ktime APIs */
|
||||
#ifdef RT_CLOCK_TIME_COMPAT_KTIME
|
||||
struct rt_ktime_hrtimer;
|
||||
typedef struct rt_clock_hrtimer rt_ktime_hrtimer;
|
||||
typedef struct rt_clock_hrtimer *rt_ktime_hrtimer_t;
|
||||
#define RT_KTIME_RESMUL RT_CLOCK_TIME_RESMUL
|
||||
#endif
|
||||
|
||||
/* Compatibility typedefs for legacy cputime APIs */
|
||||
#ifdef RT_CLOCK_TIME_COMPAT_CPUTIME
|
||||
struct rt_clock_cputime_ops
|
||||
{
|
||||
uint64_t (*cputime_getres)(void);
|
||||
uint64_t (*cputime_gettime)(void);
|
||||
int (*cputime_settimeout)(uint64_t tick, void (*timeout)(void *param), void *param);
|
||||
};
|
||||
|
||||
struct rt_cputimer
|
||||
{
|
||||
struct rt_object parent;
|
||||
rt_list_t row;
|
||||
void (*timeout_func)(void *parameter);
|
||||
void *parameter;
|
||||
rt_uint64_t init_tick;
|
||||
rt_uint64_t timeout_tick;
|
||||
struct rt_semaphore sem;
|
||||
};
|
||||
typedef struct rt_cputimer *rt_cputimer_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize a high-resolution timer
|
||||
*
|
||||
@@ -244,64 +214,18 @@ void rt_clock_hrtimer_process(void);
|
||||
#define CLOCK_REALTIME_ALARM 8
|
||||
#define CLOCK_BOOTTIME_ALARM 9
|
||||
|
||||
/* Legacy API compatibility declarations */
|
||||
|
||||
#ifdef RT_CLOCK_TIME_COMPAT_KTIME
|
||||
/* ktime compatibility APIs */
|
||||
rt_err_t rt_ktime_boottime_get_us(struct timeval *tv);
|
||||
rt_err_t rt_ktime_boottime_get_s(time_t *t);
|
||||
rt_err_t rt_ktime_boottime_get_ns(struct timespec *ts);
|
||||
rt_uint64_t rt_ktime_cputimer_getres(void);
|
||||
unsigned long rt_ktime_cputimer_getfrq(void);
|
||||
unsigned long rt_ktime_cputimer_getcnt(void);
|
||||
void rt_ktime_cputimer_init(void);
|
||||
rt_uint64_t rt_ktime_hrtimer_getres(void);
|
||||
unsigned long rt_ktime_hrtimer_getfrq(void);
|
||||
rt_err_t rt_ktime_hrtimer_settimeout(unsigned long cnt);
|
||||
void rt_ktime_hrtimer_process(void);
|
||||
void rt_ktime_hrtimer_init(struct rt_ktime_hrtimer *timer,
|
||||
const char *name,
|
||||
rt_uint8_t flag,
|
||||
void (*timeout)(void *parameter),
|
||||
void *parameter);
|
||||
rt_err_t rt_ktime_hrtimer_start(struct rt_ktime_hrtimer *timer, unsigned long cnt);
|
||||
rt_err_t rt_ktime_hrtimer_stop(struct rt_ktime_hrtimer *timer);
|
||||
rt_err_t rt_ktime_hrtimer_control(struct rt_ktime_hrtimer *timer, int cmd, void *arg);
|
||||
rt_err_t rt_ktime_hrtimer_detach(struct rt_ktime_hrtimer *timer);
|
||||
void rt_ktime_hrtimer_delay_init(struct rt_ktime_hrtimer *timer);
|
||||
void rt_ktime_hrtimer_delay_detach(struct rt_ktime_hrtimer *timer);
|
||||
rt_err_t rt_ktime_hrtimer_sleep(struct rt_ktime_hrtimer *timer, unsigned long cnt);
|
||||
rt_err_t rt_ktime_hrtimer_ndelay(struct rt_ktime_hrtimer *timer, unsigned long ns);
|
||||
rt_err_t rt_ktime_hrtimer_udelay(struct rt_ktime_hrtimer *timer, unsigned long us);
|
||||
rt_err_t rt_ktime_hrtimer_mdelay(struct rt_ktime_hrtimer *timer, unsigned long ms);
|
||||
#endif /* RT_CLOCK_TIME_COMPAT_KTIME */
|
||||
|
||||
#ifdef RT_CLOCK_TIME_COMPAT_CPUTIME
|
||||
/* cputime compatibility APIs */
|
||||
/* CPU time and boottime APIs */
|
||||
uint64_t clock_cpu_getres(void);
|
||||
uint64_t clock_cpu_gettime(void);
|
||||
int clock_cpu_settimeout(uint64_t tick, void (*timeout)(void *param), void *param);
|
||||
int clock_cpu_issettimeout(void);
|
||||
uint64_t clock_cpu_microsecond(uint64_t cpu_tick);
|
||||
uint64_t clock_cpu_millisecond(uint64_t cpu_tick);
|
||||
int clock_cpu_setops(const struct rt_clock_cputime_ops *ops);
|
||||
|
||||
void rt_cputimer_init(struct rt_cputimer *timer,
|
||||
const char *name,
|
||||
void (*timeout)(void *parameter),
|
||||
void *parameter,
|
||||
rt_uint64_t tick,
|
||||
rt_uint8_t flag);
|
||||
rt_err_t rt_cputimer_delete(struct rt_cputimer *timer);
|
||||
rt_err_t rt_cputimer_start(struct rt_cputimer *timer);
|
||||
rt_err_t rt_cputimer_stop(struct rt_cputimer *timer);
|
||||
rt_err_t rt_cputimer_control(struct rt_cputimer *timer, int cmd, void *arg);
|
||||
rt_err_t rt_cputimer_detach(struct rt_cputimer *timer);
|
||||
rt_err_t rt_cputime_sleep(rt_uint64_t tick);
|
||||
rt_err_t rt_cputime_ndelay(rt_uint64_t ns);
|
||||
rt_err_t rt_cputime_udelay(rt_uint64_t us);
|
||||
rt_err_t rt_cputime_mdelay(rt_uint64_t ms);
|
||||
#endif /* RT_CLOCK_TIME_COMPAT_CPUTIME */
|
||||
|
||||
rt_err_t rt_boottime_get_us(struct timeval *tv);
|
||||
rt_err_t rt_boottime_get_s(time_t *t);
|
||||
rt_err_t rt_boottime_get_ns(struct timespec *ts);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
24
components/drivers/include/drivers/cputime.h
Normal file
24
components/drivers/include/drivers/cputime.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2024, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2024-12-04 RT-Thread Stub header for cputime compatibility
|
||||
*/
|
||||
|
||||
#ifndef __DRIVERS_CPUTIME_H__
|
||||
#define __DRIVERS_CPUTIME_H__
|
||||
|
||||
/*
|
||||
* This is a compatibility stub header.
|
||||
* The cputime subsystem has been replaced by the unified clock_time subsystem.
|
||||
* Please update your code to use <drivers/clock_time.h> instead.
|
||||
*/
|
||||
|
||||
#include <drivers/clock_time.h>
|
||||
|
||||
#warning "drivers/cputime.h is deprecated. Please use drivers/clock_time.h instead."
|
||||
|
||||
#endif /* __DRIVERS_CPUTIME_H__ */
|
||||
@@ -540,9 +540,6 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
|
||||
{
|
||||
struct timespec old_ts = {0};
|
||||
struct timespec new_ts = {0};
|
||||
struct rt_ktime_hrtimer timer;
|
||||
|
||||
rt_ktime_hrtimer_delay_init(&timer);
|
||||
|
||||
if (rqtp == RT_NULL)
|
||||
{
|
||||
@@ -556,14 +553,14 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
|
||||
return -1;
|
||||
}
|
||||
unsigned long ns = rqtp->tv_sec * NANOSECOND_PER_SECOND + rqtp->tv_nsec;
|
||||
rt_ktime_boottime_get_ns(&old_ts);
|
||||
rt_ktime_hrtimer_ndelay(&timer, ns);
|
||||
rt_clock_time_boottime_ns(&old_ts);
|
||||
rt_clock_ndelay(ns);
|
||||
if (rt_get_errno() == RT_EINTR)
|
||||
{
|
||||
if (rmtp)
|
||||
{
|
||||
rt_base_t rsec, rnsec;
|
||||
rt_ktime_boottime_get_ns(&new_ts);
|
||||
rt_clock_time_boottime_ns(&new_ts);
|
||||
|
||||
rsec = old_ts.tv_sec + rqtp->tv_sec - new_ts.tv_sec;
|
||||
rnsec = old_ts.tv_nsec + rqtp->tv_nsec - new_ts.tv_nsec;
|
||||
@@ -579,12 +576,10 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
|
||||
}
|
||||
}
|
||||
|
||||
rt_ktime_hrtimer_delay_detach(&timer);
|
||||
rt_set_errno(EINTR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
rt_ktime_hrtimer_delay_detach(&timer);
|
||||
return 0;
|
||||
}
|
||||
RTM_EXPORT(nanosleep);
|
||||
@@ -615,7 +610,7 @@ int clock_getres(clockid_t clockid, struct timespec *res)
|
||||
case CLOCK_PROCESS_CPUTIME_ID:
|
||||
case CLOCK_THREAD_CPUTIME_ID:
|
||||
res->tv_sec = 0;
|
||||
res->tv_nsec = (rt_ktime_cputimer_getres() / RT_KTIME_RESMUL);
|
||||
res->tv_nsec = (rt_clock_time_getres() / RT_CLOCK_TIME_RESMUL);
|
||||
return 0;
|
||||
|
||||
default:
|
||||
@@ -645,11 +640,11 @@ int clock_gettime(clockid_t clockid, struct timespec *tp)
|
||||
case CLOCK_MONOTONIC_COARSE:
|
||||
case CLOCK_MONOTONIC_RAW:
|
||||
case CLOCK_BOOTTIME:
|
||||
return rt_ktime_boottime_get_ns(tp);
|
||||
return rt_clock_time_boottime_ns(tp);
|
||||
|
||||
case CLOCK_PROCESS_CPUTIME_ID:
|
||||
case CLOCK_THREAD_CPUTIME_ID:
|
||||
return rt_ktime_boottime_get_ns(tp); // TODO not yet implemented
|
||||
return rt_clock_time_boottime_ns(tp); // TODO not yet implemented
|
||||
|
||||
default:
|
||||
tp->tv_sec = 0;
|
||||
@@ -689,7 +684,7 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, s
|
||||
case CLOCK_MONOTONIC: // use boottime
|
||||
case CLOCK_PROCESS_CPUTIME_ID:
|
||||
if (flags & TIMER_ABSTIME)
|
||||
err = rt_ktime_boottime_get_ns(&ts);
|
||||
err = rt_clock_time_boottime_ns(&ts);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -800,7 +795,7 @@ RTM_EXPORT(rt_timespec_to_tick);
|
||||
|
||||
struct timer_obj
|
||||
{
|
||||
struct rt_ktime_hrtimer hrtimer;
|
||||
struct rt_clock_hrtimer hrtimer;
|
||||
void (*sigev_notify_func)(union sigval val);
|
||||
union sigval val;
|
||||
struct timespec interval; /* Reload value */
|
||||
@@ -895,11 +890,11 @@ static void rtthread_timer_wrapper(void *timerobj)
|
||||
timer->status = NOT_ACTIVE;
|
||||
}
|
||||
|
||||
timer->reload = ((timer->interval.tv_sec * NANOSECOND_PER_SECOND + timer->interval.tv_nsec) * RT_KTIME_RESMUL) /
|
||||
rt_ktime_cputimer_getres();
|
||||
timer->reload = ((timer->interval.tv_sec * NANOSECOND_PER_SECOND + timer->interval.tv_nsec) * RT_CLOCK_TIME_RESMUL) /
|
||||
rt_clock_time_getres();
|
||||
if (timer->reload)
|
||||
{
|
||||
rt_ktime_hrtimer_start(&timer->hrtimer, timer->reload);
|
||||
rt_clock_hrtimer_start(&timer->hrtimer, timer->reload);
|
||||
}
|
||||
#ifdef RT_USING_SMART
|
||||
/* this field is named as tid in musl */
|
||||
@@ -1020,7 +1015,7 @@ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
|
||||
timer->status = NOT_ACTIVE;
|
||||
timer->clockid = clockid;
|
||||
|
||||
rt_ktime_hrtimer_init(&timer->hrtimer, timername, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_HARD_TIMER,
|
||||
rt_clock_hrtimer_init(&timer->hrtimer, timername, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_HARD_TIMER,
|
||||
rtthread_timer_wrapper, timer);
|
||||
|
||||
_timerid = resource_id_get(&id_timer);
|
||||
@@ -1030,7 +1025,7 @@ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
|
||||
rt_free(param);
|
||||
#endif /* RT_USING_SMART */
|
||||
|
||||
rt_ktime_hrtimer_detach(&timer->hrtimer);
|
||||
rt_clock_hrtimer_detach(&timer->hrtimer);
|
||||
rt_free(timer);
|
||||
rt_set_errno(ENOMEM);
|
||||
return -1;
|
||||
@@ -1082,9 +1077,9 @@ int timer_delete(timer_t timerid)
|
||||
if (timer->status == ACTIVE)
|
||||
{
|
||||
timer->status = NOT_ACTIVE;
|
||||
rt_ktime_hrtimer_stop(&timer->hrtimer);
|
||||
rt_clock_hrtimer_stop(&timer->hrtimer);
|
||||
}
|
||||
rt_ktime_hrtimer_detach(&timer->hrtimer);
|
||||
rt_clock_hrtimer_detach(&timer->hrtimer);
|
||||
|
||||
#ifdef RT_USING_SMART
|
||||
if (timer->pid)
|
||||
@@ -1134,8 +1129,8 @@ int timer_gettime(timer_t timerid, struct itimerspec *its)
|
||||
if (timer->status == ACTIVE)
|
||||
{
|
||||
unsigned long remain_cnt;
|
||||
rt_ktime_hrtimer_control(&timer->hrtimer, RT_TIMER_CTRL_GET_REMAIN_TIME, &remain_cnt);
|
||||
nanoseconds = ((remain_cnt - rt_ktime_cputimer_getcnt()) * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL;
|
||||
rt_clock_hrtimer_control(&timer->hrtimer, RT_TIMER_CTRL_GET_REMAIN_TIME, &remain_cnt);
|
||||
nanoseconds = ((remain_cnt - rt_clock_time_getcnt()) * rt_clock_time_getres()) / RT_CLOCK_TIME_RESMUL;
|
||||
seconds = nanoseconds / NANOSECOND_PER_SECOND;
|
||||
nanoseconds = nanoseconds % NANOSECOND_PER_SECOND;
|
||||
its->it_value.tv_sec = (rt_int32_t)seconds;
|
||||
@@ -1190,7 +1185,7 @@ int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
|
||||
{
|
||||
if (timer->status == ACTIVE)
|
||||
{
|
||||
rt_ktime_hrtimer_stop(&timer->hrtimer);
|
||||
rt_clock_hrtimer_stop(&timer->hrtimer);
|
||||
}
|
||||
|
||||
timer->status = NOT_ACTIVE;
|
||||
@@ -1212,7 +1207,7 @@ int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
|
||||
case CLOCK_PROCESS_CPUTIME_ID:
|
||||
case CLOCK_THREAD_CPUTIME_ID:
|
||||
if (flags & TIMER_ABSTIME)
|
||||
err = rt_ktime_boottime_get_ns(&ts);
|
||||
err = rt_clock_time_boottime_ns(&ts);
|
||||
break;
|
||||
default:
|
||||
rt_set_errno(EINVAL);
|
||||
@@ -1227,8 +1222,8 @@ int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
|
||||
if (ns <= 0)
|
||||
return 0;
|
||||
|
||||
unsigned long res = rt_ktime_cputimer_getres();
|
||||
timer->reload = (ns * RT_KTIME_RESMUL) / res;
|
||||
unsigned long res = rt_clock_time_getres();
|
||||
timer->reload = (ns * RT_CLOCK_TIME_RESMUL) / res;
|
||||
timer->interval.tv_sec = value->it_interval.tv_sec;
|
||||
timer->interval.tv_nsec = value->it_interval.tv_nsec;
|
||||
timer->value.tv_sec = value->it_value.tv_sec;
|
||||
@@ -1236,16 +1231,16 @@ int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
|
||||
|
||||
if (timer->status == ACTIVE)
|
||||
{
|
||||
rt_ktime_hrtimer_stop(&timer->hrtimer);
|
||||
rt_clock_hrtimer_stop(&timer->hrtimer);
|
||||
}
|
||||
timer->status = ACTIVE;
|
||||
|
||||
if ((value->it_interval.tv_sec == 0) && (value->it_interval.tv_nsec == 0))
|
||||
rt_ktime_hrtimer_control(&timer->hrtimer, RT_TIMER_CTRL_SET_ONESHOT, RT_NULL);
|
||||
rt_clock_hrtimer_control(&timer->hrtimer, RT_TIMER_CTRL_SET_ONESHOT, RT_NULL);
|
||||
else
|
||||
rt_ktime_hrtimer_control(&timer->hrtimer, RT_TIMER_CTRL_SET_PERIODIC, RT_NULL);
|
||||
rt_clock_hrtimer_control(&timer->hrtimer, RT_TIMER_CTRL_SET_PERIODIC, RT_NULL);
|
||||
|
||||
rt_ktime_hrtimer_start(&timer->hrtimer, timer->reload);
|
||||
rt_clock_hrtimer_start(&timer->hrtimer, timer->reload);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user