Programmable Interval Timer: Difference between revisions
m
covnert some code to C to reflect the purpouse of the article better
[unchecked revision] | [unchecked revision] |
(convert exotic assembler syntax to NASM) |
m (covnert some code to C to reflect the purpouse of the article better) |
||
Line 231:
For the "lobyte/hibyte" access mode you need to send the latch command (described above) to avoid getting wrong results. If any other code could try set the PIT channel's reload value or read its current count after you've sent the latch command but before you've read the highest 8 bits, then you have to prevent it. Disabling interrupts works for single CPU computers. For example, to read the count of PIT channel 0 you could use something like:
<source lang="
unsigned read_pit_count(void) {
unsigned count = 0;
// Disable interrupts
mov al, 00000000b ; al = channel in bits 6 and 7, remaining bits clear▼
cli();
outb(0x43,0b0000000);
count = inb(0x40); // Low byte
count |= inb(0x40)<<8; // High byte
return count;
}
</source>
Line 251 ⟶ 253:
For the "lobyte/hibyte" access mode you need to send the low 8 bits followed by the high 8 bits. You must prevent other code from setting the PIT channel's reload value or reading its current count once you've sent the lowest 8 bits. Disabling interrupts works for single CPU computers. For example:
<source lang="
void set_pit_count(unsigned count) {
// Disable interrupts
cli();
outb(0x40,(count&0xFF00)>>8); // High byte
return;
}
</source>
|