diff options
author | Rafaël Carré <rafael.carre@gmail.com> | 2010-04-27 18:18:30 +0000 |
---|---|---|
committer | Rafaël Carré <rafael.carre@gmail.com> | 2010-04-27 18:18:30 +0000 |
commit | 621cf62702cecf13403d026c4f38fcca7a947917 (patch) | |
tree | 55b60ebe94f334d0f70cad005d092375cd27e9e1 /firmware | |
parent | dda7fab1d65e73a6bdbdac1b1d37330b8f0085aa (diff) |
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
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/target/arm/as3525/system-target.h | 20 |
1 files changed, 18 insertions, 2 deletions
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 */ |