Only write UART if transmitter-hold register empty

The line-status register has two relevant status bits - transmitter-hold
register empty and data-hold register empty - from which only the THR is
relevant as it signals new character can be written to the device.

Fixes #281
This commit is contained in:
Christian Helmuth 2012-07-16 10:35:24 +02:00
parent b2478aec76
commit abd09e419f

View File

@ -53,7 +53,10 @@ enum {
COMPORT_2_BASE = 0x3e8,
COMPORT_3_BASE = 0x2e8,
COMPORT_DATA_OFFSET = 0,
COMPORT_STATUS_OFFSET = 5
COMPORT_STATUS_OFFSET = 5,
STATUS_THR_EMPTY = 0x20, /* transmitter hold register empty */
STATUS_DHR_EMPTY = 0x40, /* data hold register empty - data completely sent */
};
@ -101,7 +104,8 @@ inline void serial_out_char(Comport comport, uint8_t c)
COMPORT_2_BASE, COMPORT_3_BASE };
/* wait until serial port is ready */
while (!(inb(io_port[comport] + COMPORT_STATUS_OFFSET) & 0x60));
uint8_t ready = STATUS_THR_EMPTY;
while ((inb(io_port[comport] + COMPORT_STATUS_OFFSET) & ready) != ready);
/* output character */
outb(io_port[comport] + COMPORT_DATA_OFFSET, c);