blob: 8747981f261ed8fa86b30d31a422d1dbf8079178 (
plain)
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
33
34
35
36
37
38
39
40
|
#define FOOLOS_MODULE_NAME "serial"
#include "serial.h"
#include "asm/x86.h" // provides x86_inb() and x86_outb()
/** 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
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
}
static uint32_t serial_received()
{
return x86_inb(PORT + 5) & 1;
}
uint8_t serial_read()
{
while (serial_received() == 0);
return x86_inb(PORT);
}
static uint32_t is_transmit_empty()
{
return x86_inb(PORT + 5) & 0x20;
}
void serial_write(uint8_t a)
{
while (is_transmit_empty() == 0);
x86_outb(PORT,a);
}
|