34
K
A
DAK
Application Tasks
3.7 Task Tim ing
The AMX Clock Handler and Kernel Task act as a Timer Manager providing timing
facilities for use by tasks. It has been shown in Chapter 3.6 that tasks can wait for an
event to occur with an automatic timeout. The task is suspended following its wait
request until the event occurs or the interval specified in the call expires.
The ajwatm call to AMX can also be used by a task to implement a delay. The delay
interval is specified in system ticks. The task is suspended until the interval expires.
AMX assures that the task automatically resumes execution, provided that no higher
priority task is able to execute.
Other timing functions required by the task can be implemented using interval timers (see
Chapter 5). Timers are 32-bit counters. Timing resolution is in multiples of the system
tick. The AMX routine ajtmcnv is available to convert milliseconds to the equivalent
number of system ticks.
Timers can be created at any time by a call to the AMX routine ajtmcre.
A timer is started by writing the timer period to it using the AMX routine ajtmwr. At any
instant, a task can read the time remaining in the interval by calling AMX routine
ajtmrd. A timer can be stopped by writing zero to it. A timer can be deleted when it is
no longer required by a call to ajtmdel. These simple procedures give the task complete
control over interval timing.
Whenever an interval timer expires, AMX executes an associated Timer Procedure.
Using this feature, a task can start an interval timer and rest assured that, when the
interval expires, the action determined by the associated Timer Procedure will be
performed. Since the Timer Procedure is called by the AMX Kernel Task which has the
highest priority in the system, the Timer Procedure executes at a priorit y higher than that
of any application task.
Interval timers must be used by tasks wishing to measure time. Instruction counting
loops are of no value in a multitasking system. Since a task is being constantly
interrupted and occasionally suspended to execute higher priority tasks, any timing
performed by counting instructions within a program loop will be in error.