1661 |
mateusz.vi |
1 |
/*
|
|
|
2 |
* High-resolution timing routines (PIT reprogramming)
|
|
|
3 |
*
|
|
|
4 |
* This file is part of the Mateusz' DOS Routines (MDR): http://mdr.osdn.io
|
|
|
5 |
* Published under the terms of the MIT License, as stated below.
|
|
|
6 |
*
|
|
|
7 |
* Copyright (C) 2014-2023 Mateusz Viste
|
|
|
8 |
*
|
|
|
9 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
10 |
* of this software and associated documentation files (the "Software"), to
|
|
|
11 |
* deal in the Software without restriction, including without limitation the
|
|
|
12 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
13 |
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
14 |
* furnished to do so, subject to the following conditions:
|
|
|
15 |
*
|
|
|
16 |
* The above copyright notice and this permission notice shall be included in
|
|
|
17 |
* all copies or substantial portions of the Software.
|
|
|
18 |
*
|
|
|
19 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
20 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
21 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
22 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
23 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
24 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
25 |
* IN THE SOFTWARE.
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
#ifndef MDR_TIMER_H
|
|
|
29 |
#define MDR_TIMER_H
|
|
|
30 |
|
|
|
31 |
/* Starts the timer by reprogramming the 8253 chip from its default 18.2 Hz
|
|
|
32 |
* frequency to about 1.1 kHz. It is mandatory to revert the timer to its
|
|
|
33 |
* original frequency via mdr_timer_stop() before your application quits. */
|
|
|
34 |
void mdr_timer_init(void);
|
|
|
35 |
|
|
|
36 |
/* Fills res with the amount of microseconds that elapsed since either
|
|
|
37 |
* mdr_timer_init() or mdr_timer_reset(), whichever was called last.
|
|
|
38 |
* Note that the res counter wraps around approximately every 71 minutes if
|
|
|
39 |
* mdr_timer_reset() is not called. */
|
|
|
40 |
void mdr_timer_read(unsigned long *res);
|
|
|
41 |
|
|
|
42 |
/* Reset the timer value, this can be used by the application to make sure
|
|
|
43 |
* no timer wrap occurs during critical parts of your code flow */
|
|
|
44 |
void mdr_timer_reset(void);
|
|
|
45 |
|
|
|
46 |
/* Stops (uninstalls) the timer. This must be called before your application
|
|
|
47 |
* quits, otherwise the system will likely crash. This function has a void
|
|
|
48 |
* return value so that it can be registered as an atexit() procedure. */
|
|
|
49 |
void mdr_timer_stop(void);
|
|
|
50 |
|
|
|
51 |
#endif
|