diff options
| author | Miguel <m.i@gmx.at> | 2018-08-18 16:20:26 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-08-18 16:20:26 +0200 |
| commit | 639c3d47b09114628f8e1f8817c27c10bf1fb28c (patch) | |
| tree | f0381de25cc8f2de96a87b47cc76f7d09548bf7e /driver/serial.c | |
| parent | 7b0d88b2dff9b635d9ff69f6d51b6832c1ca4c40 (diff) | |
reviving old drivers: mouse, pci, e1000
Diffstat (limited to 'driver/serial.c')
| -rw-r--r-- | driver/serial.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/driver/serial.c b/driver/serial.c new file mode 100644 index 0000000..f402d0c --- /dev/null +++ b/driver/serial.c @@ -0,0 +1,37 @@ +#define FOOLOS_MODULE_NAME "serial" +// https://wiki.osdev.org/Serial_Ports + +#define PORT 0x3f8 /* COM1 */ + +#include "lib/logger/log.h" + +void serial_init() { + + x86_outb(PORT + 1, 0x00); // Disable all interrupts + x86_outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) + x86_outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud + x86_outb(PORT + 1, 0x00); // (hi byte) + x86_outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit + x86_outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold + x86_outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"COM 1 - initialized"); +} + +int serial_received() { + return x86_inb(PORT + 5) & 1; +} + +char serial_read() { + while (serial_received() == 0); + return x86_inb(PORT); +} + +int is_transmit_empty() { + return x86_inb(PORT + 5) & 0x20; +} + +void serial_write(char a) { + while (is_transmit_empty() == 0); + x86_outb(PORT,a); +} |
