/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */
#include <ios.h>
#include <sys.h>
#include <iop.h>
#include <sys_int.h>
#include <ioslibc.h>
    
void
udelay(u32 usec)
{
    u32 start, end, ticks;
    ticks = convertMicrosecondsToTicks(usec);
    if (ticks < 2) ticks = 2;

    start = busRd32(SYS_TIMER_REG);
    end = start + ticks;
    if (end > start) {
        while (busRd32(SYS_TIMER_REG) < end );
    } else {
        while ( ((ticks = busRd32(SYS_TIMER_REG)) & 0x80000000) ||
                (ticks < end) );
    }
}
