1 /*---------------------------------------------------------------------------* 2 Project: TwlSDK - OS - include 3 File: tick.h 4 5 Copyright 2003-2009 Nintendo. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Date:: 2009-06-04#$ 14 $Rev: 10698 $ 15 $Author: okubata_ryoma $ 16 17 *---------------------------------------------------------------------------*/ 18 19 #ifndef NITRO_OS_TICK_H_ 20 #define NITRO_OS_TICK_H_ 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #include <nitro/misc.h> 27 #include <nitro/types.h> 28 #ifndef SDK_TWL 29 #include <nitro/ioreg.h> 30 #else 31 #include <twl/ioreg.h> 32 #endif 33 34 35 //---- unit of tick 36 typedef u64 OSTick; 37 38 //---- conversion tick count <-> real time count 39 #define OS_SYSTEM_CLOCK HW_SYSTEM_CLOCK 40 41 #define OSi_BOUND_SEC1 128154 // 2^8 / (OS_SYSTEM_CLOCK/1000) = 128154.4 42 #define OSi_BOUND_SEC2 128 // 2^8 / OS_SYSTEM_CLOCK = 128.2 43 #define OSi_BOUND_TICK1 67108 // 2^8 / (64*1000) = 67108.9 44 #define OSi_BOUND_TICK2 67108863 // 2^8 / 64 = 67108864 45 46 //---- sec to tick 47 #define OS_MicroSecondsToTicks( usec ) ((OSTick)( ((OS_SYSTEM_CLOCK/1000) * (u64)(usec)) / 64 / 1000 )) 48 #define OS_MicroSecondsToTicks32( usec ) ((OSTick)( ((OS_SYSTEM_CLOCK/1000) * (u32)(usec)) / 64 / 1000 )) 49 50 #define OS_MilliSecondsToTicks( msec ) ((OSTick)( ((OS_SYSTEM_CLOCK/1000) * (u64)(msec)) / 64 )) 51 #define OS_MilliSecondsToTicks32( msec ) ((OSTick)( ((OS_SYSTEM_CLOCK/1000) * (u32)(msec)) / 64 )) 52 53 #define OS_SecondsToTicks( sec ) ((OSTick)( (OS_SYSTEM_CLOCK * (u64)(sec)) / 64 )) 54 #define OS_SecondsToTicks32( sec ) ((OSTick)( (OS_SYSTEM_CLOCK * (u32)(sec)) / 64 )) 55 56 //---- tick to sec 57 #define OS_TicksToMicroSeconds( tick ) ( ((u64)(tick) * 64 * 1000) / (OS_SYSTEM_CLOCK/1000) ) 58 #define OS_TicksToMicroSeconds32( tick ) ( ((u32)(tick) * 64 * 1000) / (OS_SYSTEM_CLOCK/1000) ) 59 60 #define OS_TicksToMilliSeconds( tick ) ( ((u64)(tick) * 64) / (OS_SYSTEM_CLOCK/1000) ) 61 #define OS_TicksToMilliSeconds32( tick ) ( ((u32)(tick) * 64) / (OS_SYSTEM_CLOCK/1000) ) 62 63 #define OS_TicksToSeconds( tick ) ( ((u64)(tick) * 64) / OS_SYSTEM_CLOCK ) 64 #define OS_TicksToSeconds32( tick ) ( ((u32)(tick) * 64) / OS_SYSTEM_CLOCK ) 65 66 /*---------------------------------------------------------------------------* 67 Name: OS_InitTick 68 69 Description: Initialize tick system 70 71 Arguments: None 72 73 Returns: None 74 *---------------------------------------------------------------------------*/ 75 void OS_InitTick(void); 76 77 78 /*---------------------------------------------------------------------------* 79 Name: OS_IsTickAvailable 80 81 Description: check tick system is available 82 83 Arguments: None 84 85 Returns: if available, TRUE. 86 *---------------------------------------------------------------------------*/ 87 BOOL OS_IsTickAvailable(void); 88 89 90 /*---------------------------------------------------------------------------* 91 Name: OS_GetTick 92 93 Description: get tick value 94 95 Arguments: None 96 97 Returns: tick value 98 *---------------------------------------------------------------------------*/ 99 OSTick OS_GetTick(void); 100 101 102 /*---------------------------------------------------------------------------* 103 Name: OS_GetTickLo 104 105 Description: get tick value (only u16 part) 106 107 Arguments: None 108 109 Returns: sytem clock value (only u16 part) 110 *---------------------------------------------------------------------------*/ 111 u16 OS_GetTickLo(void); 112 113 114 /*---------------------------------------------------------------------------* 115 Name: OS_SetTick 116 117 Description: set tick value 118 119 Arguments: count value of tick to be set 120 121 Returns: None 122 *---------------------------------------------------------------------------*/ 123 void OS_SetTick(OSTick count); 124 125 126 127 #ifdef __cplusplus 128 } /* extern "C" */ 129 #endif 130 131 /* NITRO_OS_TICK_H_ */ 132 #endif 133