/*
 *               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 <types.h>
#include <sys.h>
#include <ioslibc.h>
#include <ios.h>
#include <iop.h>
#define STACK_SIZE 1024
const u8 _initStack[STACK_SIZE];
const u32 _initStackSize = sizeof(_initStack);
const u32 _initPriority = 10;

#define US_TO_TICKS_ENHANCED(x) (x + (x >> 1) + (x >>2) + (x >> 3) + (x>>6) \
                                 + (x >> 8) + (x >>9) + (x >> 10) + (x>>12))
#define US_TO_TICKS_COMPAT(x) (x + (x >> 2) + (x >>6))

void
main(u32 arg)
{
  u32 n = 10;
  u32  i = 0;
  u32 end_time;
  u32 start_time;
  initSysMode(enhancedmode);
  start_time = busRd32(SYS_TIMER_REG);
  for (i = 0; i < n; ++i ) {
      udelay(100);
  }
  end_time = busRd32(SYS_TIMER_REG);
  printf("udelay(100 x 10): start_ticks: %08x end_ticks: %08x delta: %u\n", start_time, end_time, end_time - start_time);
  printf("expected ticks = %u %u\n", 10*US_TO_TICKS_ENHANCED(100),
           US_TO_TICKS_ENHANCED(1000));
}
