This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 352e3a6873 armv7-a timer:fix timer overflow.
352e3a6873 is described below

commit 352e3a6873a3693507ce253023647ffd00006b7c
Author: yangguangcai <yangguang...@xiaomi.com>
AuthorDate: Thu Nov 23 20:49:37 2023 +0800

    armv7-a timer:fix timer overflow.
    
    Signed-off-by: yangguangcai <yangguang...@xiaomi.com>
---
 arch/arm/src/armv7-a/arm_timer.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/arm/src/armv7-a/arm_timer.c b/arch/arm/src/armv7-a/arm_timer.c
index 2efc105491..798956e823 100644
--- a/arch/arm/src/armv7-a/arm_timer.c
+++ b/arch/arm/src/armv7-a/arm_timer.c
@@ -137,7 +137,9 @@ static inline void arm_timer_set_cval(uint64_t cval)
 
 static inline uint64_t nsec_from_count(uint64_t count, uint32_t freq)
 {
-  return (uint64_t)count * NSEC_PER_SEC / freq;
+  uint64_t sec = count / freq;
+  uint64_t nsec = (count % freq) * NSEC_PER_SEC / freq;
+  return sec * NSEC_PER_SEC + nsec;
 }
 
 static inline uint64_t nsec_to_count(uint32_t nsec, uint32_t freq)

Reply via email to