CPU Frequency
From wiki.gp2x.org
You use the IO-registers as usual to set the CPU. The setting bit below was more or less taken from sdk2x.
void hw_set_cpu(int speed) { int m = 0; // Calculating the FPLL value from frequency is a bit complex // so we just use some known-to-work values instead. switch(speed) { case 250: m = 0x5D04; break; case 225: m = 0x5304; break; case 200: m = 0x4904; break; case 175: m = 0x3F04; break; case 150: m = 0x4901; break; case 125: m = 0x3c01; break; case 100: m = 0x6502; break; case 75: m = 0x4902; break; case 50: m = 0x6503; break; } if(m) { // Get interupt flags unsigned int l = memregs32[0x808>>2]; // Turn off interrupts memregs32[0x808>>2] = 0xFF8FFFE7; // Set new clock frequency memregs16[0x910>>1]=m; // Wait for it to take while(memregs16[0x0902>>1] & 1); // Turn on interrupts again memregs32[0x808>>2] = l; } }
This routine seems to work for every clockspeed.
#define SYS_CLK_FREQ 7372800 void SetClock(unsigned int MHZ) { #ifdef GP2X unsigned int v; unsigned int mdiv,pdiv=3,scale=0; MHZ*=1000000; mdiv=(MHZ*pdiv)/SYS_CLK_FREQ; mdiv=((mdiv-8)<<8) & 0xff00; pdiv=((pdiv-2)<<2) & 0xfc; scale&=3; v = mdiv | pdiv | scale; unsigned int l = memregs32[0x808>>2];// Get interupt flags memregs32[0x808>>2] = 0xFF8FFFE7; //Turn off interrupts memregs16[0x910>>1]=v; //Set frequentie while(memregs16[0x0902>>1] & 1); //Wait for the frequentie to be ajused memregs32[0x808>>2] = l; //Turn on interrupts #endif }
To appropriately set memregs16 and memregs32, see GPIO Programming Example.