]> Joshua Wise's Git repositories - netwatch.git/blame - lib/serial.c
instrument time spent in network
[netwatch.git] / lib / serial.c
CommitLineData
e931b1fe
JW
1#include <minilib.h>
2#include <io.h>
3
4#define SER_BASE 0x3F8
5#define SER_THR 0x0
6#define SER_RBR 0x0
7#define SER_DLL 0x0
8#define SER_IER 0x1
9#define SER_DLM 0x1
10#define SER_IIR 0x2
11#define SER_FCR 0x2
12#define SER_LCR 0x3
13#define SER_LCR_DLAB 0x80
14#define SER_MCR 0x4
15#define SER_LSR 0x5
16#define SER_LSR_THR_EMPTY 0x20
17#define SER_MSR 0x6
18#define SER_SR 0x7
19
20#define SER_BAUD_BASE 115200
21#define SER_BAUD_REQ 115200
22
23void _outb(unsigned short port, unsigned char d)
24{
25 outb(SER_BASE + port, d);
26}
27
28unsigned char _inb(unsigned short port)
29{
30 return inb(SER_BASE + port);
31}
32
33void serial_init()
34{
35 unsigned short baud = SER_BAUD_REQ / SER_BAUD_BASE;
c07c6eba 36 _outb(SER_LCR, _inb(SER_LCR) | SER_LCR_DLAB);
e931b1fe
JW
37 _outb(SER_DLL, baud & 0xFF);
38 _outb(SER_DLM, baud >> 8);
c07c6eba 39 _outb(SER_LCR, _inb(SER_LCR) & ~SER_LCR_DLAB);
e931b1fe
JW
40 _outb(SER_IER, 0x0);
41 _outb(SER_FCR, 0x0); /* FIFOs off */
42 _outb(SER_LCR, 0x03); /* 8 data bits, one stop bit, no parity */
43}
44
45void serial_tx(unsigned char c)
46{
113df320
JW
47 int i = 100000;
48
49 while (!(_inb(SER_LSR) & SER_LSR_THR_EMPTY) && (i--))
e931b1fe
JW
50 ;
51 _outb(SER_THR, c);
52}
This page took 0.023247 seconds and 4 git commands to generate.