GP32 Gp32 Cycles And Tick Counter


slaanesh

Certified Guru
Joined
Nov 9, 2005
Messages
1,995
Age
54
Location
Melbourne, Australia
Website
www.slaanesh.net
Just wondering if it's possible to do the following of the GP32:

Required:
QUOTE
osd_cycles() inline function/macro in osinline.h, returning a counter. The function must be as low overhead as possible since it is called thousands of times per second when the profiler is active. The counter should be as precise as possible, to provide accurate measurements; the ideal unit is the number of CPU cycles, e.g. as returned by the Pentium instruction RDTSC.


On the GP2X, the minimal lib does it using the following:

CODE
unsigned long gp2x_timer_read_real(void)
{
return gp2x_memregl[0x0A00>>2];
}



Is there an equivalent on the GP32?

Speaking of cycle counts, what about timers? I've found some really good threads about low resolution Tick counters for the GP32, however nothing better tha 64 ticks per second. I know about GpTickCountGet() which seems to do pretty much the same thing and once again low resolution.

I mean, isn't this really low? How do you get more accurate timing? Or has this been a problem with the GP32 since the start?
 
Last edited by a moderator:
Looks like I'm trying to do the same thing as you right now and profile some code on the GP32. I've just started looking into it and found the following from an old source file which I believe RobBrown supplied me with ( or it could have been Rlyeh ).

CODE

unsigned int nTcon;
unsigned int nT;
/* Now set up timer 3 to run at 16000 counts/sec */
nTcon = rTCON;
nT = rTCFG0;
nT &= 0xffff00ff;
nT |= 0xff00; /* Set prescaler to 256 */
rTCFG0 = nT;
nT = rTCFG1;
nT &= 0xffff0fff;
nT |= 0x00003000; /* Set divider to 1/16 */
rTCFG1 = nT;
/* Set reload register to 0xffff */
rTCNTB3 = 0xffff;
rTCMPB3 = 0xffff;
/* Now enable timer 3 */
nT = rTCON;
nT &= 0xfff0ffff;
nT |= 0x00020000;
rTCON = nT;
nT &= 0xfff0ffff;
nT |= 0x00090000;
rTCON = nT;



// To read the time, use the following.
short t3;
t3 = rTCNTO3;



I'll let you know if I can get it working or not.
 
slaanesh said:
Is there an equivalent on the GP32?

Speaking of cycle counts, what about timers? I've found some really good threads about low resolution Tick counters for the GP32, however nothing better tha 64 ticks per second. I know about GpTickCountGet() which seems to do pretty much the same thing and once again low resolution.



I believe Mirko took the easy way out and used the RTC for the 64 ticks per second stuff. If you use a proper timer, you can get much more accuracy. That's what rlyeh uses on the GP2X. For info on how to use the timers, your best info is in the s3c2400x user manual, section 10. Assuming PCLK is running at 66Mhz (133Mhz FCLK/2), 8-bit divider is set to zero, and the 4-bit divider is set to 1/2, then you can get 33,000,000 counts per second.
 
Last edited by a moderator:
Squidge said:
slaanesh said:
Is there an equivalent on the GP32?

Speaking of cycle counts, what about timers? I've found some really good threads about low resolution Tick counters for the GP32, however nothing better tha 64 ticks per second. I know about GpTickCountGet() which seems to do pretty much the same thing and once again low resolution.



I believe Mirko took the easy way out and used the RTC for the 64 ticks per second stuff. If you use a proper timer, you can get much more accuracy. That's what rlyeh uses on the GP2X. For info on how to use the timers, your best info is in the s3c2400x user manual, section 10. Assuming PCLK is running at 66Mhz (133Mhz FCLK/2), 8-bit divider is set to zero, and the 4-bit divider is set to 1/2, then you can get 33,000,000 counts per second.


Slaanesh, there is no need to use high resolution tick count "in the code you are trying to adapt".

#define TICKER unsigned long -> change to the type of the tick count
#define ticker() gp2x_timer_read() -> change to the function to get tick count
#define TICKS_PER_SEC 1000 -> change to number of ticks per second in the previous function

Regards.
 
Last edited by a moderator:
I've worked out an excellent replacement ticker to GpTickCountGet() using the PWM timer and a custom interrupt function to do some counting once the timer is completed. If anyone is interested I'll post it here.
 
Back
Top