void usleep(int us)
{
const int cycles = (3 * us) >> 1;
/* TIMER_FREQ * us / 1000000 =
* 24000000 / 16 * us / 1000000 =
* 1.5 * us = 3 * us / 2
*/
int timer_start = TIMER2_VALUE;
while(1)
{
int timer_val = TIMER2_VALUE;
if(timer_val > timer_start) /* timer wrapped */
timer_start += (TIMER_FREQ / HZ)
#ifdef HAVE_SCROLLWHEEL
>> 1
#endif
;

if(timer_start - timer_val >= cycles)
return;
}
}