k-tana-zero/k/serial.c

39 lines
786 B
C
Raw Normal View History

#include <stddef.h>
#include "serial.h"
#include "io.h"
2021-07-13 02:47:32 +00:00
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)
{
2021-07-13 02:47:32 +00:00
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)
{
size_t 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;
}