diff options
Diffstat (limited to 'driver/serial.c')
| -rw-r--r-- | driver/serial.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/driver/serial.c b/driver/serial.c index 1a36bf5..6e6a4bb 100644 --- a/driver/serial.c +++ b/driver/serial.c @@ -1,10 +1,13 @@ #define FOOLOS_MODULE_NAME "serial" #include "serial.h" -#define PORT 0x3f8 /* COM1 */ +#include "asm/x86.h" // provides x86_inb() and x86_outb() -void serial_init() { +/** COM1 Port */ +static const PORT=0x3f8; +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 @@ -13,23 +16,26 @@ void serial_init() { 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() { +static uint32_t serial_received() +{ return x86_inb(PORT + 5) & 1; } -char serial_read() { +uint8_t serial_read() +{ while (serial_received() == 0); return x86_inb(PORT); } -int is_transmit_empty() { +static uint32_t is_transmit_empty() +{ return x86_inb(PORT + 5) & 0x20; } -void serial_write(char a) { +void serial_write(uint8_t a) +{ while (is_transmit_empty() == 0); x86_outb(PORT,a); } |
