Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions bsp/rockchip/dm/hwtimer/clock_timer-rockchip_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,11 @@ static const struct rk_timer_data rk3399_timer_data =

#ifdef RT_USING_CLOCK_TIME

uint64_t rt_clock_hrtimer_getfrq(void)
rt_uint64_t rt_clock_hrtimer_getfrq(void)
{
return OSC_HZ;
}

uint64_t rt_clock_hrtimer_getres(void)
{
return ((1000UL * 1000 * 1000) * RT_CLOCK_TIME_RESMUL) / OSC_HZ;
}

/**
* @brief set the timeout function for hrtimer framework
*
Expand All @@ -377,7 +372,7 @@ uint64_t rt_clock_hrtimer_getres(void)
* @param cnt the count of timer dealy
* @return rt_err_t 0 forever
*/
rt_err_t rt_clock_hrtimer_settimeout(unsigned long cnt)
rt_err_t rt_clock_hrtimer_settimeout(rt_uint64_t cnt)
{
struct hrt_timer *timer = &_timer0;
struct rk_timer *time = timer->timer;
Expand Down
1 change: 0 additions & 1 deletion components/drivers/clock_time/arch/aarch64/cputimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ void rt_clock_time_source_init(void)
rt_uint8_t caps = RT_CLOCK_TIME_CAP_SOURCE;

_aarch64_clock_dev.ops = &_aarch64_clock_ops;
_aarch64_clock_dev.res_scale = RT_CLOCK_TIME_RESMUL;
_aarch64_clock_dev.caps = caps;
rt_clock_time_device_register(&_aarch64_clock_dev, "clock_time_gtimer", caps);
rt_clock_time_set_default_source(&_aarch64_clock_dev);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ void rt_clock_time_source_init(void)
rt_uint8_t caps = RT_CLOCK_TIME_CAP_SOURCE;

_riscv_clock_dev.ops = &_riscv_clock_ops;
_riscv_clock_dev.res_scale = RT_CLOCK_TIME_RESMUL;
_riscv_clock_dev.caps = caps;
rt_clock_time_device_register(&_riscv_clock_dev, "clock_time_rdtime", caps);
rt_clock_time_set_default_source(&_riscv_clock_dev);
Expand Down
39 changes: 17 additions & 22 deletions components/drivers/clock_time/clock_boottime.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,70 +9,65 @@
*/

#include <drivers/clock_time.h>
#include <sys/time.h>

#include "clock_time_internal.h"

rt_err_t rt_clock_boottime_get_us(struct timeval *tv)
{
rt_uint64_t cnt;
rt_uint64_t res;
rt_uint64_t ns;
rt_uint64_t freq;

RT_ASSERT(tv != RT_NULL);

cnt = rt_clock_time_get_counter();
res = rt_clock_time_get_res_scaled();
if (res == 0)
freq = rt_clock_time_get_freq();
if (freq == 0)
{
return -RT_ERROR;
}

ns = (cnt * res) / RT_CLOCK_TIME_RESMUL;

tv->tv_sec = ns / (1000ULL * 1000 * 1000);
tv->tv_usec = (ns % (1000ULL * 1000 * 1000)) / 1000;
tv->tv_sec = (time_t)(cnt / freq);
tv->tv_usec = rt_clock_time_muldiv_u64(cnt % freq, MICROSECOND_PER_SECOND, freq, RT_NULL, RT_NULL);

return RT_EOK;
}

rt_err_t rt_clock_boottime_get_s(time_t *t)
{
rt_uint64_t cnt;
rt_uint64_t res;
rt_uint64_t ns;
rt_uint64_t freq;

RT_ASSERT(t != RT_NULL);

cnt = rt_clock_time_get_counter();
res = rt_clock_time_get_res_scaled();
if (res == 0)
freq = rt_clock_time_get_freq();
if (freq == 0)
{
return -RT_ERROR;
}

ns = (cnt * res) / RT_CLOCK_TIME_RESMUL;
*t = ns / (1000ULL * 1000 * 1000);
*t = (time_t)(cnt / freq);

return RT_EOK;
}

rt_err_t rt_clock_boottime_get_ns(struct timespec *ts)
{
rt_uint64_t cnt;
rt_uint64_t res;
rt_uint64_t ns;
rt_uint64_t freq;

RT_ASSERT(ts != RT_NULL);

cnt = rt_clock_time_get_counter();
res = rt_clock_time_get_res_scaled();
if (res == 0)
freq = rt_clock_time_get_freq();
if (freq == 0)
{
return -RT_ERROR;
}

ns = (cnt * res) / RT_CLOCK_TIME_RESMUL;

ts->tv_sec = ns / (1000ULL * 1000 * 1000);
ts->tv_nsec = ns % (1000ULL * 1000 * 1000);
ts->tv_sec = (time_t)(cnt / freq);
ts->tv_nsec = rt_clock_time_muldiv_u64(cnt % freq, NANOSECOND_PER_SECOND, freq, RT_NULL, RT_NULL);

return RT_EOK;
}
Loading
Loading