From 621cf62702cecf13403d026c4f38fcca7a947917 Mon Sep 17 00:00:00 2001 From: Rafaël Carré Date: Tue, 27 Apr 2010 18:18:30 +0000 Subject: as3525v2: fix udelay() detect wraps so we don't miss the value we were waiting for fix audio stuttering on fuzev2 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25740 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/as3525/system-target.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'firmware/target/arm/as3525') diff --git a/firmware/target/arm/as3525/system-target.h b/firmware/target/arm/as3525/system-target.h index d2cf99499d..ee46e7c7a5 100644 --- a/firmware/target/arm/as3525/system-target.h +++ b/firmware/target/arm/as3525/system-target.h @@ -62,7 +62,8 @@ extern int c200v2_variant; static inline void udelay(unsigned usecs) __attribute__((always_inline)); static inline void udelay(unsigned usecs) { - int now, end; + unsigned now; + int end; /** * we're limited to 1.5us multiplies due to the odd timer frequency (1.5MHz), @@ -94,9 +95,24 @@ static inline void udelay(unsigned usecs) int delay = usecs * 2 / 3; /* us * 1.5 = us*timer_period */ end = now - delay; } + + unsigned old; + /* underrun ? */ if (end < 0) + { + do { + old = now; + now = TIMER2_VALUE; + } while(now <= old); /* if the new value is higher then we wrapped */ + end += TIMER_PERIOD; - while(TIMER2_VALUE != (unsigned)end); + } + + do { + /* if timer wraps then we missed our end value */ + old = now; + now = TIMER2_VALUE; + } while(now > (unsigned)end && now <= old); } #endif /* SYSTEM_TARGET_H */ -- cgit v1.2.3