From 57d19df30de0cf2223bf54b51bf613e26e638e2e Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Wed, 25 Sep 2019 11:29:09 -0700 Subject: [PATCH] Update TPS65010, fix T3 overclocking method --- bugs/currentBug.txt | 1 + bugs/regressions.txt | 3 -- bugs/unimplementedHardware.txt | 2 + src/pxa260/pxa260.c | 13 +++--- src/pxa260/pxa260Accessors.c.h | 1 + src/pxa260/pxa260Timing.c | 6 +-- src/tps65010.c | 74 +++++++++++++++++++++++++++++----- src/tps65010.h | 1 + src/tsc2101.c | 18 ++++----- src/tsc2101.h | 2 +- 10 files changed, 88 insertions(+), 33 deletions(-) create mode 100644 bugs/currentBug.txt delete mode 100644 bugs/regressions.txt diff --git a/bugs/currentBug.txt b/bugs/currentBug.txt new file mode 100644 index 0000000..596c425 --- /dev/null +++ b/bugs/currentBug.txt @@ -0,0 +1 @@ +T3 locks up endlessly checking TSC2101 interrupts \ No newline at end of file diff --git a/bugs/regressions.txt b/bugs/regressions.txt deleted file mode 100644 index b808fc4..0000000 --- a/bugs/regressions.txt +++ /dev/null @@ -1,3 +0,0 @@ -Fixed: -Endian compatibility is broken(the CPU state needs to be standardized) -RetroArch port crashes on exit(needed to check if environ_cb returned true, switched to libretro-common filestreams too) diff --git a/bugs/unimplementedHardware.txt b/bugs/unimplementedHardware.txt index 8419806..ed2134e 100644 --- a/bugs/unimplementedHardware.txt +++ b/bugs/unimplementedHardware.txt @@ -63,6 +63,8 @@ GPIO lines from misc chips to CPU are not implemented Fixed: +Endian compatibility is broken(the CPU state needs to be standardized) +RetroArch port crashes on exit(needed to check if environ_cb returned true, switched to libretro-common filestreams too) make the headers belong to the main file of the target chip being emulated for specs remove specs folder UART1 USTCNT1 diff --git a/src/pxa260/pxa260.c b/src/pxa260/pxa260.c index d8c55d5..d1ee1b6 100644 --- a/src/pxa260/pxa260.c +++ b/src/pxa260/pxa260.c @@ -23,6 +23,8 @@ #include "../armv5te/os/os.h" #include "../armv5te/translate.h" #include "../tungstenT3Bus.h" +#include "../tsc2101.h" +#include "../tps65010.h" #include "../emulator.h" @@ -190,7 +192,7 @@ void pxa260Reset(void){ pxa260TimingReset(); //set first timer event - pxa260TimingTriggerEvent(PXA260_TIMING_CALLBACK_TICK_CPU_TIMER, TUNGSTEN_T3_CPU_PLL_FREQUENCY / TUNGSTEN_T3_CPU_CRYSTAL_FREQUENCY * palmClockMultiplier); + pxa260TimingTriggerEvent(PXA260_TIMING_CALLBACK_TICK_CPU_TIMER, TUNGSTEN_T3_CPU_PLL_FREQUENCY / TUNGSTEN_T3_CPU_CRYSTAL_FREQUENCY); memset(&arm, 0, sizeof arm); arm.control = 0x00050078; @@ -226,14 +228,11 @@ void pxa260LoadState(uint8_t* data){ void pxa260Execute(bool wantVideo){ uint32_t index; + tsc2101UpdateInterrupt(); + tps65010UpdateInterrupt(); pxa260gpioUpdateKeyMatrix(&pxa260Gpio); - pxa260TimingRun(TUNGSTEN_T3_CPU_PLL_FREQUENCY / EMU_FPS * palmClockMultiplier); - //pxa260TimingRun(20000); - - //this needs to run at 3.6864 MHz - //for(index = 0; index < TUNGSTEN_T3_CPU_CRYSTAL_FREQUENCY / EMU_FPS; index++) - // pxa260timrTick(&pxa260Timer); + pxa260TimingRun(TUNGSTEN_T3_CPU_PLL_FREQUENCY / EMU_FPS); //render if(likely(wantVideo)) diff --git a/src/pxa260/pxa260Accessors.c.h b/src/pxa260/pxa260Accessors.c.h index 8ec2bfe..4e1377f 100644 --- a/src/pxa260/pxa260Accessors.c.h +++ b/src/pxa260/pxa260Accessors.c.h @@ -108,6 +108,7 @@ static void pxa260_io_write_word(uint32_t addr, uint32_t value){ static uint32_t pxa260_lcd_read_word(uint32_t addr){ uint32_t out; + pxa260lcdPrvMemAccessF(&pxa260Lcd, addr, 4, false, &out); debugLog("32 bit PXA260 LCD register read:0x%08X\n", addr); return out; diff --git a/src/pxa260/pxa260Timing.c b/src/pxa260/pxa260Timing.c index 3a4270a..d703c16 100644 --- a/src/pxa260/pxa260Timing.c +++ b/src/pxa260/pxa260Timing.c @@ -80,7 +80,7 @@ void pxa260TimingRun(int32_t cycles){ keepRunning: addCycles = pxa260TimingGetDurationUntilNextEvent(cycles); - cycle_count_delta = -addCycles; + cycle_count_delta = -addCycles * palmClockMultiplier; while (!exiting && cycle_count_delta < 0) { if (cpu_events & (EVENT_FIQ | EVENT_IRQ)) { @@ -105,7 +105,7 @@ void pxa260TimingRun(int32_t cycles){ } //if more then the requested cycles are executed count those too - addCycles += cycle_count_delta; + addCycles += cycle_count_delta / palmClockMultiplier; //remove the unused cycles addCycles -= pxa260TimingLeftoverCycles; @@ -133,5 +133,5 @@ void pxa260TimingRun(int32_t cycles){ void pxa260TimingTickCpuTimer(void){ pxa260timrTick(&pxa260Timer); - pxa260TimingTriggerEvent(PXA260_TIMING_CALLBACK_TICK_CPU_TIMER, TUNGSTEN_T3_CPU_PLL_FREQUENCY / TUNGSTEN_T3_CPU_CRYSTAL_FREQUENCY * palmClockMultiplier); + pxa260TimingTriggerEvent(PXA260_TIMING_CALLBACK_TICK_CPU_TIMER, TUNGSTEN_T3_CPU_PLL_FREQUENCY / TUNGSTEN_T3_CPU_CRYSTAL_FREQUENCY); } diff --git a/src/tps65010.c b/src/tps65010.c index b9132a6..380d400 100644 --- a/src/tps65010.c +++ b/src/tps65010.c @@ -37,9 +37,60 @@ static uint8_t tps65010State; static bool tps65010SelectedRegisterAlreadySet; +static uint8_t tps65010ReadRegister(uint8_t address){ + switch(address){ + /* + case ACKINT1: + case ACKINT2: + //TODO: dont know proper behavior, datasheet says the CPU shouldnt need to access this + //should probably clear the ints + return 0x00; + + case DEFGPIO: + //TODO: read GPIO state + return tps65010Registers[DEFGPIO]; + */ + + case CHGSTATUS: + case REGSTATUS: + case MASK1: + case MASK2: + case CHGCONFIG: + case LED1_ON: + case LED1_PER: + case LED2_ON: + case LED2_PER: + case VDCDC1: + case VDCDC2: + case VREGS1: + case MASK3: + //simple read, no actions needed + return tps65010Registers[address]; + + default: + debugLog("Unimplemented TPS65010 register read, address:0x%02X\n", address); + return 0x00; + } +} + static void tps65010WriteRegister(uint8_t address, uint8_t value){ - //TODO: add register writes - debugLog("Unimplemented TPS65010 register write, address:0x%02X, value:0x%02X\n", address, value); + switch(address){ + /* + case MASK3: + tps65010Registers[address] = value; + debugLog("TPS65010 MASK3 write, value:0x%02X\n", value); + return; + + case DEFGPIO: + tps65010Registers[address] = value; + debugLog("TPS65010 DEFGPIO write, value:0x%02X\n", value); + return; + */ + + default: + debugLog("Unimplemented TPS65010 register write, address:0x%02X, value:0x%02X\n", address, value); + return; + } } void tps65010Reset(void){ @@ -88,13 +139,12 @@ uint8_t tps65010I2cExchange(uint8_t i2cBus){ return I2C_FLOATING_BUS; } - tps65010CurrentI2cByte <<= 1; - tps65010CurrentI2cByte |= (i2cBus == I2C_1); - if(tps65010State == I2C_SENDING){ - if(tps65010SelectedRegister < 0x11) - newI2cBus = (tps65010Registers[tps65010SelectedRegister] & 1 << (tps65010CurrentI2cByteBitsRemaining - 1)) ? I2C_1 : I2C_0; - else - newI2cBus = I2C_0; + if(tps65010State != I2C_SENDING){ + tps65010CurrentI2cByte <<= 1; + tps65010CurrentI2cByte |= (i2cBus == I2C_1); + } + else{ + newI2cBus = (tps65010CurrentI2cByte & 1 << (tps65010CurrentI2cByteBitsRemaining - 1)) ? I2C_1 : I2C_0; } tps65010CurrentI2cByteBitsRemaining--; @@ -106,7 +156,7 @@ uint8_t tps65010I2cExchange(uint8_t i2cBus){ //the address is of this device tps65010State = (tps65010CurrentI2cByte & 0x01) ? I2C_SENDING : I2C_RECEIVING; if(tps65010State == I2C_SENDING) - debugLog("TPS65010 reading register:address:0x%02X\n", tps65010SelectedRegister); + tps65010CurrentI2cByte = tps65010ReadRegister(tps65010SelectedRegister); } else{ tps65010State = I2C_NOT_SELECTED; @@ -138,3 +188,7 @@ uint8_t tps65010I2cExchange(uint8_t i2cBus){ return newI2cBus; } + +void tps65010UpdateInterrupt(void){ + //TODO: implement this +} diff --git a/src/tps65010.h b/src/tps65010.h index c7abe37..1227f3e 100644 --- a/src/tps65010.h +++ b/src/tps65010.h @@ -9,5 +9,6 @@ void tps65010SaveState(uint8_t* data); void tps65010LoadState(uint8_t* data); uint8_t tps65010I2cExchange(uint8_t i2cBus); +void tps65010UpdateInterrupt(void);//called when buttons are refreshed or an SD card is inserted #endif diff --git a/src/tsc2101.c b/src/tsc2101.c index 0dfbec0..3f2c28f 100644 --- a/src/tsc2101.c +++ b/src/tsc2101.c @@ -192,7 +192,7 @@ static void tsc2101ResetRegisters(void){ tsc2101Registers[TOUCH_CONTROL_REFERENCE] = 0x0002; //currenly at register 0x5 of touch control - tsc2101RefreshInterrupt(); + tsc2101UpdateInterrupt(); } static uint16_t tsc2101RegisterRead(uint8_t page, uint8_t address){ @@ -241,7 +241,7 @@ static uint16_t tsc2101RegisterRead(uint8_t page, uint8_t address){ case TOUCH_DATA_TEMP2: debugLog("TSC2101 read ADC data register:%d\n", combinedRegisterNumber); tsc2101HasNewData &= ~(1 << combinedRegisterNumber); - tsc2101RefreshInterrupt();//clearing the new data bit could trigger an interrupt + tsc2101UpdateInterrupt();//clearing the new data bit could trigger an interrupt return tsc2101Registers[combinedRegisterNumber]; default: @@ -264,7 +264,7 @@ static void tsc2101RegisterWrite(uint8_t page, uint8_t address, uint16_t value){ case TOUCH_CONTROL_STATUS: tsc2101Registers[TOUCH_CONTROL_STATUS] = value & 0xC000; - tsc2101RefreshInterrupt();//interrupt type might have changed + tsc2101UpdateInterrupt();//interrupt type might have changed return; case TOUCH_CONTROL_BUFFER_MODE: @@ -272,7 +272,7 @@ static void tsc2101RegisterWrite(uint8_t page, uint8_t address, uint16_t value){ tsc2101BufferFifoFlush(); tsc2101Registers[TOUCH_CONTROL_BUFFER_MODE] = value & 0xF800; - tsc2101RefreshInterrupt();//need to refresh innterupt because the trigger level may have changed + tsc2101UpdateInterrupt();//need to refresh innterupt because the trigger level may have changed return; case TOUCH_CONTROL_REFERENCE: @@ -289,7 +289,7 @@ static void tsc2101RegisterWrite(uint8_t page, uint8_t address, uint16_t value){ //TODO: TOUCH_CONTROL_CONFIGURATION SWPDTD bit debugLog("TSC2101 config register writes not fully implemented\n"); tsc2101Registers[TOUCH_CONTROL_CONFIGURATION] = value & 0x007F; - tsc2101RefreshInterrupt(); + tsc2101UpdateInterrupt(); return; case TOUCH_CONTROL_TEMPERATURE_MAX: @@ -299,12 +299,12 @@ static void tsc2101RegisterWrite(uint8_t page, uint8_t address, uint16_t value){ case TOUCH_CONTROL_AUX2_MAX: case TOUCH_CONTROL_AUX2_MIN: tsc2101Registers[combinedRegisterNumber] = value & 0x1FFF; - tsc2101RefreshInterrupt(); + tsc2101UpdateInterrupt(); return; case TOUCH_CONTROL_MEASUREMENT_CONFIGURATION: tsc2101Registers[TOUCH_CONTROL_MEASUREMENT_CONFIGURATION] = value & 0xFE04; - tsc2101RefreshInterrupt(); + tsc2101UpdateInterrupt(); return; case TOUCH_DATA_X: @@ -439,7 +439,7 @@ bool tsc2101ExchangeBit(bool bit){ return output; } -void tsc2101RefreshInterrupt(void){ +void tsc2101UpdateInterrupt(void){ debugLog("TSC2101 PINTDAV not fully implemented\n"); //check if PINTDAV is data or pen and data interrupt @@ -635,6 +635,6 @@ void tsc2101Scan(void){ else tsc2101Registers[TOUCH_CONTROL_TSC_ADC] &= 0xC3FF; - tsc2101RefreshInterrupt(); + tsc2101UpdateInterrupt(); } diff --git a/src/tsc2101.h b/src/tsc2101.h index 57b9d02..f8b34d0 100644 --- a/src/tsc2101.h +++ b/src/tsc2101.h @@ -12,7 +12,7 @@ void tsc2101LoadState(uint8_t* data); void tsc2101SetPwrDn(bool value); void tsc2101SetChipSelect(bool value); bool tsc2101ExchangeBit(bool bit); -void tsc2101RefreshInterrupt(void);//called after touchscreen update to flush the values +void tsc2101UpdateInterrupt(void);//called after touchscreen update to flush the values //TODO: this chip seems to do audio output, need to add a 16bit optimized transfer function void tsc2101Scan(void);