-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpit.c
More file actions
40 lines (32 loc) · 980 Bytes
/
Copy pathpit.c
File metadata and controls
40 lines (32 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "pit.h"
#include "assembly-utility.h"
void kInitializePIT(WORD wCount, BOOL bPeriodic) {
kOutPortByte(PIT_PORT_CONTROL, PIT_COUNTER0_ONCE);
if(bPeriodic) {
kOutPortByte(PIT_PORT_CONTROL, PIT_COUNTER0_PERIODIC);
}
kOutPortByte(PIT_PORT_COUNTER0, wCount);
kOutPortByte(PIT_PORT_COUNTER0, (wCount >> 8));
}
WORD kReadCounter0() {
BYTE bHighByte, bLowByte;
WORD wTemp = 0;
kOutPortByte(PIT_PORT_CONTROL, PIT_COUNTER0_LATCH);
bLowByte = kInPortByte(PIT_PORT_COUNTER0);
bHighByte = kInPortByte(PIT_PORT_COUNTER0);
wTemp = bHighByte;
wTemp = (wTemp << 8) | bLowByte;
return wTemp;
}
void kWaitUsingDirectPIT(WORD wCount) {
WORD wLastCounter0;
WORD wCurrentCounter0;
kInitializePIT(0, TRUE);
wLastCounter0 = kReadCounter0();
while(1) {
wCurrentCounter0 = kReadCounter0();
if(((wLastCounter0 - wCurrentCounter0) & 0xFFFF) >= wCount) {
break;
}
}
}