Get the user timer working properly consequentially fixing doom without a hack.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15510 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Karl Kurbjun 2007-11-07 05:30:31 +00:00
parent 22e3d56940
commit 5db6b51759
5 changed files with 48 additions and 51 deletions

View file

@ -87,7 +87,7 @@ void doomtime(void)
int I_GetTime (void)
{
#if defined(HAVE_LCD_COLOR) && !defined(TOSHIBA_GIGABEAT_F) && !defined(SIMULATOR) && !defined(RB_PROFILE)
#if defined(HAVE_LCD_COLOR) && !defined(SIMULATOR) && !defined(RB_PROFILE)
return doomtimer;
#else
#if HZ==100

View file

@ -109,6 +109,7 @@ void mrdebug(void)
touchpad_calibrate_screen();
use_calibration(true);
#endif
while(true)
{
#if 0
@ -144,14 +145,14 @@ void mrdebug(void)
// tsc2100_read_values(&x, &y, &z1, &z2);
// printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2);
// printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff);
// printf("current tick: %04x", current_tick);
// printf("Address: 0x%08x Data: 0x%08x", address, *address);
// printf("Address: 0x%08x Data: 0x%08x", address+1, *(address+1));
// printf("Address: 0x%08x Data: 0x%08x", address+2, *(address+2));
printf("current tick: %04x", current_tick);
printf("Address: 0x%08x Data: 0x%08x", address, *address);
printf("Address: 0x%08x Data: 0x%08x", address+1, *(address+1));
printf("Address: 0x%08x Data: 0x%08x", address+2, *(address+2));
// // tsc2100_keyclick(); /* doesnt work :( */
// line -= 6;
// }
#if 1
#if 0
if (button&BUTTON_TOUCHPAD)
{
if (button&BUTTON_REL)

View file

@ -32,7 +32,7 @@ void tick_start(unsigned int interval_in_ms)
/* Setup the Prescalar (Divide by 10)
* Based on linux/include/asm-arm/arch-integrator/timex.h
*/
IO_TIMER1_TMPRSCL = 0x000A;
IO_TIMER1_TMPRSCL = 0x0009;
/* Setup the Divisor */
IO_TIMER1_TMDIV = (TIMER_FREQ / (10*1000))*interval_in_ms;

View file

@ -169,6 +169,10 @@ void system_init(void)
IO_INTC_ENTRY_TBA0 = 0;
IO_INTC_ENTRY_TBA1 = 0;
/* Turn off other timers */
IO_TIMER2_TMMD = CONFIG_TIMER2_TMMD_STOP;
IO_TIMER3_TMMD = CONFIG_TIMER3_TMMD_STOP;
/* set GIO26 (reset pin) to output and low */
IO_GIO_BITCLR1=(1<<10);

View file

@ -32,6 +32,39 @@ void TIMER0(void)
IO_INTC_IRQ0 |= 1<<IRQ_TIMER0;
}
bool __timer_set(long cycles, bool start)
{
int oldlevel;
unsigned int divider=cycles, prescaler=0;
if(cycles<1)
return false;
IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_STOP;
if (start && pfn_unregister != NULL)
{
pfn_unregister();
pfn_unregister = NULL;
}
oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
/* Increase prescale values starting from 0 to make the cycle count fit */
while(divider>65535 && prescaler<1024)
{
prescaler++;
divider=cycles/(prescaler+1);
}
IO_TIMER0_TMPRSCL = prescaler;
IO_TIMER0_TMDIV = divider;
set_irq_level(oldlevel);
return true;
}
static void stop_timer(void)
{
IO_INTC_EINT0 &= ~(1<<IRQ_TIMER0);
@ -41,61 +74,20 @@ static void stop_timer(void)
IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_STOP;
}
bool __timer_set(long cycles, bool start)
{
int oldlevel;
unsigned int divider;
/* taken from linux/arch/arm/mach-itdm320-20/time.c and timer-meg-fx.c */
/* Turn off all timers */
IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_STOP;
IO_TIMER1_TMMD = CONFIG_TIMER1_TMMD_STOP;
IO_TIMER2_TMMD = CONFIG_TIMER2_TMMD_STOP;
IO_TIMER3_TMMD = CONFIG_TIMER3_TMMD_STOP;
/* Find the minimum factor that puts the counter in range 1-65535 */
unsigned int prescaler = (cycles + 65534) / 65535;
/* Test this by writing 1's to registers to see how many bits we have */
/* Maximum divider setting is x / 1024 / 65536 = x / 67108864 */
if (start && pfn_unregister != NULL)
{
pfn_unregister();
pfn_unregister = NULL;
}
oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
/* Max prescale is 1023+1 */
for (divider = 0; prescaler > 1024; prescaler >>= 1, divider++);
/* Setup the Prescalar */
IO_TIMER0_TMPRSCL = prescaler;
/* Setup the Divisor */
IO_TIMER0_TMDIV = divider;
set_irq_level(oldlevel);
return true;
}
bool __timer_register(void)
{
bool retval = true;
int oldstatus = set_interrupt_status(IRQ_FIQ_DISABLED, IRQ_FIQ_STATUS);
stop_timer();
/* Turn Timer0 to Free Run mode */
IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_FREE_RUN;
IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_FREE_RUN;
IO_INTC_EINT0 |= 1<<IRQ_TIMER0;
IO_INTC_EINT0 |= 1<<IRQ_TIMER0;
set_interrupt_status(oldstatus, IRQ_FIQ_STATUS);
return retval;
return true;
}
void __timer_unregister(void)