Initial revision
[pintos-anon] / src / devices / serial.c
1 #include "serial.h"
2 #include "16550a.h"
3 #include "debug.h"
4 #include "io.h"
5 #include "timer.h"
6
7 static void
8 set_serial (int bps, int bits, enum parity_type parity, int stop)
9 {
10   int baud_base = 1843200 / 16;         /* Base rate of 16550A. */
11   uint16_t divisor = baud_base / bps;   /* Clock rate divisor. */
12     
13   /* Enable DLAB. */
14   outb (LCR_REG, make_lcr (bits, parity, stop, false, true));
15
16   /* Set baud rate. */
17   outb (LS_REG, divisor & 0xff);
18   outb (MS_REG, divisor >> 8);
19   
20   /* Reset DLAB. */
21   outb (LCR_REG, make_lcr (bits, parity, stop, false, false));
22 }
23
24 void
25 serial_init (void) 
26 {
27   outb (IER_REG, 0);    /* Turn off all interrupts. */
28   outb (FCR_REG, 0);    /* Disable FIFO. */
29   set_serial (9600, 8, NONE, 1);
30   outb (MCR_REG, 0);    /* Turn off output lines. */
31 }
32
33 void
34 serial_outb (uint8_t byte) 
35 {
36   while ((inb (LSR_REG) & LSR_THRE) == 0)
37     continue;
38   outb (THR_REG, byte);
39 }