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
This commit is contained in:
Rafaël Carré 2010-04-27 18:18:30 +00:00
parent dda7fab1d6
commit 621cf62702

View file

@ -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 */