-
Notifications
You must be signed in to change notification settings - Fork 0
/
serial.c
34 lines (25 loc) · 1023 Bytes
/
serial.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "port-io.h"
#define SERIAL_COM1_BASE 0x3F8
#define SERIAL_DATA_PORT(base) (base)
#define SERIAL_FIFO_COMMAND_PORT(base) (base + 2)
#define SERIAL_LINE_COMMAND_PORT(base) (base + 3)
#define SERIAL_MODEM_COMMAND_PORT(base) (base + 4)
#define SERIAL_LINE_STATUS_PORT(base) (base + 5)
#define SERIAL_LINE_ENABLE_DLAB 0x80
void serial_configure_baud_rate(unsigned short com, unsigned short divisor) {
outb(SERIAL_LINE_COMMAND_PORT(com), SERIAL_LINE_ENABLE_DLAB);
outb(SERIAL_DATA_PORT(com), (divisor >> 8) & 0x00FF);
outb(SERIAL_DATA_PORT(com), (divisor & 0x00FF));
}
void serial_configure_line(unsigned short com) {
outb(SERIAL_LINE_COMMAND_PORT(com), 0x03);
}
void serial_configure_buffer(unsigned short com) {
outb(SERIAL_FIFO_COMMAND_PORT(com), 0xC7);
}
void serial_configure_modem(unsigned short com) {
outb(SERIAL_MODEM_COMMAND_PORT(com), 0x03);
}
void serial_is_transmit_fifo_empty(unsigned int com) {
return inb(SERIAL_LINE_STATUS_PORT(com) & 0x20);
}