2 * Acess2 Kernel ARMv7 Port
3 * - By John Hodge (thePowersGang)
5 * platform_realviewpb.c
6 * - RealviewPB core code
11 extern tTime giTimestamp;
14 void Time_Setup(void); // TODO: Should be in header
15 void Time_int_RTCIRQHandler(int IRQ, void *unused);
16 void Time_int_TimerIRQHandler(int IRQ, void *unused);
17 tTime Time_GetTickOffset(void); // TODO: Should be in header
22 tPAddr gGIC_DistributorAddr = 0x1e001000;
23 tPAddr gGIC_InterfaceAddr = 0x1e000000;
26 #define DIVISOR_REAL (1 << (4*DIVISOR_ENC))
27 #define TICKS_PER_SECOND (1000000/DIVISOR_REAL)
28 #define TICKS_PER_IRQ (TICKS_PER_SECOND/2) // Tick twice a second
29 #define TICKS_PER_MS (TICKS_PER_SECOND/1000)
30 #define MS_PER_IRQ (TICKS_PER_IRQ*1000/TICKS_PER_SECOND) // (TICKS_PER_IRQ/(TICKS_PER_SECOND/1000))
31 #define PART_PER_IRQ (TICKS_PER_IRQ%(TICKS_PER_SECOND/1000)) // (TICKS_PER_IRQ%(TICKS_PER_SECOND/1000))
34 #define PL031_BASE 0x10017000
47 #define SP804_BASE 0x10011000
63 void Time_int_RTCIRQHandler(int IRQ, void *unused)
65 if( !(gTime_PL031->IS & 1) ) {
68 gTime_PL031->ICR = 1; // Clear interrupt
69 // giTimestamp = (Uint64)gTime_PL031->DR * 1000 - giTimeBase;
72 void Time_int_TimerIRQHandler(int IRQ, void *unused)
74 if( !(gTime_SP804->Timers[0].RIS) ) {
77 gTime_SP804->Timers[0].CIS = 1;
78 giTime_PartMS += PART_PER_IRQ;
79 giTimestamp += MS_PER_IRQ;
80 while( giTime_PartMS > TICKS_PER_MS ) {
81 giTime_PartMS -= TICKS_PER_MS;
89 gTime_PL031 = MM_MapHWPages(PL031_BASE, 1);
90 //IRQ_AddHandler(PL031_IRQ, Time_int_RTCIRQHandler, NULL);
91 gTime_PL031->IMSC = 1;
93 // giTimestamp = (Uint64)gTime_PL031->DR * 1000;
95 // SP804 Timer (Contains two basic ARM timers, each at 1MHz base)
96 gTime_SP804 = MM_MapHWPages(SP804_BASE, 1);
97 // - Use the first to maintain the system clock
98 gTime_SP804->Timers[0].Load = TICKS_PER_IRQ;
99 // > Enable,Periodic,IE,Div=1,32bit
100 gTime_SP804->Timers[0].Control = (1<<7)|(1<<6)|(1<<5)|(DIVISOR_ENC<<2)|(1<<1);
101 IRQ_AddHandler(SP805_IRQ, Time_int_TimerIRQHandler, NULL);
102 gTime_SP804->Timers[0].CIS = 1;
103 // - TODO: use the second for short events (and use RTC for long events)
106 tTime Time_GetTickOffset(void)
110 // Want count of ms since last tick
111 return (giTime_PartMS + gTime_SP804->Timers[0].Value) / TICKS_PER_MS;