GP32 Gp_setcpuspeed


M-.-n

Member
Joined
May 28, 2005
Messages
160
Location
Brussels, Belgium
Website
discodirt.10pm.org
I'm kind of puzzled but the gp_SetCpuspeed().. what does it do exactly ? Make the GP32 run at different speed.. that seems wierd.

Can anybody shed some light on what it is exactly ? I hate stuff I don't understand :)

Thanks !
 
Yes gp_SetCpuspeed() allows you to control the speed of the GP32's cpu. It can be called at any point but you need to re-init the display/audio drivers afterwards as changing the cpu speed effects the timing of these devices.

The thing to remember is the faster your GP32 is running the more battery power it will use up.
 
that is so wierd... so programs let the user choose to which CPUspeed they wanna run ? or do u hardcode it ?

They can do both, it depends on the application in question. In emulators the users are given a choice on what cpu speed to use. They can use higher cpu speeds to give better fps but at a cost of battery life. Or they can choose a lower cpu speed and have the batteries last longer.

In the end it all comes down to how much you want the batteries to last.
 
Last edited by a moderator:
Here is the code for the Gp_setcpuspeed routine:
Code:
/*
 * CPU setup - gp_cpuspeed.c
 *
 * Copyright (C) 2003,2004 Mirko Roller <mirko@mirkoroller.de>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Changelog:
 *
 *  21 Aug 2004 - Mirko Roller <mirko@mirkoroller.de>
 *   first release 
 *
 */


/*
MCLK is the main clock for the CPU                (160Mhz maximum)
HCLK is the clock for the system bus (SDRAM LCD)  (133Mhz maximum)
PCLK is the clock for the peripherals (UARTs, SMC, IIS, timers etc) (66Mhz maximum)

The values for clk_mode are:
0 HCLK = MCLK,     PCLK = MCLK
1 HCLK = MCLK,     PCLK = MCLK / 2
2 HCLK = MCLK / 2, PCLK = MCLK / 2
3 HCLK = MCLK / 2, PCLK = MCLK / 4
*/

void gp_initButton();
void _cpu_speed(int MCLK,int CLKDIV,int CLKMODE);


// 40Mhz mode
static int CLKDIV =0x48013;
static int MCLK   =40000000;
static int CLKMODE=0;
static int HCLK   =40000000;
static int PCLK   =40000000;

int gp_getPCLK(){
   return PCLK;
}

int gp_getHCLK(){
   return HCLK;
}

void gp_setCpuspeed(int freq) {
  switch (freq) {
     // overclocking 
     case 168: { CLKDIV=0x14000; MCLK=168000000; CLKMODE=3; break;}
     case 172: { CLKDIV=0x23010; MCLK=172000000; CLKMODE=3; break;}
     case 176: { CLKDIV=0x24010; MCLK=176000000; CLKMODE=3; break;}
     case 180: { CLKDIV=0x16000; MCLK=180000000; CLKMODE=3; break;}
     case 184: { CLKDIV=0x26010; MCLK=184000000; CLKMODE=3; break;}
     case 188: { CLKDIV=0x27010; MCLK=188000000; CLKMODE=3; break;}
     case 192: { CLKDIV=0x18000; MCLK=192000000; CLKMODE=3; break;}
     case 196: { CLKDIV=0x29010; MCLK=196000000; CLKMODE=3; break;}
     case 200: { CLKDIV=0x2A010; MCLK=200000000; CLKMODE=3; break;}
     case 204: { CLKDIV=0x2b010; MCLK=204000000; CLKMODE=3; break;}
     case 208: { CLKDIV=0x2c010; MCLK=208000000; CLKMODE=3; break;}
     case 212: { CLKDIV=0x2d010; MCLK=212000000; CLKMODE=3; break;}
     case 216: { CLKDIV=0x2e010; MCLK=216000000; CLKMODE=3; break;}
     case 220: { CLKDIV=0x2f010; MCLK=220000000; CLKMODE=3; break;}
     case 224: { CLKDIV=0x30010; MCLK=224000000; CLKMODE=3; break;}
     case 228: { CLKDIV=0x1e000; MCLK=228000000; CLKMODE=3; break;}
     case 232: { CLKDIV=0x32010; MCLK=232000000; CLKMODE=3; break;}
     case 236: { CLKDIV=0x33010; MCLK=236000000; CLKMODE=3; break;}
     case 240: { CLKDIV=0x20000; MCLK=240000000; CLKMODE=3; break;}
     case 244: { CLKDIV=0x35010; MCLK=244000000; CLKMODE=3; break;}
     case 248: { CLKDIV=0x36010; MCLK=248000000; CLKMODE=3; break;}
     case 252: { CLKDIV=0x22000; MCLK=252000000; CLKMODE=3; break;}
     case 256: { CLKDIV=0x38010; MCLK=256000000; CLKMODE=3; break;}
     
     // normal
     case 166: { CLKDIV=0x4B011; MCLK=166000000; CLKMODE=3; break;}
     case 164: { CLKDIV=0x4a011; MCLK=164000000; CLKMODE=3; break;}
     case 160: { CLKDIV=0x48011; MCLK=160000000; CLKMODE=3; break;}
     case 156: { CLKDIV=0x2c001; MCLK=156000000; CLKMODE=3; break;}
     case 144: { CLKDIV=0x28001; MCLK=144000000; CLKMODE=3; break;}
     case 133: { CLKDIV=0x3a011; MCLK=132000000; CLKMODE=3; break;}
     case 100: { CLKDIV=0x2b011; MCLK=102000000; CLKMODE=2; break;}
     case  66: { CLKDIV=0x25002; MCLK= 67500000; CLKMODE=2; break;}
     case  50: { CLKDIV=0x2a012; MCLK= 50000000; CLKMODE=0; break;}
     case  40: { CLKDIV=0x48013; MCLK= 40000000; CLKMODE=0; break;}
     case  33: { CLKDIV=0x25003; MCLK= 33750000; CLKMODE=0; break;}
     case  22: { CLKDIV=0x33023; MCLK= 22125000; CLKMODE=0; break;}
  }
   if (CLKMODE==0) {HCLK=MCLK ;PCLK=MCLK ;}
   if (CLKMODE==1) {HCLK=MCLK ;PCLK=MCLK/2;}
   if (CLKMODE==2) {HCLK=MCLK/2;PCLK=MCLK/2;}
   if (CLKMODE==3) {HCLK=MCLK/2;PCLK=MCLK/4;}
   _cpu_speed(MCLK,CLKDIV,CLKMODE);
   gp_initButton();  // Init the Buttons to input
}

