1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - OS - include
3 File: timer.h
4
5 Copyright 2003-2008 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:: 2008-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 #ifndef NITRO_OS_TIMER_H_
19 #define NITRO_OS_TIMER_H_
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #include <nitro/misc.h>
26 #include <nitro/types.h>
27 #ifdef SDK_NITRO
28 #include <nitro/ioreg.h>
29 #else
30 #include <twl/ioreg.h>
31 #endif
32
33 //----------------------------------------------------------------------
34 //---- pre-scaler
35 typedef enum
36 {
37 OS_TIMER_PRESCALER_1 = (0UL << REG_OS_TM0CNT_H_PS_SHIFT), // x 1
38 OS_TIMER_PRESCALER_64 = (1UL << REG_OS_TM0CNT_H_PS_SHIFT), // x 64
39 OS_TIMER_PRESCALER_256 = (2UL << REG_OS_TM0CNT_H_PS_SHIFT), // x 256
40 OS_TIMER_PRESCALER_1024 = (3UL << REG_OS_TM0CNT_H_PS_SHIFT) // x 1024
41 }
42 OSTimerPrescaler;
43
44 //---- timer number
45 typedef enum
46 {
47 OS_TIMER_0 = 0,
48 OS_TIMER_1 = 1,
49 OS_TIMER_2 = 2,
50 OS_TIMER_3 = 3
51 }
52 OSTimer;
53
54 //---- timer number ( if use 32 bit timer )
55 typedef enum
56 {
57 OS_TIMER32_01 = 0,
58 OS_TIMER32_12 = 1,
59 OS_TIMER32_23 = 2
60 }
61 OSTimer32;
62
63 //---- timer number ( if use 48 bit timer )
64 typedef enum
65 {
66 OS_TIMER48_012 = 0,
67 OS_TIMER48_123 = 1
68 }
69 OSTimer48;
70
71 //================================================================================
72 // TIMER
73 //================================================================================
74 /*---------------------------------------------------------------------------*
75 Name: OS_SetTimerCount
76
77 Description: set timer count
78
79 Arguments: id timerNo
80 count count value to be set to timer
81
82 Returns: None
83 *---------------------------------------------------------------------------*/
OS_SetTimerCount(OSTimer id,u16 count)84 static inline void OS_SetTimerCount(OSTimer id, u16 count)
85 {
86 SDK_ASSERT(OS_TIMER_0 <= id && id <= OS_TIMER_3);
87 *((REGType16 *)((u32)REG_TM0CNT_L_ADDR + id * 4)) = count;
88 }
89
90 /*---------------------------------------------------------------------------*
91 Name: OS_SetTimerControl
92
93 Description: set timer control
94
95 Arguments: id timerNo
96 control control value to be set to timer
97
98 Returns: None
99 *---------------------------------------------------------------------------*/
OS_SetTimerControl(OSTimer id,u16 control)100 static inline void OS_SetTimerControl(OSTimer id, u16 control)
101 {
102 SDK_ASSERT(OS_TIMER_0 <= id && id <= OS_TIMER_3);
103 *((REGType16 *)((u32)REG_TM0CNT_H_ADDR + id * 4)) = control;
104 }
105
106 /*---------------------------------------------------------------------------*
107 Name: OS_StartTimer
108
109 Description: set timer(s) and start
110
111 Arguments: id timerNo
112 count count value to be set to timer
113 preScale preScale
114
115 Returns: None
116 *---------------------------------------------------------------------------*/
117 //
118 // use 1 timer, 16bit counter, timer<id> interrupt occurs by overflow
119 //
120 void OS_StartTimer(OSTimer id, u16 count, OSTimerPrescaler preScale);
121 //
122 // use 2 timers, 32bit counter, timer<id+1> interrupt occurs by overflow
123 //
124 void OS_StartTimer32(OSTimer32 id, u32 count, OSTimerPrescaler preScale);
125 //
126 // use 3 timers, 48bit counter, timer<id+2> interrupt occurs by overflow
127 //
128 void OS_StartTimer48(OSTimer48 id, u64 count, OSTimerPrescaler preScale);
129 //
130 // use all 4 timers, 64bit counter, timer3 interrupt occurs by overflow
131 //
132 void OS_StartTimer64(u64 count, OSTimerPrescaler preScale);
133
134
135 /*---------------------------------------------------------------------------*
136 Name: OS_StopTimer
137
138 Description: stop timer(s)
139
140 Arguments: id timerNo
141
142 Returns: None
143 *---------------------------------------------------------------------------*/
144 //
145 // stop a timer
146 //
147 void OS_StopTimer(OSTimer id);
148 //
149 // stop 2 timers
150 //
151 void OS_StopTimer32(OSTimer32 id);
152 //
153 // stop 3 timers
154 //
155 void OS_StopTimer48(OSTimer48 id);
156 //
157 // stop all 4 timers
158 //
159 void OS_StopTimer64(void);
160
161
162 #ifdef __cplusplus
163 } /* extern "C" */
164 #endif
165
166 /* NITRO_OS_TIMER_H_ */
167 #endif
168