Skip to content
Closed
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
43 changes: 30 additions & 13 deletions components/drivers/cputime/cputime.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
* Copyright (c) 2006-2025 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017-12-23 Bernard first version
* 2025-01-30 wumingzi transform to doxygen comment
*/

#include <rtdevice.h>
#include <rtthread.h>
#include <sys/errno.h>

/**
* @addtogroup Drivers RTTHREAD Driver
* @defgroup cputimer cputimer
* @brief cputimer driver api
* @ingroup Drivers
* @addtogroup cputimer
* @{
*/

static const struct rt_clock_cputime_ops *_cputime_ops = RT_NULL;

/**
* The clock_cpu_getres() function shall return the resolution of CPU time, the
* @brief 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))
* @return the number of nanosecond per tick(x (1000UL * 1000))
*/
uint64_t clock_cpu_getres(void)
{
Expand All @@ -30,9 +40,9 @@ uint64_t clock_cpu_getres(void)
}

/**
* The clock_cpu_gettime() function shall return the current value of cpu time tick.
* @brief The clock_cpu_gettime() function shall return the current value of cpu time tick.
*
* @return the cpu tick
* @return the cpu tick
*/
uint64_t clock_cpu_gettime(void)
{
Expand All @@ -44,13 +54,14 @@ uint64_t clock_cpu_gettime(void)
}

/**
* The clock_cpu_settimeout() fucntion set timeout time and timeout callback function
* @brief 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
* @param param the Parameters of timeout function
*
* @return RT_FALSE or RT_TURE
*/
int clock_cpu_settimeout(uint64_t tick, void (*timeout)(void *param), void *param)
{
Expand All @@ -61,6 +72,11 @@ int clock_cpu_settimeout(uint64_t tick, void (*timeout)(void *param), void *para
return 0;
}

/**
* @brief Check if cputimer timeout callback function has been set
*
* @return RT_FALSE or RT_TURE
*/
int clock_cpu_issettimeout(void)
{
if (_cputime_ops)
Expand All @@ -69,12 +85,12 @@ int clock_cpu_issettimeout(void)
}

/**
* The clock_cpu_microsecond() fucntion shall return the microsecond according to
* @brief The clock_cpu_microsecond() fucntion shall return the microsecond according to
* cpu_tick parameter.
*
* @param cpu_tick the cpu tick
*
* @return the microsecond
* @return the microseconds
*/
uint64_t clock_cpu_microsecond(uint64_t cpu_tick)
{
Expand All @@ -84,12 +100,12 @@ uint64_t clock_cpu_microsecond(uint64_t cpu_tick)
}

/**
* The clock_cpu_microsecond() fucntion shall return the millisecond according to
* @brief The clock_cpu_millisecond() fucntion shall return the millisecond according to
* cpu_tick parameter.
*
* @param cpu_tick the cpu tick
*
* @return the millisecond
* @return the milliseconds
*/
uint64_t clock_cpu_millisecond(uint64_t cpu_tick)
{
Expand All @@ -99,9 +115,9 @@ uint64_t clock_cpu_millisecond(uint64_t cpu_tick)
}

/**
* The clock_cpu_seops() function shall set the ops of cpu time.
* @brief The clock_cpu_seops() function shall set the ops of cpu time.
*
* @return always return 0.
* @return always return 0.
*/
int clock_cpu_setops(const struct rt_clock_cputime_ops *ops)
{
Expand All @@ -114,3 +130,4 @@ int clock_cpu_setops(const struct rt_clock_cputime_ops *ops)

return 0;
}
/*! @}*/
22 changes: 18 additions & 4 deletions components/drivers/cputime/cputime_cortexm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
* Copyright (c) 2006-2025 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -18,7 +18,11 @@
#include <perf_counter.h>
#endif

/* Use Cycle counter of Data Watchpoint and Trace Register for CPU time */
/**
* @brief Get nanoseconds per tick
*
* @return the number of nanoseconds per tick multiplied by 1 000 000
*/
static uint64_t cortexm_cputime_getres(void)
{
uint64_t ret = 1000UL * 1000 * 1000;
Expand All @@ -27,6 +31,11 @@ static uint64_t cortexm_cputime_getres(void)
return ret;
}

/**
* @brief Read time counter
*
* @return value of ticks
*/
static uint64_t cortexm_cputime_gettime(void)
{
#ifdef PKG_USING_PERF_COUNTER
Expand All @@ -42,7 +51,12 @@ const static struct rt_clock_cputime_ops _cortexm_ops =
cortexm_cputime_gettime
};


/**
* @brief Init cputimer operation of cortex-m architecture by using Cycle
counter of Data Watchpoint and Trace Register for CPU time
*
* @return return 0 forever
*/
int cortexm_cputime_init(void)
{
#ifdef PKG_USING_PERF_COUNTER
Expand All @@ -66,4 +80,4 @@ int cortexm_cputime_init(void)
#endif /* PKG_USING_PERF_COUNTER */
return 0;
}
INIT_BOARD_EXPORT(cortexm_cputime_init);
INIT_BOARD_EXPORT(cortexm_cputime_init);
38 changes: 37 additions & 1 deletion components/drivers/cputime/cputime_riscv.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
/*
* Copyright (c) 2006-2025 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-11-23 Guozhanxin first version
* 2023-04-12 xqyjlj fix cpu timer in multithreading
* 2025-01-30 wumingzi add doxygen comment
*/

#include <rthw.h>
#include <rtdevice.h>
#include <rtthread.h>

#include <board.h>

/* Use Cycle counter of Data Watchpoint and Trace Register for CPU time */
/**
* @addtogroup Drivers RTTHREAD Driver
* @defgroup cputimer cputimer
* @brief cputimer driver api
* @ingroup Drivers
* @addtogroup cputimer
* @{
*/

/**
* @brief Get nanoseconds per tick
*
* @return the number of nanoseconds per tick multiplied by 1 000 000
*/
static uint64_t riscv_cputime_getres(void)
{
uint64_t ret = 1000UL * 1000 * 1000;
Expand All @@ -14,6 +38,11 @@ static uint64_t riscv_cputime_getres(void)
return ret;
}

/**
* @brief Read time counter
*
* @return value of ticks
*/
static uint64_t riscv_cputime_gettime(void)
{
uint64_t time_elapsed;
Expand All @@ -29,9 +58,16 @@ const static struct rt_clock_cputime_ops _riscv_ops =
riscv_cputime_gettime
};

/**
* @brief Init cputimer operation of riscv architecture
*
* @return return 0 forever
*/
int riscv_cputime_init(void)
{
clock_cpu_setops(&_riscv_ops);
return 0;
}
INIT_BOARD_EXPORT(riscv_cputime_init);

/*! @}*/
Loading
Loading