mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-02 14:23:19 +08:00
Remove old hwtimer/ktime/cputime subsystems and fix formatting
Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com>
This commit is contained in:
co-authored by
BernardXiong
parent
9a3daf23ac
commit
e9f911cbd4
@@ -5,7 +5,6 @@ rsource "ipc/Kconfig"
|
||||
|
||||
rsource "serial/Kconfig"
|
||||
rsource "can/Kconfig"
|
||||
rsource "cputime/Kconfig"
|
||||
rsource "i2c/Kconfig"
|
||||
rsource "phy/Kconfig"
|
||||
rsource "misc/Kconfig"
|
||||
@@ -47,9 +46,7 @@ rsource "pic/Kconfig"
|
||||
rsource "pin/Kconfig"
|
||||
rsource "pinctrl/Kconfig"
|
||||
rsource "clock_time/Kconfig"
|
||||
rsource "ktime/Kconfig"
|
||||
rsource "clk/Kconfig"
|
||||
rsource "hwtimer/Kconfig"
|
||||
rsource "usb/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -12,7 +12,7 @@ if RT_USING_CLOCK_TIME
|
||||
default y
|
||||
help
|
||||
Enable high-resolution software timers built on clock_time devices.
|
||||
|
||||
|
||||
config RT_USING_CLOCK_CPUTIME
|
||||
bool "Enable CPU time APIs"
|
||||
default y
|
||||
@@ -25,26 +25,4 @@ if RT_USING_CLOCK_TIME
|
||||
help
|
||||
Enable system boottime (monotonic time since boot) APIs.
|
||||
|
||||
# Backward compatibility options
|
||||
config RT_USING_HWTIMER
|
||||
bool
|
||||
default y
|
||||
help
|
||||
Legacy option for backward compatibility with hwtimer.
|
||||
Automatically enabled when RT_USING_CLOCK_TIME is enabled.
|
||||
|
||||
config RT_USING_KTIME
|
||||
bool
|
||||
default y if RT_USING_CLOCK_HRTIMER
|
||||
help
|
||||
Legacy option for backward compatibility with ktime.
|
||||
Automatically enabled when RT_USING_CLOCK_HRTIMER is enabled.
|
||||
|
||||
config RT_USING_CPUTIME
|
||||
bool
|
||||
default y if RT_USING_CLOCK_CPUTIME
|
||||
help
|
||||
Legacy option for backward compatibility with cputime.
|
||||
Automatically enabled when RT_USING_CLOCK_CPUTIME is enabled.
|
||||
|
||||
endif
|
||||
|
||||
@@ -27,32 +27,32 @@ rt_err_t rt_clock_time_device_register(struct rt_clock_time_device *dev,
|
||||
rt_uint8_t caps)
|
||||
{
|
||||
rt_err_t result;
|
||||
|
||||
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
RT_ASSERT(name != RT_NULL);
|
||||
RT_ASSERT(dev->ops != RT_NULL);
|
||||
|
||||
|
||||
/* Initialize parent device structure */
|
||||
dev->parent.type = RT_Device_Class_Timer;
|
||||
dev->parent.rx_indicate = RT_NULL;
|
||||
dev->parent.tx_complete = RT_NULL;
|
||||
|
||||
|
||||
dev->parent.init = RT_NULL;
|
||||
dev->parent.open = RT_NULL;
|
||||
dev->parent.close = RT_NULL;
|
||||
dev->parent.read = RT_NULL;
|
||||
dev->parent.write = RT_NULL;
|
||||
dev->parent.control = RT_NULL;
|
||||
|
||||
|
||||
dev->caps = caps;
|
||||
|
||||
|
||||
/* Calculate resolution scale factor */
|
||||
if (dev->ops->get_freq)
|
||||
{
|
||||
rt_uint64_t freq = dev->ops->get_freq();
|
||||
if (freq > 0)
|
||||
{
|
||||
/* res_scale = (1e9 * RT_CLOCK_TIME_RESMUL) / freq
|
||||
/* res_scale = (1e9 * RT_CLOCK_TIME_RESMUL) / freq
|
||||
* To avoid overflow, we check if freq is very small.
|
||||
* For freq >= 1000, this calculation is safe on 64-bit.
|
||||
* For very small frequencies, limit the scale factor.
|
||||
@@ -76,7 +76,7 @@ rt_err_t rt_clock_time_device_register(struct rt_clock_time_device *dev,
|
||||
{
|
||||
dev->res_scale = RT_CLOCK_TIME_RESMUL;
|
||||
}
|
||||
|
||||
|
||||
/* Register device */
|
||||
result = rt_device_register(&dev->parent, name, RT_DEVICE_FLAG_RDWR);
|
||||
if (result != RT_EOK)
|
||||
@@ -84,16 +84,16 @@ rt_err_t rt_clock_time_device_register(struct rt_clock_time_device *dev,
|
||||
LOG_E("Failed to register clock_time device: %s", name);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Set as default if none exists */
|
||||
if (_default_device == RT_NULL)
|
||||
{
|
||||
_default_device = dev;
|
||||
LOG_D("Set %s as default clock_time device", name);
|
||||
}
|
||||
|
||||
|
||||
LOG_I("Registered clock_time device: %s (caps: 0x%02x)", name, caps);
|
||||
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
@@ -111,9 +111,9 @@ rt_clock_time_t rt_clock_time_default(void)
|
||||
rt_err_t rt_clock_time_set_default(rt_clock_time_t dev)
|
||||
{
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
|
||||
|
||||
_default_device = dev;
|
||||
LOG_D("Changed default clock_time device to: %s", dev->parent.parent.name);
|
||||
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@ static unsigned long _cnt_convert(unsigned long cnt)
|
||||
{
|
||||
unsigned long rtn = 0;
|
||||
unsigned long current_cnt = rt_clock_cputimer_getcnt();
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
* Check if target count is in the past.
|
||||
* For unsigned counters, if cnt <= current_cnt, it means the target
|
||||
* has already passed (or is exactly now).
|
||||
@@ -91,10 +91,10 @@ static unsigned long _cnt_convert(unsigned long cnt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
unsigned long count = cnt - current_cnt;
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
* Sanity check for wrap-around detection.
|
||||
* If the difference exceeds half the maximum counter value, it's likely
|
||||
* a wrap-around or invalid value. This handles both:
|
||||
@@ -108,7 +108,7 @@ static unsigned long _cnt_convert(unsigned long cnt)
|
||||
rt_uint64_t count_64 = (rt_uint64_t)count;
|
||||
rt_uint64_t res_cpu = rt_clock_cputimer_getres();
|
||||
rt_uint64_t res_hr = rt_clock_hrtimer_getres();
|
||||
|
||||
|
||||
rtn = (unsigned long)((count_64 * res_cpu) / res_hr);
|
||||
return rtn == 0 ? 1 : rtn; /* at least 1 */
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
config RT_USING_CPUTIME
|
||||
bool "Enable CPU time for high resolution clock counter (DEPRECATED - use RT_USING_CLOCK_TIME)"
|
||||
default n
|
||||
depends on !RT_USING_CLOCK_TIME
|
||||
help
|
||||
DEPRECATED: This option is maintained for backward compatibility only.
|
||||
New projects should use RT_USING_CLOCK_TIME instead.
|
||||
|
||||
When enable this option, the BSP should provide a rt_clock_cputime_ops
|
||||
for CPU time by:
|
||||
const static struct rt_clock_cputime_ops _ops = {...};
|
||||
clock_cpu_setops(&_ops);
|
||||
|
||||
Then user can use high resolution clock counter with:
|
||||
|
||||
ts1 = clock_cpu_gettime();
|
||||
ts2 = clock_cpu_gettime();
|
||||
|
||||
/* and get the ms of delta tick with API: */
|
||||
ms_tick = clock_cpu_millisecond(t2 - t1);
|
||||
us_tick = clock_cpu_microsecond(t2 - t1);
|
||||
|
||||
if RT_USING_CPUTIME
|
||||
config RT_USING_CPUTIME_CORTEXM
|
||||
bool "Support Cortex-M CPU"
|
||||
default y
|
||||
depends on ARCH_ARM_CORTEX_M0 || ARCH_ARM_CORTEX_M3 || ARCH_ARM_CORTEX_M4 || ARCH_ARM_CORTEX_M7
|
||||
select PKG_USING_PERF_COUNTER
|
||||
config RT_USING_CPUTIME_RISCV
|
||||
bool "Use rdtime instructions for CPU time"
|
||||
default y
|
||||
depends on ARCH_RISCV64
|
||||
help
|
||||
Some RISCV64 MCU Use rdtime instructions read CPU time.
|
||||
config CPUTIME_TIMER_FREQ
|
||||
int "CPUTIME timer freq"
|
||||
default 0
|
||||
endif
|
||||
@@ -1,18 +0,0 @@
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
CPPPATH = [cwd + '/../include']
|
||||
src = Split('''
|
||||
cputime.c
|
||||
cputimer.c
|
||||
''')
|
||||
|
||||
if GetDepend('RT_USING_CPUTIME_CORTEXM'):
|
||||
src += ['cputime_cortexm.c']
|
||||
|
||||
if GetDepend('RT_USING_CPUTIME_RISCV'):
|
||||
src += ['cputime_riscv.c']
|
||||
|
||||
group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_CPUTIME'], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-12-23 Bernard first version
|
||||
*/
|
||||
|
||||
#include <rtdevice.h>
|
||||
#include <rtthread.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
static const struct rt_clock_cputime_ops *_cputime_ops = RT_NULL;
|
||||
|
||||
/**
|
||||
* The clock_cpu_getres() function shall return the resolution of CPU time, the
|
||||
* number of nanosecond per tick.
|
||||
*
|
||||
* @return the number of nanosecond per tick(x (1000UL * 1000))
|
||||
*/
|
||||
uint64_t clock_cpu_getres(void)
|
||||
{
|
||||
if (_cputime_ops)
|
||||
return _cputime_ops->cputime_getres();
|
||||
|
||||
rt_set_errno(ENOSYS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The clock_cpu_gettime() function shall return the current value of cpu time tick.
|
||||
*
|
||||
* @return the cpu tick
|
||||
*/
|
||||
uint64_t clock_cpu_gettime(void)
|
||||
{
|
||||
if (_cputime_ops)
|
||||
return _cputime_ops->cputime_gettime();
|
||||
|
||||
rt_set_errno(ENOSYS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The clock_cpu_settimeout() fucntion set timeout time and timeout callback function
|
||||
* The timeout callback function will be called when the timeout time is reached
|
||||
*
|
||||
* @param tick the Timeout tick
|
||||
* @param timeout the Timeout function
|
||||
* @param parameter the Parameters of timeout function
|
||||
*
|
||||
*/
|
||||
int clock_cpu_settimeout(uint64_t tick, void (*timeout)(void *param), void *param)
|
||||
{
|
||||
if (_cputime_ops)
|
||||
return _cputime_ops->cputime_settimeout(tick, timeout, param);
|
||||
|
||||
rt_set_errno(ENOSYS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clock_cpu_issettimeout(void)
|
||||
{
|
||||
if (_cputime_ops)
|
||||
return _cputime_ops->cputime_settimeout != RT_NULL;
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* The clock_cpu_microsecond() fucntion shall return the microsecond according to
|
||||
* cpu_tick parameter.
|
||||
*
|
||||
* @param cpu_tick the cpu tick
|
||||
*
|
||||
* @return the microsecond
|
||||
*/
|
||||
uint64_t clock_cpu_microsecond(uint64_t cpu_tick)
|
||||
{
|
||||
uint64_t unit = clock_cpu_getres();
|
||||
|
||||
return (uint64_t)(((cpu_tick * unit) / (1000UL * 1000)) / 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* The clock_cpu_microsecond() fucntion shall return the millisecond according to
|
||||
* cpu_tick parameter.
|
||||
*
|
||||
* @param cpu_tick the cpu tick
|
||||
*
|
||||
* @return the millisecond
|
||||
*/
|
||||
uint64_t clock_cpu_millisecond(uint64_t cpu_tick)
|
||||
{
|
||||
uint64_t unit = clock_cpu_getres();
|
||||
|
||||
return (uint64_t)(((cpu_tick * unit) / (1000UL * 1000)) / (1000UL * 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
* The clock_cpu_seops() function shall set the ops of cpu time.
|
||||
*
|
||||
* @return always return 0.
|
||||
*/
|
||||
int clock_cpu_setops(const struct rt_clock_cputime_ops *ops)
|
||||
{
|
||||
_cputime_ops = ops;
|
||||
if (ops)
|
||||
{
|
||||
RT_ASSERT(ops->cputime_getres != RT_NULL);
|
||||
RT_ASSERT(ops->cputime_gettime != RT_NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-12-23 Bernard first version
|
||||
* 2022-06-14 Meco Man suuport pref_counter
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtdevice.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include <board.h>
|
||||
#ifdef PKG_USING_PERF_COUNTER
|
||||
#include <perf_counter.h>
|
||||
#endif
|
||||
|
||||
/* Use Cycle counter of Data Watchpoint and Trace Register for CPU time */
|
||||
static uint64_t cortexm_cputime_getres(void)
|
||||
{
|
||||
uint64_t ret = 1000UL * 1000 * 1000;
|
||||
|
||||
ret = (ret * (1000UL * 1000)) / SystemCoreClock;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint64_t cortexm_cputime_gettime(void)
|
||||
{
|
||||
#ifdef PKG_USING_PERF_COUNTER
|
||||
return get_system_ticks();
|
||||
#else
|
||||
return DWT->CYCCNT;
|
||||
#endif
|
||||
}
|
||||
|
||||
const static struct rt_clock_cputime_ops _cortexm_ops =
|
||||
{
|
||||
cortexm_cputime_getres,
|
||||
cortexm_cputime_gettime
|
||||
};
|
||||
|
||||
|
||||
int cortexm_cputime_init(void)
|
||||
{
|
||||
#ifdef PKG_USING_PERF_COUNTER
|
||||
clock_cpu_setops(&_cortexm_ops);
|
||||
#else
|
||||
/* check support bit */
|
||||
if ((DWT->CTRL & (1UL << DWT_CTRL_NOCYCCNT_Pos)) == 0)
|
||||
{
|
||||
/* enable trace*/
|
||||
CoreDebug->DEMCR |= (1UL << CoreDebug_DEMCR_TRCENA_Pos);
|
||||
|
||||
/* whether cycle counter not enabled */
|
||||
if ((DWT->CTRL & (1UL << DWT_CTRL_CYCCNTENA_Pos)) == 0)
|
||||
{
|
||||
/* enable cycle counter */
|
||||
DWT->CTRL |= (1UL << DWT_CTRL_CYCCNTENA_Pos);
|
||||
}
|
||||
|
||||
clock_cpu_setops(&_cortexm_ops);
|
||||
}
|
||||
#endif /* PKG_USING_PERF_COUNTER */
|
||||
return 0;
|
||||
}
|
||||
INIT_BOARD_EXPORT(cortexm_cputime_init);
|
||||
@@ -1,37 +0,0 @@
|
||||
#include <rthw.h>
|
||||
#include <rtdevice.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include <board.h>
|
||||
|
||||
/* Use Cycle counter of Data Watchpoint and Trace Register for CPU time */
|
||||
|
||||
static uint64_t riscv_cputime_getres(void)
|
||||
{
|
||||
uint64_t ret = 1000UL * 1000 * 1000;
|
||||
|
||||
ret = (ret * (1000UL * 1000)) / CPUTIME_TIMER_FREQ;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint64_t riscv_cputime_gettime(void)
|
||||
{
|
||||
uint64_t time_elapsed;
|
||||
__asm__ __volatile__(
|
||||
"rdtime %0"
|
||||
: "=r"(time_elapsed));
|
||||
return time_elapsed;
|
||||
}
|
||||
|
||||
const static struct rt_clock_cputime_ops _riscv_ops =
|
||||
{
|
||||
riscv_cputime_getres,
|
||||
riscv_cputime_gettime
|
||||
};
|
||||
|
||||
int riscv_cputime_init(void)
|
||||
{
|
||||
clock_cpu_setops(&_riscv_ops);
|
||||
return 0;
|
||||
}
|
||||
INIT_BOARD_EXPORT(riscv_cputime_init);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,18 +0,0 @@
|
||||
menuconfig RT_USING_HWTIMER
|
||||
bool "Using Hardware Timer device drivers (DEPRECATED - use RT_USING_CLOCK_TIME)"
|
||||
default n
|
||||
depends on !RT_USING_CLOCK_TIME
|
||||
help
|
||||
DEPRECATED: This option is maintained for backward compatibility only.
|
||||
New projects should use RT_USING_CLOCK_TIME instead.
|
||||
|
||||
config RT_HWTIMER_ARM_ARCH
|
||||
bool "ARM ARCH Timer"
|
||||
depends on RT_USING_DM
|
||||
depends on RT_USING_HWTIMER
|
||||
depends on ARCH_ARM_CORTEX_A || ARCH_ARMV8
|
||||
default n
|
||||
|
||||
if RT_USING_DM && RT_USING_HWTIMER
|
||||
osource "$(SOC_DM_HWTIMER_DIR)/Kconfig"
|
||||
endif
|
||||
@@ -1,18 +0,0 @@
|
||||
from building import *
|
||||
|
||||
group = []
|
||||
|
||||
if not GetDepend(['RT_USING_HWTIMER']):
|
||||
Return('group')
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
CPPPATH = [cwd + '/../include']
|
||||
|
||||
src = ['hwtimer.c']
|
||||
|
||||
if GetDepend(['RT_HWTIMER_ARM_ARCH']):
|
||||
src += ['hwtimer-arm_arch.c']
|
||||
|
||||
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-12-23 Bernard first version
|
||||
*/
|
||||
|
||||
#ifndef CPUTIME_H__
|
||||
#define CPUTIME_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "cputimer.h"
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
#ifdef RT_USING_CPUTIME_RISCV
|
||||
int riscv_cputime_init(void);
|
||||
#endif /* RT_USING_CPUTIME_RISCV */
|
||||
|
||||
#endif
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-02-13 zhkag first version
|
||||
*/
|
||||
|
||||
#ifndef CPUTIMER_H__
|
||||
#define CPUTIMER_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
struct rt_cputimer
|
||||
{
|
||||
struct rt_object parent; /**< inherit from rt_object */
|
||||
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;
|
||||
|
||||
rt_err_t rt_cputimer_detach(rt_cputimer_t timer);
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
void rt_cputimer_init(rt_cputimer_t timer,
|
||||
const char *name,
|
||||
void (*timeout)(void *parameter),
|
||||
void *parameter,
|
||||
rt_uint64_t tick,
|
||||
rt_uint8_t flag);
|
||||
rt_err_t rt_cputimer_delete(rt_cputimer_t timer);
|
||||
#endif
|
||||
|
||||
rt_err_t rt_cputimer_start(rt_cputimer_t timer);
|
||||
rt_err_t rt_cputimer_stop(rt_cputimer_t timer);
|
||||
rt_err_t rt_cputimer_control(rt_cputimer_t timer, int cmd, void *arg);
|
||||
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
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef __HWTIMER_H__
|
||||
#define __HWTIMER_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Timer Control Command */
|
||||
typedef enum
|
||||
{
|
||||
HWTIMER_CTRL_FREQ_SET = RT_DEVICE_CTRL_BASE(Timer) + 0x01, /* set the count frequency */
|
||||
HWTIMER_CTRL_STOP = RT_DEVICE_CTRL_BASE(Timer) + 0x02, /* stop timer */
|
||||
HWTIMER_CTRL_INFO_GET = RT_DEVICE_CTRL_BASE(Timer) + 0x03, /* get a timer feature information */
|
||||
HWTIMER_CTRL_MODE_SET = RT_DEVICE_CTRL_BASE(Timer) + 0x04 /* Setting the timing mode(oneshot/period) */
|
||||
} rt_hwtimer_ctrl_t;
|
||||
|
||||
/* Timing Mode */
|
||||
typedef enum
|
||||
{
|
||||
HWTIMER_MODE_ONESHOT = 0x01,
|
||||
HWTIMER_MODE_PERIOD
|
||||
} rt_hwtimer_mode_t;
|
||||
|
||||
/* Time Value */
|
||||
typedef struct rt_hwtimerval
|
||||
{
|
||||
rt_int32_t sec; /* second */
|
||||
rt_int32_t usec; /* microsecond */
|
||||
} rt_hwtimerval_t;
|
||||
|
||||
#define HWTIMER_CNTMODE_UP 0x01 /* increment count mode */
|
||||
#define HWTIMER_CNTMODE_DW 0x02 /* decreasing count mode */
|
||||
|
||||
struct rt_hwtimer_device;
|
||||
|
||||
struct rt_hwtimer_ops
|
||||
{
|
||||
void (*init)(struct rt_hwtimer_device *timer, rt_uint32_t state);
|
||||
rt_err_t (*start)(struct rt_hwtimer_device *timer, rt_uint32_t cnt, rt_hwtimer_mode_t mode);
|
||||
void (*stop)(struct rt_hwtimer_device *timer);
|
||||
rt_uint32_t (*count_get)(struct rt_hwtimer_device *timer);
|
||||
rt_err_t (*control)(struct rt_hwtimer_device *timer, rt_uint32_t cmd, void *args);
|
||||
};
|
||||
|
||||
/* Timer Feature Information */
|
||||
struct rt_hwtimer_info
|
||||
{
|
||||
rt_int32_t maxfreq; /* the maximum count frequency timer support */
|
||||
rt_int32_t minfreq; /* the minimum count frequency timer support */
|
||||
rt_uint32_t maxcnt; /* counter maximum value */
|
||||
rt_uint8_t cntmode; /* count mode (inc/dec) */
|
||||
};
|
||||
|
||||
typedef struct rt_hwtimer_device
|
||||
{
|
||||
struct rt_device parent;
|
||||
const struct rt_hwtimer_ops *ops;
|
||||
const struct rt_hwtimer_info *info;
|
||||
|
||||
rt_int32_t freq; /* counting frequency set by the user */
|
||||
rt_int32_t overflow; /* timer overflows */
|
||||
float period_sec;
|
||||
rt_int32_t cycles; /* how many times will generate a timeout event after overflow */
|
||||
rt_int32_t reload; /* reload cycles(using in period mode) */
|
||||
rt_hwtimer_mode_t mode; /* timing mode(oneshot/period) */
|
||||
} rt_hwtimer_t;
|
||||
|
||||
rt_err_t rt_device_hwtimer_register(rt_hwtimer_t *timer, const char *name, void *user_data);
|
||||
void rt_device_hwtimer_isr(rt_hwtimer_t *timer);
|
||||
|
||||
#ifdef RT_USING_DM
|
||||
extern void (*rt_device_hwtimer_us_delay)(rt_uint32_t us);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2025, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2025-01-01 RT-Thread Compatibility layer for legacy hwtimer API
|
||||
*
|
||||
* DEPRECATED: This header provides backward compatibility for the legacy hwtimer API.
|
||||
* New code should use the unified clock_time subsystem instead.
|
||||
* This compatibility layer will be removed in a future release.
|
||||
*/
|
||||
|
||||
#ifndef __HWTIMER_H__
|
||||
#define __HWTIMER_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* For backward compatibility, we keep the hwtimer types and APIs.
|
||||
* If RT_USING_CLOCK_TIME is defined, these will map to clock_time.
|
||||
* Otherwise, we include the original hwtimer implementation.
|
||||
*/
|
||||
|
||||
#ifdef RT_USING_CLOCK_TIME
|
||||
|
||||
/* Timer Control Command */
|
||||
typedef enum
|
||||
{
|
||||
HWTIMER_CTRL_FREQ_SET = RT_DEVICE_CTRL_BASE(Timer) + 0x01, /* set the count frequency */
|
||||
HWTIMER_CTRL_STOP = RT_DEVICE_CTRL_BASE(Timer) + 0x02, /* stop timer */
|
||||
HWTIMER_CTRL_INFO_GET = RT_DEVICE_CTRL_BASE(Timer) + 0x03, /* get a timer feature information */
|
||||
HWTIMER_CTRL_MODE_SET = RT_DEVICE_CTRL_BASE(Timer) + 0x04 /* Setting the timing mode(oneshot/period) */
|
||||
} rt_hwtimer_ctrl_t;
|
||||
|
||||
/* Timing Mode */
|
||||
typedef enum
|
||||
{
|
||||
HWTIMER_MODE_ONESHOT = 0x01,
|
||||
HWTIMER_MODE_PERIOD
|
||||
} rt_hwtimer_mode_t;
|
||||
|
||||
/* Time Value */
|
||||
typedef struct rt_hwtimerval
|
||||
{
|
||||
rt_int32_t sec; /* second */
|
||||
rt_int32_t usec; /* microsecond */
|
||||
} rt_hwtimerval_t;
|
||||
|
||||
#define HWTIMER_CNTMODE_UP 0x01 /* increment count mode */
|
||||
#define HWTIMER_CNTMODE_DW 0x02 /* decreasing count mode */
|
||||
|
||||
struct rt_hwtimer_device;
|
||||
|
||||
struct rt_hwtimer_ops
|
||||
{
|
||||
void (*init)(struct rt_hwtimer_device *timer, rt_uint32_t state);
|
||||
rt_err_t (*start)(struct rt_hwtimer_device *timer, rt_uint32_t cnt, rt_hwtimer_mode_t mode);
|
||||
void (*stop)(struct rt_hwtimer_device *timer);
|
||||
rt_uint32_t (*count_get)(struct rt_hwtimer_device *timer);
|
||||
rt_err_t (*control)(struct rt_hwtimer_device *timer, rt_uint32_t cmd, void *args);
|
||||
};
|
||||
|
||||
/* Timer Feature Information */
|
||||
struct rt_hwtimer_info
|
||||
{
|
||||
rt_int32_t maxfreq; /* the maximum count frequency timer support */
|
||||
rt_int32_t minfreq; /* the minimum count frequency timer support */
|
||||
rt_uint32_t maxcnt; /* counter maximum value */
|
||||
rt_uint8_t cntmode; /* count mode (inc/dec) */
|
||||
};
|
||||
|
||||
typedef struct rt_hwtimer_device
|
||||
{
|
||||
struct rt_device parent;
|
||||
const struct rt_hwtimer_ops *ops;
|
||||
const struct rt_hwtimer_info *info;
|
||||
|
||||
rt_int32_t freq; /* counting frequency set by the user */
|
||||
rt_int32_t overflow; /* timer overflows */
|
||||
float period_sec;
|
||||
rt_int32_t cycles; /* how many times will generate a timeout event after overflow */
|
||||
rt_int32_t reload; /* reload cycles(using in period mode) */
|
||||
rt_hwtimer_mode_t mode; /* timing mode(oneshot/period) */
|
||||
} rt_hwtimer_t;
|
||||
|
||||
rt_err_t rt_device_hwtimer_register(rt_hwtimer_t *timer, const char *name, void *user_data);
|
||||
void rt_device_hwtimer_isr(rt_hwtimer_t *timer);
|
||||
|
||||
#ifdef RT_USING_DM
|
||||
extern void (*rt_device_hwtimer_us_delay)(rt_uint32_t us);
|
||||
#endif
|
||||
|
||||
#else /* !RT_USING_CLOCK_TIME */
|
||||
|
||||
#warning "RT_USING_HWTIMER is deprecated. Please migrate to RT_USING_CLOCK_TIME. Include <drivers/clock_time.h> instead and use rt_clock_time_* APIs."
|
||||
|
||||
/* If clock_time is not enabled, this means the old hwtimer module should still exist */
|
||||
/* The build system should handle this by including the old hwtimer directory */
|
||||
|
||||
#endif /* RT_USING_CLOCK_TIME */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __HWTIMER_H__ */
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2025, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2025-01-01 RT-Thread Compatibility layer for legacy ktime API
|
||||
*
|
||||
* COMPATIBILITY HEADER:
|
||||
* This header provides backward compatibility for code using the old ktime API.
|
||||
* All rt_ktime_* APIs are now redirected to rt_clock_* APIs.
|
||||
*
|
||||
* The old ktime subsystem has been removed and replaced with the unified
|
||||
* clock_time subsystem. Include <drivers/clock_time.h> for new code.
|
||||
*/
|
||||
|
||||
#ifndef __KTIME_H__
|
||||
#define __KTIME_H__
|
||||
|
||||
#ifdef RT_USING_CLOCK_TIME
|
||||
/* Include the unified clock_time header which provides all APIs */
|
||||
#include <drivers/clock_time.h>
|
||||
|
||||
/* All rt_ktime_* APIs are already defined as macros in clock_time.h */
|
||||
|
||||
#else
|
||||
#error "ktime subsystem has been removed. Please enable RT_USING_CLOCK_TIME in menuconfig."
|
||||
#endif /* RT_USING_CLOCK_TIME */
|
||||
|
||||
#endif /* __KTIME_H__ */
|
||||
@@ -246,18 +246,10 @@ extern "C" {
|
||||
#include "drivers/clock_time.h"
|
||||
#endif /* RT_USING_CLOCK_TIME */
|
||||
|
||||
#ifdef RT_USING_HWTIMER
|
||||
#include "drivers/hwtimer.h"
|
||||
#endif /* RT_USING_HWTIMER */
|
||||
|
||||
#ifdef RT_USING_AUDIO
|
||||
#include "drivers/dev_audio.h"
|
||||
#endif /* RT_USING_AUDIO */
|
||||
|
||||
#ifdef RT_USING_CPUTIME
|
||||
#include "drivers/cputime.h"
|
||||
#endif /* RT_USING_CPUTIME */
|
||||
|
||||
#ifdef RT_USING_ADC
|
||||
#include "drivers/adc.h"
|
||||
#endif /* RT_USING_ADC */
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
menuconfig RT_USING_KTIME
|
||||
bool "Ktime: kernel time (DEPRECATED - use RT_USING_CLOCK_TIME)"
|
||||
default n
|
||||
depends on !RT_USING_CLOCK_TIME
|
||||
help
|
||||
DEPRECATED: This option is maintained for backward compatibility only.
|
||||
New projects should use RT_USING_CLOCK_TIME instead.
|
||||
@@ -1,63 +0,0 @@
|
||||
# ktime
|
||||
|
||||
## 1、介绍
|
||||
|
||||
ktime 为 kernel time,为内核时间子系统,实现了内核启动时间以及芯片内核 cputimer 时间管理以及一个 ns 精度的高精度定时器,
|
||||
|
||||
## 2、如何打开 ktime
|
||||
|
||||
使用 ktime 需要在 RT-Thread 的 menuconfig 中选择它,具体路径如下:
|
||||
|
||||
```
|
||||
RT-Thread Components
|
||||
[*] Ktime: kernel time
|
||||
```
|
||||
|
||||
## 3、使用 ktime
|
||||
|
||||
> 函数的功能以及参数类型已经写在头文件的注释之中,本文不再赘述
|
||||
|
||||
### 3.1、boottime
|
||||
|
||||
boottime 为系统启动时间,即为系统从上电开始到现在运行的时间,默认的时间基准为芯片内核的 cputimer 的 cnt 值,已经适配了 aarch64 与 riscv64 平台,例如 stm32 等平台需要在自己的 bsp 里面进行适配(boottime 里面函数都为 weak function),需要注意 tick 从中断到设置中间的时延
|
||||
|
||||
**此值应当为 Readonly**
|
||||
|
||||
### 3.2、cputimer
|
||||
|
||||
cputimer 为芯片内核的 cputimer,也可以认为是 os tick 来源的那个定时器,cputimer 主要是提供了一个统一的接口去获得其分辨率,频率,cnt 值
|
||||
|
||||
**此值应当为 Readonly**
|
||||
|
||||
### 3.3、hrtimer
|
||||
|
||||
> TODO: hrtimer 目前还是使用优先级链表的方式进行管理,在遇到任务的大规模并发时还是存在部分性能问题,待内核有一个统一的红黑树组件后,再进行优化
|
||||
|
||||
hrtimer 为高精度定时器,需要重写其 weak 函数(需要对接到硬件定时器,否则默认走的是软件定时器,分辨率只有 os tick 的值)才能正常使用,其主要使用方法:
|
||||
|
||||
#### 3.3.1、延时
|
||||
|
||||
hrtimer 的延时并不是 while(1)式死等,它会将一个线程挂起,睡眠多少时间后通过硬件定时器将其唤醒(注:延时 ns 并不是真的能准确的延时这么多,而是在保证性能的情况下尽可能的延时)
|
||||
|
||||
- rt_ktime_hrtimer_sleep:单位为 cputimer 的 tick 值
|
||||
- rt_ktime_hrtimer_ndelay:单位为 ns
|
||||
- rt_ktime_hrtimer_udelay:单位为 us
|
||||
- rt_ktime_hrtimer_mdelay:单位为 ms
|
||||
|
||||
#### 3.3.1、定时器
|
||||
|
||||
hrtimer 还提供了一套 rt_timer 风格的 api
|
||||
|
||||
- rt_ktime_hrtimer_init
|
||||
- rt_ktime_hrtimer_delete
|
||||
- rt_ktime_hrtimer_start
|
||||
- rt_ktime_hrtimer_stop
|
||||
- rt_ktime_hrtimer_control
|
||||
- rt_ktime_hrtimer_detach
|
||||
|
||||
需要注意,此定时器回调函数依旧处于中断之中,不能做一些耗时的任务
|
||||
|
||||
## 5、联系方式
|
||||
|
||||
- 维护:xqyjlj
|
||||
- 主页:https://github.com/xqyjlj
|
||||
@@ -1,24 +0,0 @@
|
||||
import os
|
||||
from building import *
|
||||
|
||||
Import('rtconfig')
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
|
||||
src = Glob('src/*.c')
|
||||
list = os.listdir(cwd + "/src")
|
||||
if rtconfig.ARCH in list:
|
||||
if os.path.exists(cwd + "/src/" + rtconfig.ARCH + "/" + rtconfig.CPU):
|
||||
src += Glob("src/" + rtconfig.ARCH + "/" + rtconfig.CPU + "/*.c")
|
||||
else:
|
||||
src += Glob("src/" + rtconfig.ARCH + "/*.c")
|
||||
CPPPATH = [cwd, cwd + "/inc"]
|
||||
LOCAL_CCFLAGS = ''
|
||||
if rtconfig.PLATFORM in ['gcc', 'armclang']:
|
||||
LOCAL_CCFLAGS += ' -std=gnu99'
|
||||
elif rtconfig.PLATFORM in ['armcc']:
|
||||
LOCAL_CCFLAGS += ' --c99 --gnu'
|
||||
|
||||
group = DefineGroup('DeviceDrivers', src, depend=['RT_USING_KTIME'], CPPPATH=CPPPATH, LOCAL_CCFLAGS = LOCAL_CCFLAGS)
|
||||
|
||||
Return('group')
|
||||
@@ -1,192 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2025, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-07-10 xqyjlj The first version.
|
||||
* 2024-04-26 Shell Improve ipc performance
|
||||
* 2025-01-01 RT-Thread Compatibility layer for unified clock_time
|
||||
*/
|
||||
|
||||
#ifndef __KTIME_H__
|
||||
#define __KTIME_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
#include <ipc/completion.h>
|
||||
|
||||
#include "rtthread.h"
|
||||
|
||||
/*
|
||||
* COMPATIBILITY LAYER:
|
||||
* When RT_USING_CLOCK_TIME is enabled, this header redirects to the
|
||||
* unified clock_time subsystem. All rt_ktime_* APIs are mapped to
|
||||
* rt_clock_* APIs via macros defined in clock_time.h.
|
||||
*
|
||||
* When RT_USING_CLOCK_TIME is not enabled, the original ktime
|
||||
* implementation is used.
|
||||
*/
|
||||
|
||||
#ifdef RT_USING_CLOCK_TIME
|
||||
|
||||
/* Include the unified clock_time header which provides all APIs */
|
||||
#include <drivers/clock_time.h>
|
||||
|
||||
/* All rt_ktime_* APIs are already defined as macros in clock_time.h */
|
||||
/* No additional definitions needed here */
|
||||
|
||||
#else /* !RT_USING_CLOCK_TIME - Original ktime implementation */
|
||||
|
||||
#define RT_KTIME_RESMUL (1000000ULL)
|
||||
|
||||
struct rt_ktime_hrtimer
|
||||
{
|
||||
rt_uint8_t flag; /**< compatible to tick timer's flag */
|
||||
char name[RT_NAME_MAX];
|
||||
rt_list_t node;
|
||||
void *parameter;
|
||||
unsigned long delay_cnt;
|
||||
unsigned long timeout_cnt;
|
||||
rt_err_t error;
|
||||
struct rt_completion completion;
|
||||
void (*timeout_func)(void *parameter);
|
||||
};
|
||||
typedef struct rt_ktime_hrtimer *rt_ktime_hrtimer_t;
|
||||
|
||||
/**
|
||||
* @brief Get boottime with us precision
|
||||
*
|
||||
* @param tv: timeval
|
||||
* @return rt_err_t
|
||||
*/
|
||||
rt_err_t rt_ktime_boottime_get_us(struct timeval *tv);
|
||||
|
||||
/**
|
||||
* @brief Get boottime with s precision
|
||||
*
|
||||
* @param t: time_t
|
||||
* @return rt_err_t
|
||||
*/
|
||||
rt_err_t rt_ktime_boottime_get_s(time_t *t);
|
||||
|
||||
/**
|
||||
* @brief Get boottime with ns precision
|
||||
*
|
||||
* @param ts: timespec
|
||||
* @return rt_err_t
|
||||
*/
|
||||
rt_err_t rt_ktime_boottime_get_ns(struct timespec *ts);
|
||||
|
||||
/**
|
||||
* @brief Get cputimer resolution
|
||||
*
|
||||
* @return (resolution * RT_KTIME_RESMUL)
|
||||
*/
|
||||
rt_uint64_t rt_ktime_cputimer_getres(void);
|
||||
|
||||
/**
|
||||
* @brief Get cputimer frequency
|
||||
*
|
||||
* @return frequency
|
||||
*/
|
||||
unsigned long rt_ktime_cputimer_getfrq(void);
|
||||
|
||||
/**
|
||||
* @brief Get cputimer the value of the cnt counter
|
||||
*
|
||||
* @return cnt
|
||||
*/
|
||||
unsigned long rt_ktime_cputimer_getcnt(void);
|
||||
|
||||
/**
|
||||
* @brief Init cputimer
|
||||
*
|
||||
*/
|
||||
void rt_ktime_cputimer_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get hrtimer resolution
|
||||
*
|
||||
* @return (resolution * RT_KTIME_RESMUL)
|
||||
*/
|
||||
rt_uint64_t rt_ktime_hrtimer_getres(void);
|
||||
|
||||
/**
|
||||
* @brief Get hrtimer frequency
|
||||
*
|
||||
* @return frequency
|
||||
*/
|
||||
unsigned long rt_ktime_hrtimer_getfrq(void);
|
||||
|
||||
/**
|
||||
* @brief set hrtimer interrupt timeout count (cnt), you should re-implemented it in hrtimer device driver
|
||||
*
|
||||
* @param cnt: hrtimer requires a timing cnt value
|
||||
* @return rt_err_t
|
||||
*/
|
||||
rt_err_t rt_ktime_hrtimer_settimeout(unsigned long cnt);
|
||||
|
||||
/**
|
||||
* @brief called in hrtimer device driver isr routinue, it will process the timeouts
|
||||
*/
|
||||
void rt_ktime_hrtimer_process(void);
|
||||
|
||||
void rt_ktime_hrtimer_init(rt_ktime_hrtimer_t timer,
|
||||
const char *name,
|
||||
rt_uint8_t flag,
|
||||
void (*timeout)(void *parameter),
|
||||
void *parameter);
|
||||
rt_err_t rt_ktime_hrtimer_start(rt_ktime_hrtimer_t timer, unsigned long cnt);
|
||||
rt_err_t rt_ktime_hrtimer_stop(rt_ktime_hrtimer_t timer);
|
||||
rt_err_t rt_ktime_hrtimer_control(rt_ktime_hrtimer_t timer, int cmd, void *arg);
|
||||
rt_err_t rt_ktime_hrtimer_detach(rt_ktime_hrtimer_t timer);
|
||||
|
||||
rt_inline void rt_ktime_hrtimer_keep_errno(rt_ktime_hrtimer_t timer, rt_err_t err)
|
||||
{
|
||||
RT_ASSERT(timer != RT_NULL);
|
||||
|
||||
timer->error = err;
|
||||
rt_set_errno(-err);
|
||||
}
|
||||
|
||||
void rt_ktime_hrtimer_delay_init(struct rt_ktime_hrtimer *timer);
|
||||
void rt_ktime_hrtimer_delay_detach(struct rt_ktime_hrtimer *timer);
|
||||
void rt_ktime_hrtimer_process(void);
|
||||
|
||||
/**
|
||||
* @brief sleep by the cputimer cnt value
|
||||
*
|
||||
* @param cnt: the cputimer cnt value
|
||||
* @return rt_err_t
|
||||
*/
|
||||
rt_err_t rt_ktime_hrtimer_sleep(struct rt_ktime_hrtimer *timer, unsigned long cnt);
|
||||
|
||||
/**
|
||||
* @brief sleep by ns
|
||||
*
|
||||
* @param ns: ns
|
||||
* @return rt_err_t
|
||||
*/
|
||||
rt_err_t rt_ktime_hrtimer_ndelay(struct rt_ktime_hrtimer *timer, unsigned long ns);
|
||||
|
||||
/**
|
||||
* @brief sleep by us
|
||||
*
|
||||
* @param us: us
|
||||
* @return rt_err_t
|
||||
*/
|
||||
rt_err_t rt_ktime_hrtimer_udelay(struct rt_ktime_hrtimer *timer, unsigned long us);
|
||||
|
||||
/**
|
||||
* @brief sleep by ms
|
||||
*
|
||||
* @param ms: ms
|
||||
* @return rt_err_t
|
||||
*/
|
||||
rt_err_t rt_ktime_hrtimer_mdelay(struct rt_ktime_hrtimer *timer, unsigned long ms);
|
||||
|
||||
#endif /* !RT_USING_CLOCK_TIME */
|
||||
|
||||
#endif /* __KTIME_H__ */
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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 "gtimer.h"
|
||||
#include "ktime.h"
|
||||
|
||||
static volatile unsigned long _init_cnt = 0;
|
||||
|
||||
rt_uint64_t rt_ktime_cputimer_getres(void)
|
||||
{
|
||||
return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / rt_hw_get_gtimer_frq();
|
||||
}
|
||||
|
||||
unsigned long rt_ktime_cputimer_getfrq(void)
|
||||
{
|
||||
return rt_hw_get_gtimer_frq();
|
||||
}
|
||||
|
||||
unsigned long rt_ktime_cputimer_getcnt(void)
|
||||
{
|
||||
return rt_hw_get_cntpct_val() - _init_cnt;
|
||||
}
|
||||
|
||||
void rt_ktime_cputimer_init(void)
|
||||
{
|
||||
_init_cnt = rt_hw_get_cntpct_val();
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
#define __KTIME_MUL ((1000ULL * 1000 * 1000) / RT_TICK_PER_SECOND)
|
||||
|
||||
rt_weak rt_err_t rt_ktime_boottime_get_us(struct timeval *tv)
|
||||
{
|
||||
RT_ASSERT(tv != RT_NULL);
|
||||
|
||||
rt_uint64_t ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL;
|
||||
|
||||
tv->tv_sec = ns / (1000ULL * 1000 * 1000);
|
||||
tv->tv_usec = (ns % (1000ULL * 1000 * 1000)) / 1000;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_weak rt_err_t rt_ktime_boottime_get_s(time_t *t)
|
||||
{
|
||||
RT_ASSERT(t != RT_NULL);
|
||||
|
||||
rt_uint64_t ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL;
|
||||
|
||||
*t = ns / (1000ULL * 1000 * 1000);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_weak rt_err_t rt_ktime_boottime_get_ns(struct timespec *ts)
|
||||
{
|
||||
RT_ASSERT(ts != RT_NULL);
|
||||
|
||||
rt_uint64_t ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL;
|
||||
|
||||
ts->tv_sec = ns / (1000ULL * 1000 * 1000);
|
||||
ts->tv_nsec = ns % (1000ULL * 1000 * 1000);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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_uint64_t rt_ktime_cputimer_getres(void)
|
||||
{
|
||||
return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / RT_TICK_PER_SECOND;
|
||||
}
|
||||
|
||||
rt_weak unsigned long rt_ktime_cputimer_getfrq(void)
|
||||
{
|
||||
return RT_TICK_PER_SECOND;
|
||||
}
|
||||
|
||||
rt_weak unsigned long rt_ktime_cputimer_getcnt(void)
|
||||
{
|
||||
return rt_tick_get();
|
||||
}
|
||||
|
||||
rt_weak void rt_ktime_cputimer_init(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
static volatile unsigned long _init_cnt = 0;
|
||||
|
||||
rt_uint64_t rt_ktime_cputimer_getres(void)
|
||||
{
|
||||
return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / CPUTIME_TIMER_FREQ;
|
||||
}
|
||||
|
||||
unsigned long rt_ktime_cputimer_getfrq(void)
|
||||
{
|
||||
return CPUTIME_TIMER_FREQ;
|
||||
}
|
||||
|
||||
unsigned long rt_ktime_cputimer_getcnt(void)
|
||||
{
|
||||
unsigned long time_elapsed;
|
||||
__asm__ __volatile__("rdtime %0" : "=r"(time_elapsed));
|
||||
return time_elapsed - _init_cnt;
|
||||
}
|
||||
|
||||
void rt_ktime_cputimer_init(void)
|
||||
{
|
||||
__asm__ __volatile__("rdtime %0" : "=r"(_init_cnt));
|
||||
}
|
||||
Reference in New Issue
Block a user