Talking about the clock debugging in the driver development

  

I think that the friends who have debugged the driver have been exposed to the clock more or less. Because the clock is indispensable to the device, just as the heart supplies blood to the human body. Some devices have their own clocks, some receive the system's external clock, and the clock source is the cornerstone of the device's operation.

Therefore, detecting whether the clock is working is one of the keys to debugging the device. In this article, I will give you an effective clock debugging method —— no need to use the tester, but use the software method.

I will talk about the clock problem I encountered, and then see how to debug the clock.

The problem occurred when developing mcc (multi-channel controller) driver —— When we tested the driver, we found that no matter how the mcc parameters and trigger devices were configured, the device was self-sustaining, as if it were dead. Therefore the estimated clock is received. After investigation, the clock source mt9045 used by mcc is not set. This clock source will input the mcc input transmission and reception clocks, as well as the synchronous clock.

Because we didn't have enough data to configure the clock at the time, and the clock was really complicated, we were busy for a while and didn't get through it. Therefore, we urgently need to check the correctness of the clock input. If you use a wave tester, you don't know how to pick up the hardware pins (the device is well packaged). Finally, we use a software program to detect the port clock frequency.


static

int frequency_count(volatile unsigned long addr, unsigned int mask )

{

int t, nt, et ;

int v, lv, cnt;


t = Gettick();

while ( 1 )

{< Br>

nt = Gettick();

if ( nt != t )

break;

}

et = nt + GetsysClkRate ();

cnt = 0;

lv = v = (*(int*)addr) & mask;

while ( 1 )

{

nt = Gettick();

if ( nt >= et )

break;

v = (*(int*) Addr) & mask;

if ( v != lv )

{

lv = v;

cnt++;

}

}

return cnt/2;

}


The calculated values ​​of the above program are approximate - when the system When the cpu frequency is about fast, the accuracy is about - the mechanism is left for everyone to understand.

The usage of the function is very simple. When detecting a clock output, that is, whether a pin on a particular address line (a software angle is a bit) generates a frequency, only the address address and the output pin mask of frequency_count are required, such as address 0xfdf90d50. The 0th bit is passed to 0xfdf90d50, 0x00000001. The function outputs the time frequency value.

Be aware that there are two helper functions. One is Gettick, which is used to get the current tick value of the system; the other is GetsysClkRate to get the system tick frequency.

The above functions can be implemented as follows in a Linux system.


static int Gettick()

{

return (int)jiffies;

}

< Br>

static int GetsysClkRate ()

{

return (int)HZ;

}

The above functions for the vxWorks system can be implemented as follows

static int Gettick()

{

return tickGet();

}


static int GetsysClkRate ()

{

return sysClkRateGet();

}




Copyright © Windows knowledge All Rights Reserved