ztimer.c
来自「适合KS8695X」· C语言 代码 · 共 517 行 · 第 1/2 页
C
517 行
PARAMETERS:
tm - Timer object to compute the elapsed time with.
RETURNS:
Count that has elapsed in microseconds.
REMARKS:
Returns the current count that has elapsed between calls to
LZTimerOn and LZTimerOff in microseconds.
SEE ALSO:
LZTimerOn, LZTimerOff, LZTimerLap
****************************************************************************/
ulong ZAPI LZTimerCountExt(
LZTimerObject *tm)
{
#ifdef __INTEL__
CPU_largeInteger tmCount;
if (haveRDTSC) {
_CPU_diffTime64(&tm->start,&tm->end,&tmCount);
return _CPU_calcMicroSec(&tmCount,cpuSpeed);
}
else
#endif
return __LZTimerCount(tm);
}
/****************************************************************************
DESCRIPTION:
Starts the Long Period Zen Timer counting.
HEADER:
ztimer.h
REMARKS:
Obsolete function. You should use the LZTimerOnExt function instead
which allows for multiple timers running at the same time.
****************************************************************************/
void ZAPI LZTimerOn(void)
{ LZTimerOnExt(&LZTimer); }
/****************************************************************************
DESCRIPTION:
Returns the current count for the Long Period Zen Timer and keeps it
running.
HEADER:
ztimer.h
RETURNS:
Count that has elapsed in microseconds.
REMARKS:
Obsolete function. You should use the LZTimerLapExt function instead
which allows for multiple timers running at the same time.
****************************************************************************/
ulong ZAPI LZTimerLap(void)
{ return LZTimerLapExt(&LZTimer); }
/****************************************************************************
DESCRIPTION:
Stops the Long Period Zen Timer counting.
HEADER:
ztimer.h
REMARKS:
Obsolete function. You should use the LZTimerOffExt function instead
which allows for multiple timers running at the same time.
****************************************************************************/
void ZAPI LZTimerOff(void)
{ LZTimerOffExt(&LZTimer); }
/****************************************************************************
DESCRIPTION:
Returns the current count for the Long Period Zen Timer.
HEADER:
ztimer.h
RETURNS:
Count that has elapsed in microseconds.
REMARKS:
Obsolete function. You should use the LZTimerCountExt function instead
which allows for multiple timers running at the same time.
****************************************************************************/
ulong ZAPI LZTimerCount(void)
{ return LZTimerCountExt(&LZTimer); }
/****************************************************************************
DESCRIPTION:
Starts the Ultra Long Period Zen Timer counting.
HEADER:
ztimer.h
REMARKS:
Starts the Ultra Long Period Zen Timer counting. Once you have started the
timer, you can stop it with ULZTimerOff or you can latch the current count
with ULZTimerLap.
The Ultra Long Period Zen Timer uses the available operating system services
to obtain accurate timings results with as much precision as the operating
system provides, but with enough granularity to time longer periods of
time than the Long Period Zen Timer. Note that the resolution of the timer
ticks is not constant between different platforms, and you should use the
ULZTimerResolution function to determine the number of seconds in a single
tick of the timer, and use this to convert the timer counts to seconds.
Under 32-bit Windows, we use the timeGetTime function which provides a
resolution of 1 millisecond (0.001 of a second). Given that the timer
count is returned as an unsigned 32-bit integer, this we can time intervals
that are a maximum of 2^32 milliseconds in length (or about 1,200 hours or
50 days!).
Under 32-bit DOS, we use the system timer tick which runs at 18.2 times per
second. Given that the timer count is returned as an unsigned 32-bit integer,
this we can time intervals that are a maximum of 2^32 * (1/18.2) in length
(or about 65,550 hours or 2731 days!).
SEE ALSO:
ULZTimerOff, ULZTimerLap, ULZTimerCount, ULZElapsedTime, ULZReadTime
****************************************************************************/
void ZAPI ULZTimerOn(void)
{ start = __ULZReadTime(); }
/****************************************************************************
DESCRIPTION:
Returns the current count for the Ultra Long Period Zen Timer and keeps it
running.
HEADER:
ztimer.h
RETURNS:
Count that has elapsed in resolution counts.
REMARKS:
Returns the current count that has elapsed since the last call to
ULZTimerOn in microseconds. The time continues to run after this function is
called so you can call this function repeatedly.
SEE ALSO:
ULZTimerOn, ULZTimerOff, ULZTimerCount
****************************************************************************/
ulong ZAPI ULZTimerLap(void)
{ return (__ULZReadTime() - start); }
/****************************************************************************
DESCRIPTION:
Stops the Long Period Zen Timer counting.
HEADER:
ztimer.h
REMARKS:
Stops the Ultra Long Period Zen Timer counting and latches the count. Once
you have stopped the timer you can read the count with ULZTimerCount.
SEE ALSO:
ULZTimerOn, ULZTimerLap, ULZTimerCount
****************************************************************************/
void ZAPI ULZTimerOff(void)
{ finish = __ULZReadTime(); }
/****************************************************************************
DESCRIPTION:
Returns the current count for the Ultra Long Period Zen Timer.
HEADER:
ztimer.h
RETURNS:
Count that has elapsed in resolution counts.
REMARKS:
Returns the current count that has elapsed between calls to
ULZTimerOn and ULZTimerOff in resolution counts.
SEE ALSO:
ULZTimerOn, ULZTimerOff, ULZTimerLap, ULZTimerResolution
****************************************************************************/
ulong ZAPI ULZTimerCount(void)
{ return (finish - start); }
/****************************************************************************
DESCRIPTION:
Reads the current time from the Ultra Long Period Zen Timer.
HEADER:
ztimer.h
RETURNS:
Current timer value in resolution counts.
REMARKS:
Reads the current Ultra Long Period Zen Timer and returns it抯 current
count. You can use the ULZElapsedTime function to find the elapsed time
between two timer count readings.
SEE ALSO:
ULZElapsedTime, ULZTimerResolution
****************************************************************************/
ulong ZAPI ULZReadTime(void)
{ return __ULZReadTime(); }
/****************************************************************************
DESCRIPTION:
Compute the elapsed time between two timer counts.
HEADER:
ztimer.h
PARAMETERS:
start - Starting time for elapsed count
finish - Ending time for elapsed count
RETURNS:
Elapsed timer in resolution counts.
REMARKS:
Returns the elapsed time for the Ultra Long Period Zen Timer in units of the
timers resolution (1/18th of a second under DOS). This function correctly
computes the difference even if a midnight boundary has been crossed
during the timing period.
SEE ALSO:
ULZReadTime, ULZTimerResolution
****************************************************************************/
ulong ZAPI ULZElapsedTime(
ulong start,
ulong finish)
{ return __ULZElapsedTime(start,finish); }
/****************************************************************************
DESCRIPTION:
Returns the resolution of the Ultra Long Period Zen Timer.
HEADER:
ztimer.h
PARAMETERS:
resolution - Place to store the timer in microseconds per timer count.
REMARKS:
Returns the resolution of the Ultra Long Period Zen Timer as a 32-bit
integer value measured in microseconds per timer count.
SEE ALSO:
ULZReadTime, ULZElapsedTime, ULZTimerCount
****************************************************************************/
void ZAPI ULZTimerResolution(
ulong *resolution)
{ *resolution = ULZTIMER_RESOLUTION; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?