00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00040
00041 #ifndef NDS_TIMERS_INCLUDE
00042 #define NDS_TIMERS_INCLUDE
00043
00044
00045
00046
00047 #ifdef __cplusplus
00048 extern "C" {
00049 #endif
00050
00051
00052
00053 #include <nds/ndstypes.h>
00054 #include <nds/linkedlist.h>
00055
00065 typedef enum {
00066 ClockDivider_1 = 0,
00067 ClockDivider_64 = 1,
00068 ClockDivider_256 = 2,
00069 ClockDivider_1024 = 3
00070 }ClockDivider;
00071
00072
00073
00074
00083 void timerStart(int channel, ClockDivider divider, u16 ticks, fp callback);
00084
00085
00091 u16 timerElapsed(int channel);
00092
00093
00094 static inline u16 timerFreqToTicks_1(int freq) {return -0x2000000 / freq;}
00095 static inline u16 timerFreqToTicks_64(int freq) {return (-0x2000000 >> 6) / freq;}
00096 static inline u16 timerFreqToTicks_256(int freq) {return (-0x2000000 >> 8) / freq;}
00097 static inline u16 timerFreqToTicks_1024(int freq) {return (-0x2000000 >> 10) / freq;}
00098
00104
00105
00107
00124 #define TIMER_FREQ(n) (-0x2000000/(n))
00125
00127
00144 #define TIMER_FREQ_64(n) (-(0x2000000>>6)/(n))
00145
00147
00163 #define TIMER_FREQ_256(n) (-(0x2000000>>8)/(n))
00164
00166
00182 #define TIMER_FREQ_1024(n) (-(0x2000000>>10)/(n))
00183
00184
00186 #define TIMER0_DATA (*(vuint16*)0x04000100)
00187
00188 #define TIMER1_DATA (*(vuint16*)0x04000104)
00189
00190 #define TIMER2_DATA (*(vuint16*)0x04000108)
00191
00192 #define TIMER3_DATA (*(vuint16*)0x0400010C)
00193
00195
00206 #define TIMER_DATA(n) (*(vuint16*)(0x04000100+((n)<<2)))
00207
00208
00210 #define TIMER0_CR (*(vuint16*)0x04000102)
00211
00212 #define TIMER1_CR (*(vuint16*)0x04000106)
00213
00214 #define TIMER2_CR (*(vuint16*)0x0400010A)
00215
00216 #define TIMER3_CR (*(vuint16*)0x0400010E)
00217
00219
00230 #define TIMER_CR(n) (*(vuint16*)(0x04000102+((n)<<2)))
00231
00233 #define TIMER_ENABLE (1<<7)
00234
00236 #define TIMER_IRQ_REQ (1<<6)
00237
00239 #define TIMER_CASCADE (1<<2)
00240
00242 #define TIMER_DIV_1 (0)
00243
00244 #define TIMER_DIV_64 (1)
00245
00246 #define TIMER_DIV_256 (2)
00247
00248 #define TIMER_DIV_1024 (3)
00249
00255 static inline void timerStop(int channel){TIMER_CR(channel) &= ~TIMER_ENABLE;}
00256
00263 void cpuStartTiming(u32 timer);
00264
00269 u32 cpuEndTiming();
00270
00271
00272 #ifdef __cplusplus
00273 }
00274 #endif
00275
00276
00277
00278 #endif
00279
00280