hi, I have just finished a driver of mpc5200 slice timer.I want to test it's PRECISION. I use DEC to help my work. here is the code:
unsigned int BUS_MHZ = 66;
void dec_init( unsigned int mhz ) { BUS_MHZ = mhz; }
void dec_sett(); asm(".text"); asm(".global dec_sett"); asm("dec_sett:"); asm("li 3,0xffffffff"); asm("mtdec 3"); asm("sync"); asm("isync"); asm("blr");
unsigned int dec_gett(); asm(".text"); asm(".global dec_gett"); asm("dec_gett:"); asm("mfdec 3"); asm("sync"); asm("isync"); asm("blr");
float dec_unit() { float f1; f1 = 4.0/BUS_MHZ;
return f1; }
void PPCTimeGet(float * sys_time) { *sys_time =(float )(0xffffffff - dec_gett())/((float )BUS_MHZ/4.0); }
I use these function like this:
#define WAIT_TICK 1 #define TICKPERUS 1000 //microsecond per ticks #define MAXRUNTIME 10
void Init(void ) { float curtime; unsigned i;
//enable Arbiter Configuration Register's TBEN bit MBAR_ACR_CFG |= 0x00002000;
//init the frequency of bus dec_init(66); dec_sett();
for (i = 0; i < MAXRUNTIME; i++) {
dec_sett();
sleep(WAIT_TICK )
PPCTimeGet(&curtime);
printf("%f\n",curtime - WAIT_TICK * TICKPERUS); } }
can any one give some advices about my code? I am not sure whether my code is correct or not. Or , if you have better idea, please tell me. thanks.