/*---------------------------------------------------------------------------*
  Project:  NitroSDK - OS - include
  File:     tick.h

  Copyright 2003-2004 Nintendo.  All rights reserved.

  These coded instructions, statements, and computer programs contain
  proprietary information of Nintendo of America Inc. and/or Nintendo
  Company Ltd., 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 Nintendo.

  $Log: tick.h,v $
  Revision 1.3  2004/04/07 02:03:17  yada
  fixed header comment

  Revision 1.2  2004/03/02 06:59:13  yasu
  added one more ')' at OS_TicksToMicroSeconds

  Revision 1.1  2004/02/25 11:36:52  yada
  Changes in accordance with systemClock ->Tick

  Revision 1.8  2004/02/24 12:37:15  yada
  Fixed misspelling in OS_GetTick()

  Revision 1.7  2004/02/24 10:49:49  yada
  Added OS_GetTick()

  Revision 1.6  2004/02/12 13:36:40  yasu
  changed directory of ioreg.h

  Revision 1.5  2004/02/12 10:56:04  yasu
  new location of include files ARM9/ARM7

  Revision 1.4  2004/02/05 07:09:03  yasu
  changed SDK prefix iris -> nitro

  Revision 1.3  2004/02/04 07:36:25  yada
  Added OS_IsSystemClockAvailable()
  Changed names from OS_GetSystemClock(), OS_SetSystemClock()
   to OS_GetTime(), OS_SetTime()

  Revision 1.2  2004/02/03 11:18:29  yada
  Changed the systemClock value from u32 to OSTime(u64).

  Revision 1.1  2004/02/02 05:29:18  yada
  System rock firstRelease


  $NoKeywords: $
 *---------------------------------------------------------------------------*/

#ifndef NITRO_OS_TICK_H_
#define NITRO_OS_TICK_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <nitro/misc.h>
#include <nitro/types.h>
#include <nitro/ioreg.h>


//---- unit of tick
typedef u64 OSTick;

//---- conversion tick count <-> real time count
#define OS_SYSTEM_CLOCK                HW_SYSTEM_CLOCK

#define  OS_MicroSecondsToTicks( msec ) ( ((OS_SYSTEM_CLOCK/1000) * (msec)) / 64 / 1000 )
#define  OS_MilliSecondsToTicks( msec ) ( ((OS_SYSTEM_CLOCK/1000) * (msec)) / 64 )
#define  OS_SecondsToTicks(       sec ) ( (OS_SYSTEM_CLOCK * (sec)) / 64 )

#define  OS_TicksToMicroSeconds( tick ) ( ((tick) * 64 * 1000) / (OS_SYSTEM_CLOCK/1000) )
#define  OS_TicksToMilliSeconds( tick ) ( ((tick) * 64) / (OS_SYSTEM_CLOCK/1000) )
#define  OS_TicksToSeconds(      tick ) ( ((tick) * 64) / OS_SYSTEM_CLOCK )


/*---------------------------------------------------------------------------*
  Name:         OS_InitTick

  Description:  Initialize tick system

  Arguments:    None

  Returns:      None
 *---------------------------------------------------------------------------*/
void OS_InitTick( void );


/*---------------------------------------------------------------------------*
  Name:         OS_IsTickAvailable

  Description:  check tick system is available

  Arguments:    None

  Returns:      if available, TRUE.
 *---------------------------------------------------------------------------*/
BOOL OS_IsTickAvailable( void );


/*---------------------------------------------------------------------------*
  Name:         OS_GetTick

  Description:  get tick value

  Arguments:    None

  Returns:      tick value
 *---------------------------------------------------------------------------*/
OSTick OS_GetTick( void );


/*---------------------------------------------------------------------------*
  Name:         OS_GetTickLo

  Description:  get tick value (only u16 part)

  Arguments:    None

  Returns:      sytem clock value (only u16 part)
 *---------------------------------------------------------------------------*/
u16 OS_GetTickLo( void );


/*---------------------------------------------------------------------------*
  Name:         OS_SetTick

  Description:  set tick value

  Arguments:    count     value of tick to be set

  Returns:      None
 *---------------------------------------------------------------------------*/
void  OS_SetTick( OSTick count );



#ifdef __cplusplus
} /* extern "C" */
#endif

/* NITRO_OS_TICK_H_ */
#endif
