guo ecf2d82159
sync branch rt-smart. (#6641)
* Synchronize the code of the rt mart branch to the master branch.
  * TTY device
  * Add lwP code from rt-smart
  * Add vnode in DFS, but DFS will be re-write for rt-smart
  * There are three libcpu for rt-smart:
    * arm/cortex-a, arm/aarch64
    * riscv64

Co-authored-by: Rbb666 <zhangbingru@rt-thread.com>
Co-authored-by: zhkag <zhkag@foxmail.com>
2022-12-03 12:07:44 +08:00

40 lines
739 B
C

#include <rthw.h>
#include <rtdevice.h>
#include <rtthread.h>
#include <board.h>
#define TIMER_FREQ (24000000)
/* Use Cycle counter of Data Watchpoint and Trace Register for CPU time */
static float riscv_cputime_getres(void)
{
float ret = 1000 * 1000 * 1000;
ret = ret / 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);