Skip to content

Commit

Permalink
riscv_mtimer: modify riscv_mtimer_current to reduce precision lost
Browse files Browse the repository at this point in the history
Signed-off-by: liaoao <[email protected]>
  • Loading branch information
leo11261 committed Sep 12, 2024
1 parent 8b4b66e commit c6fa87b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions arch/risc-v/src/common/riscv_mtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,11 @@ static int riscv_mtimer_current(struct oneshot_lowerhalf_s *lower,
struct riscv_mtimer_lowerhalf_s *priv =
(struct riscv_mtimer_lowerhalf_s *)lower;
uint64_t mtime = riscv_mtimer_get_mtime(priv);
uint64_t nsec = mtime / (priv->freq / USEC_PER_SEC) * NSEC_PER_USEC;
uint64_t left;

ts->tv_sec = nsec / NSEC_PER_SEC;
ts->tv_nsec = nsec % NSEC_PER_SEC;
ts->tv_sec = mtime / priv->freq;
left = mtime - ts->tv_sec * priv->freq;
ts->tv_nsec = NSEC_PER_SEC * left / priv->freq;

return 0;
}
Expand Down

0 comments on commit c6fa87b

Please sign in to comment.