b06fe24aebf4333708b5e3247dff9e704aadeef7
[reactos.git] / reactos / subsystems / mvdm / ntvdm / hardware / pit.h
1 /*
2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: pit.h
5 * PURPOSE: Programmable Interval Timer emulation -
6 * i82C54/8254 compatible
7 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
8 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
9 */
10
11 #ifndef _PIT_H_
12 #define _PIT_H_
13
14 /* INCLUDES *******************************************************************/
15
16 #include "ntvdm.h"
17
18 /* DEFINES ********************************************************************/
19
20 #define PIT_CHANNELS 3
21 #define PIT_BASE_FREQUENCY 1193182LL
22 #define PIT_DATA_PORT(x) (0x40 + (x))
23 #define PIT_COMMAND_PORT 0x43
24
25 #define WRITE_PIT_VALUE(PitChannel, Value) \
26 (PitChannel).Bcd ? BCD_TO_BINARY(Value) : (Value)
27
28 #define READ_PIT_VALUE(PitChannel, Value) \
29 (PitChannel).Bcd ? BINARY_TO_BCD(Value) : (Value)
30
31 typedef enum _PIT_MODE
32 {
33 PIT_MODE_INT_ON_TERMINAL_COUNT,
34 PIT_MODE_HARDWARE_ONE_SHOT,
35 PIT_MODE_RATE_GENERATOR,
36 PIT_MODE_SQUARE_WAVE,
37 PIT_MODE_SOFTWARE_STROBE,
38 PIT_MODE_HARDWARE_STROBE
39 } PIT_MODE, *PPIT_MODE;
40
41 typedef VOID (WINAPI *PIT_OUT_FUNCTION)(LPVOID Param, BOOLEAN State);
42
43 typedef struct _PIT_CHANNEL
44 {
45 /* PIT Status fields */
46 PIT_MODE Mode;
47 BOOLEAN Bcd;
48 BYTE ReadWriteMode; // 0 --> Counter Latch ; 1 --> LSB R/W ; 2 --> MSB R/W ; 3 --> LSB then MSB R/W
49
50 /* For interleaved reading and writing in 2-byte RW mode */
51 BYTE ReadStatus; // Same convention as ReadWriteMode
52 BYTE WriteStatus; // Same convention as ReadWriteMode
53
54 /* For reading the PIT status byte */
55 BOOLEAN LatchStatusSet;
56 BYTE StatusLatch;
57
58 /* Counting */
59 BOOLEAN Gate;
60
61 /**/WORD CountRegister;/**/ // Our ReloadValue ???
62 WORD OutputLatch;
63 /*******************************/
64
65 WORD ReloadValue; // Max value of the counter
66 WORD CurrentValue; // Real value of the counter
67
68 /* PIT Output */
69 BOOLEAN Out; // 0: Low ; 1: High
70 /** HACK!! **/BOOLEAN FlipFlop;/** HACK!! **/
71 LPVOID OutParam;
72 PIT_OUT_FUNCTION OutFunction;
73
74 } PIT_CHANNEL, *PPIT_CHANNEL;
75
76 /* FUNCTIONS ******************************************************************/
77
78 VOID PitSetOutFunction(BYTE Channel, LPVOID Param, PIT_OUT_FUNCTION OutFunction);
79 VOID PitSetGate(BYTE Channel, BOOLEAN State);
80 WORD PitGetReloadValue(BYTE Channel);
81
82 VOID PitInitialize(VOID);
83
84 #endif // _PIT_H_
85
86 /* EOF */