ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
time.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2005, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
16 #include <time.h>
17 #include <kernel.h>
18 #include <timer.h>
19 #include "ps2sdkapi.h"
20 
21 extern int __time_intr_overflow_id;
23 
24 #ifdef TIME_USE_T0
25 #define INTC_TIM INTC_TIM0
26 #define T_COUNT T0_COUNT
27 #define T_MODE T0_MODE
28 #define T_COMP T0_COMP
29 #else
30 #define INTC_TIM INTC_TIM1
31 #define T_COUNT T1_COUNT
32 #define T_MODE T1_MODE
33 #define T_COMP T1_COMP
34 #endif
35 
36 #ifdef F___time_internals
39 
40 static int intrOverflow(int ca)
41 {
43 
44  // A write to the overflow flag will clear the overflow flag
45  // ---------------------------------------------------------
46  *T_MODE |= (1 << 11);
47 
48  ExitHandler();
49  return -1;
50 }
51 
52 void _ps2sdk_time_init(void)
53 {
54  *T_MODE = 0x0000; // Disable T_MODE
55 
56  if (__time_intr_overflow_id == -1)
57  {
60  }
61 
62  // Initialize the timer registers
63  // CLKS: 0x02 - 1/256 of the BUSCLK (0x01 is 1/16th)
64  // CUE: 0x01 - Start/Restart the counting
65  // OVFE: 0x01 - An interrupt is generated when an overflow occurs
66  *T_COUNT = 0;
67  *T_MODE = Tn_MODE(0x02, 0, 0, 0, 0, 0x01, 0, 0x01, 0, 0);
68 
70 }
71 
72 void _ps2sdk_time_deinit(void)
73 {
74  *T_MODE = 0x0000; // Stop the timer
75 
76  if (__time_intr_overflow_id >= 0)
77  {
81  }
82 
84 }
85 #endif
86 
87 #ifdef F_ps2_clock
89 {
90  ps2_clock_t t;
91 
92  // Tn_COUNT is 16 bit precision. Therefore, each __time_intr_overflow_count is 65536 ticks
93  t = *T_COUNT + (__time_intr_overflow_count << 16);
94 
95  return t;
96 }
97 #endif
98 
void _ps2sdk_time_init()
void _ps2sdk_time_deinit()
#define ExitHandler()
Definition: kernel.h:28
int EnableIntc(int intc)
int DisableIntc(int intc)
s32 RemoveIntcHandler(s32 cause, s32 handler_id)
s32 AddIntcHandler(s32 cause, s32(*handler_func)(s32 cause), s32 next)
uint64_t ps2_clock_t
Definition: ps2sdkapi.h:41
ps2_clock_t ps2_clock(void)
#define INTC_TIM
Definition: time.c:30
ps2_clock_t __time_intr_overflow_count
int __time_intr_overflow_id
#define T_MODE
Definition: time.c:32
#define T_COUNT
Definition: time.c:31
#define Tn_MODE(CLKS, GATE, GATS, GATM, ZRET, CUE, CMPE, OVFE, EQUF, OVFF)
Definition: timer.h:42