Serial Ports: Difference between revisions
[unchecked revision] | [unchecked revision] |
Content deleted Content added
→First In First Out Control Register: FCR is at offset +2 not +3 |
m Bot: Replace main article with main template |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 68:
! IO Port Offset
! Setting of DLAB
! I/O Access
! Register mapped to this port
|-
| +0 || 0 ||
|-
| +
|-
| +1 || 0 || Read/Write || Interrupt Enable Register.
| +0 || 1 || With DLAB set to 1, this is the least significant byte of the divisor value for setting the baud rate.▼
|-
| +
|-
▲| +
| +2 || - || Interrupt Identification and FIFO control registers▼
|-
|-
| +
|-
| +
|-
| +
|-
| +
|-
| +6 || - || Read || Modem Status Register.
|-
| +7 || - || Read/Write || Scratch Register.
|}
Line 383 ⟶ 388:
===Terminals===
Once you can send and receive bytes with confidence, you probably want to connect the serial port to a terminal (or more likely a terminal emulator these days). Those send specific byte sequences when a key is pressed, and can interpret codes to move the cursor on the screen and change color for example.
Line 390 ⟶ 395:
==Example Code==
===Initialization===
<
#define PORT 0x3f8 // COM1
Line 414 ⟶ 419:
return 0;
}
</syntaxhighlight>
Notice that the initialization code above writes to [PORT + 1] twice with different values. This is once to write to the Divisor register along with [PORT + 0] and once to write to the Interrupt register as detailed in the previous section. The second write to the Line Control register [PORT + 3] clears the DLAB again as well as setting various other bits.
===Receiving data===
<
int serial_received() {
return inb(PORT + 5) & 1;
Line 429 ⟶ 434:
return inb(PORT);
}
</syntaxhighlight>
===Sending data===
<
int is_transmit_empty() {
return inb(PORT + 5) & 0x20;
Line 443 ⟶ 448:
outb(PORT,a);
}
</syntaxhighlight>
==Glossary==
|