jlaitine commented on code in PR #15929: URL: https://github.com/apache/nuttx/pull/15929#discussion_r1983204204
########## arch/risc-v/src/common/riscv_mtimer.c: ########## @@ -211,19 +210,20 @@ static int riscv_mtimer_max_delay(struct oneshot_lowerhalf_s *lower, static int riscv_mtimer_start(struct oneshot_lowerhalf_s *lower, oneshot_callback_t callback, void *arg, - const struct timespec *ts) + clock_t ticks) { struct riscv_mtimer_lowerhalf_s *priv = (struct riscv_mtimer_lowerhalf_s *)lower; irqstate_t flags; uint64_t mtime; + clock_t current; uint64_t alarm; flags = up_irq_save(); mtime = riscv_mtimer_get_mtime(priv); - alarm = mtime + ts->tv_sec * priv->freq + - ts->tv_nsec * priv->freq / NSEC_PER_SEC; + current = mtime * TICK_PER_SEC / priv->freq; + alarm = (current + ticks) * priv->freq / TICK_PER_SEC; Review Comment: No, this is exactly what can't be done. The first conversion calculates the "current" tick. the (current + tick) calculates the tick on which the wakeup needs to be set. The "(current + ticks) * priv->freq / TICK_PER_SEC" properly aligns the compare register value on the proper boundary. If you'd leave out the first conversion, you'd return the issue of timer drift, as the "mtime" is not the accurate start time of the tick. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org