k-tana-zero/k/serial.c

39 lines
781 B
C

#include <stddef.h>
#include "serial.h"
#include "io.h"
static void set_baud_rate(void)
{
u8 line_control_register = inb(COM1 + 3);
outb(COM1 + 3, DLAB | line_control_register);
outb(COM1, 3);
outb(COM1 + 1, 0);
outb(COM1 + 3, line_control_register);
}
void init_serial(void)
{
set_baud_rate();
outb(COM1 + 3, NO_PARITY | EIGHT_BITS_LENGTH);
outb(COM1 + 2, FIFO | TRIGGER_LVL_14 | CLEAR_TRANSMIT_FIFO
| CLEAR_RECEIVE_FIFO);
outb(COM1 + 1, ENABLE_TRANSMITTER);
}
int write(const char *buf, size_t count)
{
int sent;
for(sent = 0; sent < count; ++sent)
{
u8 line_status = inb(COM1 + 5);
if (!line_status & EMPTY_TRANSMITTER)
break;
outb(COM1, buf[sent]);
}
return sent;
}