+ // PL031 RTC
+ gTime_PL031 = MM_MapHWPages(PL031_BASE, 1);
+ //IRQ_AddHandler(PL031_IRQ, Time_int_RTCIRQHandler, NULL);
+ gTime_PL031->IMSC = 1;
+ gTime_PL031->ICR = 1;
+// giTimestamp = (Uint64)gTime_PL031->DR * 1000;
+
+ // SP804 Timer (Contains two basic ARM timers, each at 1MHz base)
+ gTime_SP804 = MM_MapHWPages(SP804_BASE, 1);
+ // - Use the first to maintain the system clock
+ gTime_SP804->Timers[0].Load = TICKS_PER_IRQ;
+ // > Enable,Periodic,IE,Div=1,32bit
+ gTime_SP804->Timers[0].Control = (1<<7)|(1<<6)|(1<<5)|(DIVISOR_ENC<<2)|(1<<1);
+ IRQ_AddHandler(SP805_IRQ, Time_int_TimerIRQHandler, NULL);
+ gTime_SP804->Timers[0].CIS = 1;
+ // - TODO: use the second for short events (and use RTC for long events)
+}
+
+tTime Time_GetTickOffset(void)
+{
+ if( !gTime_SP804 )
+ return 0;
+ // Want count of ms since last tick
+ return (giTime_PartMS + gTime_SP804->Timers[0].Value) / TICKS_PER_MS;