home *** CD-ROM | disk | FTP | other *** search
- -- Listing 1. Package specification for a polled timer.
-
- generic
- type Seconds is private;
- with function Dimensionless
- (T : Seconds) return float
- is <>;
- with function Type_Convert
- (F : float) return Seconds
- is <>;
- package POLLED_TIMER is
-
- INVALID_PERIOD : exception;
- -- The requested period is too long
- -- or two short. Use the Max_Period
- -- and/or Single_Tick function to
- -- find out what is wrong.
-
- type Modes is (SINGLE, REPEATED);
- -- Program the timer to expire once,
- -- then stop (SINGLE), or program it
- -- to start another timing cycle as
- -- soon as the first one finishes
- -- (REPEATED).
-
- -- Call the following procedure once
- -- to initially configure the timer.
- -- It should not be called again,
- -- unless you want to change the
- -- PERIOD or the MODE.
-
- procedure Set(PERIOD : Seconds;
- MODE : Modes);
- -- May raise INVALID_PERIOD from the
- -- TIMER_EXCEPTION package. If so,
- -- use the two functions at the end
- -- of this package to find out what
- -- went wrong.
-
- procedure Start;
- -- Starts the timer running in the
- -- MODE determined by Set.
-
- procedure Restart;
- -- Reloads the counter with the
- -- desired time delay and starts
- -- the counter again.
-
- function Has_Expired return boolean;
- -- Poll this function to see if the
- -- time delay has expired yet.
-
- procedure Stop;
- -- If the MODE is REPEATED, you
- -- should use this procedure at the
- -- end of the program to turn off
- -- the timer. (Otherwise it will
- -- keep running after the program is
- -- finished.) You need not use it in
- -- SINGLE mode because the timer
- -- will stop automatically as soon
- -- as it expires.
-
- -- You can also use this procedure,
- -- in conjuction with Start, to
- -- simulate a stopwatch.
-
- function Time_Used return Seconds;
- -- Tells you how many seconds have
- -- gone by since you started the
- -- timer. It does NOT stop the
- -- timer.
-
- function Time_Left return Seconds;
- -- Tells you how many seconds until
- -- the time delay will expire. It
- -- does NOT stop the timer.
-
- -- The following two functions tell
- -- the limitations of the underlying
- -- physical timer. They can be called
- -- before setting the period to make
- -- sure the timer can support the
- -- desired time resolution, or they
- -- can be called after Set raises
- -- TIMER_EXCEPTION.INVALID_PERIOD to
- -- find out what went wrong.
-
- function Max_Period return Seconds;
- function Single_Tick return Seconds;
-
- end POLLED_TIMER;
-