diff options
Diffstat (limited to 'drivers/serial.cc')
-rw-r--r-- | drivers/serial.cc | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/drivers/serial.cc b/drivers/serial.cc index 84dd4b0..22b8051 100644 --- a/drivers/serial.cc +++ b/drivers/serial.cc @@ -5,22 +5,18 @@ * |dla| | parity | s | data | */ enum LineControlRegister : uint8_t { - // data bits - d5bit = 0b00000000, + d5bit = 0b00000000, // data bits d6bit = 0b00000001, d7bit = 0b00000010, d8bit = 0b00000011, - // parity bits - none = 0b00000000, + none = 0b00000000, // parity bits odd = 0b00001000, even = 0b00011000, mark = 0b00101000, space = 0b00111000, - // stop bits - s1bit = 0b00000000, + s1bit = 0b00000000, // stop bits s2bit = 0b00000100, // 1.5 for 5bit data; 2 otherwise - // divisor latch access bit - dlab = 0b10000000, + dlab = 0b10000000, // divisor latch access bit }; /* Line Status Register */ @@ -35,6 +31,10 @@ enum LineStatusRegister : uint8_t { ERRO = 0b10000000, // impending error: see if there is an error with a word in the input buffer }; +// TODO InterruptControlRegister +// TODO FifoControlRegister +// TODO ModemControlRegister + SerialPort::SerialPort() { /* * The serial controller (UART) has a baud rate of 115200 ticks per second; to limit the speed of the port set the @@ -54,6 +54,16 @@ SerialPort::SerialPort() { port.write(0xc7, FifoControl); // enable FIFO, clear, with 14-byte threshold port.write(0x0b, ModemControl); // IRQ enabled, RTS/DSR set + + // test serial port + port.write(0x1e, ModemControl); // set in loopback mode + port.write(0xae); // write 0xae to port + self_check_okay = (port.read() == 0xae); + + // if not faulty, set in normal operation mode + if (self_check_okay) { + port.write(0x0f, ModemControl); + } } bool SerialPort::ready_read() { @@ -61,9 +71,7 @@ bool SerialPort::ready_read() { } uint8_t SerialPort::read() { - while (!ready_read()) { - asm volatile("nop"); - } + while (!ready_read()) asm volatile("nop"); return port.read(); } @@ -72,9 +80,7 @@ bool SerialPort::ready_write() { } void SerialPort::write(char c) { - while (!ready_write()) { - asm volatile("nop"); - } + while (!ready_write()) asm volatile("nop"); switch (c) { case '\n': |