diff options
author | dzwdz | 2021-10-02 19:32:41 +0000 |
---|---|---|
committer | dzwdz | 2021-10-02 19:32:41 +0000 |
commit | 1fb05a21e8ae570c4c3902ae5fe6635df029bcda (patch) | |
tree | e4129a5ffda5b8be307f647fd873a852d335c51f | |
parent | 9413809a49dba99c1f8da73b1bda8dc2cd5446ca (diff) |
serial: implement a selftest
-rw-r--r-- | src/kernel/arch/i386/tty/serial.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/kernel/arch/i386/tty/serial.c b/src/kernel/arch/i386/tty/serial.c index b3f1d9d..6ddc05b 100644 --- a/src/kernel/arch/i386/tty/serial.c +++ b/src/kernel/arch/i386/tty/serial.c @@ -1,9 +1,17 @@ -#include <kernel/arch/i386/tty/serial.h> #include <kernel/arch/i386/port_io.h> +#include <kernel/arch/i386/tty/serial.h> +#include <kernel/panic.h> #include <stdint.h> static const int COM1 = 0x3f8; +static void serial_selftest(void) { + char b = 0x69; + port_outb(COM1 + 4, 0b00011110); // enable loopback mode + port_outb(COM1, b); + assert(port_inb(COM1) == b); +} + void serial_init(void) { // see https://www.sci.muni.cz/docs/pc/serport.txt @@ -16,11 +24,10 @@ void serial_init(void) { port_outb(COM1 + 3, 0b00000011); // 8 bits, no parity, one stop bit port_outb(COM1 + 2, 0b11000111); // enable FIFO with 14-bit trigger level (???) - port_outb(COM1 + 4, 0b00001111); // enable everything in the MCR - /* the example on the OSDEV wiki does a selftest of the serial connection - * i don't really see the point as long as i'm not using it for input? - * if i start using serial for input, TODO selftest */ + serial_selftest(); + + port_outb(COM1 + 4, 0b00001111); // enable everything in the MCR } static void serial_putchar(char c) { |