From 5aeab4a36cb43a729874231b6110a9d79124e2a3 Mon Sep 17 00:00:00 2001 From: ligd Date: Tue, 26 Dec 2023 22:56:29 +0800 Subject: [PATCH] armv7-a timer:fix timer overflow. Signed-off-by: ligd --- arch/arm/src/armv7-r/arm_timer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm/src/armv7-r/arm_timer.c b/arch/arm/src/armv7-r/arm_timer.c index dfb3e541c0..08f9d24a6c 100644 --- a/arch/arm/src/armv7-r/arm_timer.c +++ b/arch/arm/src/armv7-r/arm_timer.c @@ -143,7 +143,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)