mirror of
https://github.com/apache/nuttx.git
synced 2025-12-11 21:20:26 +08:00
arch: risc-v: Fix nsec overflow in riscv_mtimer_current()
Summary: - I noticed that mtimer stops around 30min after boot. - Finally, I found that nesc overflows in riscv_mtimer_current(). - This commit fixes this issue. Impact: - None Testing: - Tested with rv-virt:nsh on QEMU-7.1 Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
This commit is contained in:
committed by
Xiang Xiao
parent
0ae242aa8d
commit
3b2685409a
@@ -290,7 +290,7 @@ static int riscv_mtimer_current(struct oneshot_lowerhalf_s *lower,
|
|||||||
struct riscv_mtimer_lowerhalf_s *priv =
|
struct riscv_mtimer_lowerhalf_s *priv =
|
||||||
(struct riscv_mtimer_lowerhalf_s *)lower;
|
(struct riscv_mtimer_lowerhalf_s *)lower;
|
||||||
uint64_t mtime = riscv_mtimer_get_mtime(priv);
|
uint64_t mtime = riscv_mtimer_get_mtime(priv);
|
||||||
uint64_t nsec = mtime * NSEC_PER_SEC / priv->freq;
|
uint64_t nsec = mtime / (priv->freq / USEC_PER_SEC) * NSEC_PER_USEC;
|
||||||
|
|
||||||
ts->tv_sec = nsec / NSEC_PER_SEC;
|
ts->tv_sec = nsec / NSEC_PER_SEC;
|
||||||
ts->tv_nsec = nsec % NSEC_PER_SEC;
|
ts->tv_nsec = nsec % NSEC_PER_SEC;
|
||||||
|
|||||||
Reference in New Issue
Block a user