]> Joshua Wise's Git repositories - netwatch.git/blame_incremental - lib/serial.c
rfb chunks
[netwatch.git] / lib / serial.c
... / ...
CommitLineData
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;
36 _outb(SER_LCR, _inb(SER_LCR) | SER_LCR_DLAB);
37 _outb(SER_DLL, baud & 0xFF);
38 _outb(SER_DLM, baud >> 8);
39 _outb(SER_LCR, _inb(SER_LCR) & ~SER_LCR_DLAB);
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{
47 int i = 100000;
48
49 while (!(_inb(SER_LSR) & SER_LSR_THR_EMPTY) && (i--))
50 ;
51 _outb(SER_THR, c);
52}
This page took 0.026342 seconds and 4 git commands to generate.