PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Problem with CCNT register interrogation (iPaq 3970)!!!

Hi all,
I try to get CCNT register value on my PDA(iPaq 3970 pxa250 400MHz).
And I always get frequency about 50MHz or less.
If I try to set frequency multiplier in CCNTCFG register, that I get frequency more less than 50MHz.
What is wrong in my code?
.asm
Code:

AREA ArmGfxLib,CODE,READONLY
EXPORT ARM_read_CCLKCFG
EXPORT ARM_write_CCLKCFG
EXPORT ARM_write_PMNC
EXPORT ARM_read_CCNT

ARM_read_CCLKCFG
MOV r12, sp
stmfd sp!, {r4-r11,lr}
MRC p14, 0, r0, c6, c0, 0 ;read CCLKCFG
ldmfd sp!, {r4-r11,pc}

ARM_write_CCLKCFG
MOV r12, sp
stmfd sp!, {r4-r11,lr}
MCR p14, 0, r0, c6, c0, 0 ;write CCLKCFG
ldmfd sp!, {r4-r11,pc}

ARM_write_PMNC
MOV r12, sp
stmfd sp!, {r4-r11,lr}
MCR p14, 0, r0, c0, c0, 0 ;write PMNC
ldmfd sp!, {r4-r11,pc}

ARM_read_CCNT
MOV r12, sp
stmfd sp!, {r4-r11,lr}
MRC p14, 0, r0, c1, c0, 0 ;read CCNT
ldmfd sp!, {r4-r11,pc}

.c
Code:

#ifdef ARM
extern "C" int ARM_read_CCLKCFG();
extern "C" void ARM_write_CCLKCFG(int value);
extern "C" void ARM_write_PMNC(int value);
extern "C" int ARM_read_CCNT();
#endif
...
#define PMNC_CCNT_OVERFLOW_CLEAR 0x00000400
#define PMNC_CCNT_EVERY_64TH_PROC_CLK 0x00000008
#define PMNC_CCNT_RESET 0x00000004
#define PMNC_PCNT_RESET 0x00000002
#define PMNC_3CNT_ENABLE 0x00000001

ARM_write_PMNC(PMNC_CCNT_OVERFLOW_CLEAR | PMNC_CCNT_RESET | PMNC_3CNT_ENABLE);

UINT before = ARM_read_CCNT();

Sleep(1000);

UINT after = ARM_read_CCNT();

fprintf(f, "before = %u\nafter = %u\nsub = %u\n", before, after, after - before);

int new_cfg = 0;

for (i = 1; i < 3; i++)
{
ARM_write_CCLKCFG(i);
new_cfg = ARM_read_CCLKCFG();
fprintf(f, "new cfg = 0x%08x\n", new_cfg);
mode = ARM_read_PWRMODE();
fprintf(f, "mode = 0x%08x\n", mode);
ARM_write_PMNC(PMNC_CCNT_OVERFLOW_CLEAR | PMNC_CCNT_RESET | PMNC_3CNT_ENABLE);
before = ARM_read_CCNT();
Sleep(1000);
after = ARM_read_CCNT();
fprintf(f, "before = %u\nafter = %u\nsub = %u\n", before, after, after - before);
}
By setting the FCS bit in the CCLKCFG register, you're just telling it to change the frequency, not what frequency to change to. You need to mess with the CCCR register also. (XScale developer's manual page 3-32). Activating "turbo" mode may be doing nothing if the multiplier between "run mode" and "turbo" mode is 1.

It's a 2 stage process - you have to set up the contents of the CCCR and then tell the processor you want to change speed.

CCCR is a memory mapped register (XScale manual says its located at 0x4130 0000), so map it into your process using VirtualAlloc and VirtualCopy, and write the "correct" values to it. (If you get stuck on that search for VirtualCopy on this forum - we've discussed it before I think).

So, going on what's in the manual, if you want to set the CPU clock to 100MHz, you need to write:
L = 00001 (27 * the 3.68Mhz Xtal = ~99.5 MHz)
M = 01
N = 010

= 0100100001 = 289 to that address

If you want to murder your device:
(this is just an example - do not try this)
L = 00101 (45 x the 3.68MHz Xtal = ~166Mhz memory frequency)
M = 10 (run mode is 2 x memory frequency = 332 Mhz frequency in normal operation)
N = 110 (turbo = 3 x M = ~1GHz in with the turbo bit set;))

= 1101000101 = write 837

Then tell it to you want to perform the frequency change:
(normally you would be leaving the turbo bit in the CCLKCFG register alone by reading it, setting the FCS bit, and modifying it, but I'm presuming you want to mess with it :))

;r0 contains the desired status of the turbo bit (i.e. 0 for off, 1 for on)
orr r0,r0,#2 ; <-- we always set the FCS bit to tell it to change freq.
MCR p14, 0, r0, c6, c0, 0 ;write CCLKCFG (change freq please)


Disclaimer:
It's all untested, and I'm just going on what I read from the manual. If you try it and damage your device, your sanity, or anything else, I'm not to be held responsible.

Hope it works though :P
Thank you for your reply.
My problem was that I'd used Sleep() function to measure PDA frequency in ACTIVE mode.
Sleep() function switchs PDA to SLEEP mode.