Important: The information in this document is obsolete and should not be used for new development.
Using the Time Manager
The Time Manager is automatically initialized when the system starts up. At that time, the queue of Time Manager task records is empty. The Operating System, applications, and other software components may place records into the queue. Because the delay time for a given task can be as small as 20 microseconds, you need to install an element into the Time Manager queue before actually issuing a request to execute it at some future time. You place elements into the queue by calling theInsTimeprocedure or (if you need the fixed-frequency services of the extended Time Manager) theInsXTimeprocedure. To activate the request, callPrimeTime. The Time Manager then marks the specified task record as active by setting the high-order bit in theqTypefield of that record.The
tmAddrfield of the Time Manager task record contains the address of a task. The Time Manager calls this task when the time delay specified by a previous call toPrimeTimehas elapsed. The task can perform any desired actions, as long as it does not call the Memory Manager (either directly or indirectly) and does not depend on the validity of handles to unlocked blocks.
There are two ways for an active queue element to become inactive. First, the specified time delay can elapse, in which case the routine pointed to by the
- Note
- If the routine specified in the Time Manager task record is located in your application's heap, then your application must still be active when the specified delay elapses, or the application should call
RmvTimebefore it terminates. Otherwise, the Time Manager does not know that the address of that routine is not valid when the routine is called. The Time Manager then attempts to call the task, but with a stale pointer. If you want to let the application terminate after it has installed and activated a Time Manager task record, load the routine into the system heap. ·tmAddrfield is called. Second, your application can call theRmvTimeprocedure, in which case the amount of time remaining before the delay would have elapsed (the unused time) is reported in thetmCountfield of the task record. This feature allows you to use the Time Manager to compute elapsed times (see the section "Computing Elapsed Time" on page 3-14), which is useful for obtaining performance measurements. CallingRmvTimeremoves an element from the queue whether or not that task is active whenRmvTimeis called.To use the Time Manager for periodic execution of a task, simply have the routine pointed to by
tmAddrcallPrimeTimeagain. This technique is illustrated in the section "Performing Periodic Tasks" on page 3-13. Similarly, you can execute a Time Manager task a specific number of times by keeping a count of the number of times the task has been called. In cases where the task needs access to your application's global variables (such as a count variable), make sure that the A5 register points to your application's global variables when the task is executed and that A5 is restored to its original value when your task exits. A technique for this purpose is illustrated in "Using Application Global Variables in Tasks" on page 3-11.
Subtopics
- Installing and Activating Tasks
- Using Application Global Variables in Tasks
- Performing Periodic Tasks
- Computing Elapsed Time