How To Set Cpu Speed And Gamma


el_pango

Member
Joined
May 31, 2006
Messages
145
Location
California
Hi,

In my program, when I do the following, the console locks up:

CODE

/*****************************************************************************/
//! Change CPU frequency.
/*!
* ...on a GP2x, anyway.
* Does nothing and returns on a desktop.
* Gotten from http://wiki.gp2x.org/wiki/CPU_Frequency
*
* Don't use right now, it crashes
*/
void set_cpu_speed(int mhz)
{
int memfd;
unsigned long* memregs32;
unsigned short* memregs16;

#ifdef TARGET_GP2X
unsigned int v;
unsigned int mdiv,pdiv=3,scale=0;

memfd = open("/dev/mem", O_RDWR);

memregs32 = (unsigned long*) mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, memfd, 0xc0000000);
memregs16 = (unsigned short *)memregs32;

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

close(memfd);
#endif
}



Unfortunately, I don't have access to a serial cable, so I can't see any error output. Anyone know what might cause this?

This is on a MK2-F100 with firmware 2.1.1, and I'm working with HW-accelerated Allegro (0.3 with button fix). I am calling this before setting the graphics mode or calling any of Allegro's initialization functions, and I am trying to get the speed to 225, which has been known to work in other games on the same '2x.

Followup question - how does one go about setting the global gamma? I'm unable to find a doc that explains this...
 
Your using a MK2 - are you your it's not hanging at the Allegro initialisation functions? Are you doing this?

Does it work without the cpu change code?
 
Last edited by a moderator:
Parkydr said:
Your using a MK2 - are you your it's not hanging at the Allegro initialisation functions? Are you doing this?

Does it work without the cpu change code?



Hi,

If I don't call this, the app is able to run normally. I haven't yet implemented the dummy blit, but I am launching it from GP2XMB, which seems to leave the blitter in a state that Allegro likes (it's on the to-do list, though).
 
Last edited by a moderator:
el_pango said:
Parkydr said:
Your using a MK2 - are you your it's not hanging at the Allegro initialisation functions? Are you doing this?

Does it work without the cpu change code?



Hi,

If I don't call this, the app is able to run normally. I haven't yet implemented the dummy blit, but I am launching it from GP2XMB, which seems to leave the blitter in a state that Allegro likes (it's on the to-do list, though).


I recompiled against the unaccelerated allegro from way back when, and it still hangs when attempting to set the CPU speed. Not sure what to do here.

No one else has ever encountered this?
 
Last edited by a moderator:
What CPU speed are you trying to set it to? Or better, what are you passing as parameter?

(I'm using that bit of code in my custom menu, and it works fine from 50 up to 270 on my F100 unit)
 
Back
Top