void gp_Reset() {
   gp_setCpuspeed(66);
   asm volatile("swi #4\n");
}

As you can see, it simply is a switch that sets the three parameters (CLKDIV, Mainclock, and Clockmode) according to the values you give. Clockmode tells it how to set the Bus and Peripheral clocks according to the Mainclock (cpu frequency). These values have been preset for you.

Since it is a switch, that means it only works with the values its designed for.

These are 22,33,40,50,66,100,133,144,156,160,164,166,168,172,176,180,184,188,192,196, 200,204,208,212,216,220,224,228,232,236,240,244,248,252,and 256mhz. Anything above 133 is overclocking. Overclocking works for some models and up to a certain point (people with more than 166mhz are REALLY lucky).

To use frequencies not listed here, you'll have to add them to the switch (use the pllset program to find values you need)

The cpu frequency can effect the sound pitch as you already know. Pretty much if it ends in a 3 or 6 the sound pitch will be about right. But theres a tool for finding the right cpu speed for the sound system also.
 
Mine goes up to 224 MHz. I guess I fall into the "REALLY lucky" category :p
 
The cpu frequency can effect the sound pitch as you already know. Pretty much if it ends in a 3 or 6 the sound pitch will be about right. But theres a tool for finding the right cpu speed for the sound system also.

Yeah... that thing *does* worries me though. Is it related to Mr. Mirko's SDK in particular or to the GP itself ? Is there an SDK that is better geared towards real-time sound generation or should I go on with Mirko's one ?

Thanks for all your help !
 
Last edited by a moderator:
The cpu frequency can effect the sound pitch as you already know. Pretty much if it ends in a 3 or 6 the sound pitch will be about right. But theres a tool for finding the right cpu speed for the sound system also.

Yeah... that thing *does* worries me though. Is it related to Mr. Mirko's SDK in particular or to the GP itself ? Is there an SDK that is better geared towards real-time sound generation or should I go on with Mirko's one ?

Thanks for all your help !

The pitch "bug" does not depend on a SDK, or any Software, its a Hardware thing.
Thanx to gamepark, the gp32 does not have a real soundchip, only a dac, connected to a serial line (internal). The best thing is to choose a nice clockspeed, with gives you the samplespeed you want. There is a little command line tool, that tells you that the samplerate at 66Mhz Clockspeed is not 44.100Khz, its 44.1040khz. But, hey dont care about this, write your little application under Linux/windows , and if it runs nice, porting to gp32 is the smallest piece of work.
 
Last edited by a moderator:
Back
Top