完整函数如下
void ADT_L0_CALL_CONV ADT_L0_msSleep(ADT_L0_UINT32 msDelay)
{
static int delayLoop = 0;
int ix;
int iy;
int maxLoop;
int start;
int stop;
int mpt; /* microsecs per tick */
msDelay = msDelay*1000; /* Convert input to usec*/
if (delayLoop == 0 || msDelay == 0xffffffff) /* need calibration? Run first time only when delayLoop=0 */
{
start = 0;
stop = 0;
mpt = (1000 * 1000) / sysClkRateGet (); /* microsecs per tick */
for (delayLoop = 1; delayLoop < 0x1000 && stop == start; delayLoop<<=1)
{
for (stop = start = tickGet (); start == stop; start = tickGet ())
; /* wait for clock turn over */
ADT_L0_msSleep(mpt/1000); /* single recursion */
stop = tickGet ();
}
void ADT_L0_CALL_CONV ADT_L0_msSleep(ADT_L0_UINT32 msDelay)
{
static int delayLoop = 0;
int ix;
int iy;
int maxLoop;
int start;
int stop;
int mpt; /* microsecs per tick */
msDelay = msDelay*1000; /* Convert input to usec*/
if (delayLoop == 0 || msDelay == 0xffffffff) /* need calibration? Run first time only when delayLoop=0 */
{
start = 0;
stop = 0;
mpt = (1000 * 1000) / sysClkRateGet (); /* microsecs per tick */
for (delayLoop = 1; delayLoop < 0x1000 && stop == start; delayLoop<<=1)
{
for (stop = start = tickGet (); start == stop; start = tickGet ())
; /* wait for clock turn over */
ADT_L0_msSleep(mpt/1000); /* single recursion */
stop = tickGet ();
}
maxLoop = delayLoop / 2; /* loop above overshoots */
start = 0;
stop = 0;
if (delayLoop < 4)
delayLoop = 4;
for (delayLoop /= 4; delayLoop<maxLoop && stop == start; delayLoop++)
{
for (stop = start = tickGet (); start == stop; start = tickGet ())
; /* wait for clock turn over */
ADT_L0_msSleep(mpt/1000); /* single recursion */
stop = tickGet ();
}
}
/* Main delay loop after calibration above*/
for (iy = 0; iy < msDelay; iy++)
{
for (ix = 0; ix < delayLoop; ix++);
}
}
....
一周热门 更多>