9-4
Timer MTimer Management
Programmer’s Manual
9.9
Continuous Reference Timer
PPSM provides a continuous 32-bit reference timer to applications. This 32-bit
value wraps around about every 5 days, but PPSM takes care of the wrap-around
condition, making it transparent to the application. Applications can select to use
either a resolution of 1 millisecond unit or 100 microsecond unit. The following
tools allow the user to make use of this reference timer for functions, such as time-
stamping and time-out.
Note that there are two sets of timer tools, one for millisecond resolution, one for
100 microsecond resolution. The reference value returned by these two separate
sets of tools should NOT be mixed. That is, values returned from the millisecond
tools cannot be used in the 100 microsecond tools.
The millisecond resolution timer tools are named with prefix "RefTime", and the
100 microsecond resolution tools are named with prefix "RefFineTime".
9.10
Read The Reference Timer
U32
RefTimeRead
(void)
U32
RefFineTimeRead
(void)
Read the reference timer value. The return value is an unsigned 32-bit integer
representing the current reference timer value, either in millisecond resolution for
RefTimeRead(), or in 100 microsecond resolution for RefFineTimeRead().
9.11
Set Reference Timer Alarm
STATUS
RefTimeAlarm
(U32 alarmTime)
STATUS
RefFineTimeAlarm
(U32 alarmTime)
STATUS
RefTimeAlarmId
(P_U32 alarmId, U32 alarmTime)
STATUS
RefFineTimeAlarmId
(P_U32 alarmId U32 alarmTime)
Set the alarm time, using the reference value as reference. This is a relative alarm
tool. When using this tool, the input argument is the time that the system will
generate an alarm interrupt to the caller application. This value can easily be
obtained by calling the respective RefTimeRead() or RefFineTimeRead() tool. The
alarmId output from this functions will be returned in IrptGetData() once the alarm
time is reached.
9.12
Compute Reference Times Differences
U32
RefTimeDiff
(U32 beginTime, U32 endTime)
U32
RefFineTimeDiff
(U32 beginTime, U32 endTime)
Personal Portable System Manager
Programmer’s Manual
9-5
Compute the difference in time for the given two reference times. The return value
is in millisecond resolution for RefTimeDiff(), and in 100 microsecond for
RefFineTimeDiff().
U32 (*TimeRead)();
STATUS (*TimeAlarm)(U32 alarmTime);
U32 (*TimeDiff)(U32 beginTime, U32 endTime);
.
.
.
.
while ( 1 )
{
/* Initialize all the variable for holding the time value */
gOldTime = 0;
gNewTime = 0;
gDiffTime = 0;
/* Set up time function for reference timer to read the time,
* to start the alarm and to calculate the time difference.
*/
if (gUnit == MILLI_SECOND) /* Unit in millisecond */
{
/* Assign the function pointer to its corresponding reference
* timer function.
*/
TimeRead = RefTimeRead;
TimeAlarm = RefTimeAlarm;
TimeDiff = RefTimeDiff;
}
else if (gUnit==MICRO_SECOND) /* Unit in microsecond */
{
TimeRead = RefFineTimeRead;
TimeAlarm = RefFineTimeAlarm;
TimeDiff = RefFineTimeDiff;
}
SetUnit(MILLI_SECOND); /* use RefTime toolset */
.
if (*inData == PPSM_ICON_PEN_UP)
{
.
.
if (id == readTimerId)
{
/* Put the previous time to the gOldTime buffer, then read
* the latest time and store in the gNewTime. Get the
* difference of both and store in the gDiffTime.
*/
gOldTime = gNewTime;
gNewTime = (*TimeRead)();
gDiffTime= (*TimeDiff)(gOldTime, gNewTime);
DisplayTime();
}/*if readTimerId*/
.
.
}
}/*while*/
}/*RefTimer*/
F
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
.