From abd09e419fd39cd8b8c069f2c77c790a8292e943 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Mon, 16 Jul 2012 10:35:24 +0200 Subject: [PATCH] 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 --- base-nova/src/base/console/core_console.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/base-nova/src/base/console/core_console.h b/base-nova/src/base/console/core_console.h index 8638e47c3c..dfbf8b7f6a 100644 --- a/base-nova/src/base/console/core_console.h +++ b/base-nova/src/base/console/core_console.h @@ -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);