Reorganization, comments.
[pintos-anon] / src / devices / serial.c
index 8d1633f351b241b731ec8f8dcc1127fbba4b078b..e5b2fb7de3f0d5fe4fae45fbdf02fb6ee3cd0067 100644 (file)
@@ -4,23 +4,9 @@
 #include "io.h"
 #include "timer.h"
 
-static void
-set_serial (int bps, int bits, enum parity_type parity, int stop)
-{
-  int baud_base = 1843200 / 16;         /* Base rate of 16550A. */
-  uint16_t divisor = baud_base / bps;   /* Clock rate divisor. */
-    
-  /* Enable DLAB. */
-  outb (LCR_REG, make_lcr (bits, parity, stop, false, true));
-
-  /* Set baud rate. */
-  outb (LS_REG, divisor & 0xff);
-  outb (MS_REG, divisor >> 8);
-  
-  /* Reset DLAB. */
-  outb (LCR_REG, make_lcr (bits, parity, stop, false, false));
-}
+static void set_serial (int bps, int bits, enum parity_type parity, int stop);
 
+/* Initializes the serial port device. */
 void
 serial_init (void) 
 {
@@ -30,6 +16,7 @@ serial_init (void)
   outb (MCR_REG, 0);    /* Turn off output lines. */
 }
 
+/* Sends BYTE to the serial port. */
 void
 serial_outb (uint8_t byte) 
 {
@@ -37,3 +24,22 @@ serial_outb (uint8_t byte)
     continue;
   outb (THR_REG, byte);
 }
+
+/* Configures the first serial port for BPS bits per second,
+   BITS bits per byte, the given PARITY, and STOP stop bits. */
+static void
+set_serial (int bps, int bits, enum parity_type parity, int stop)
+{
+  int baud_base = 1843200 / 16;         /* Base rate of 16550A. */
+  uint16_t divisor = baud_base / bps;   /* Clock rate divisor. */
+    
+  /* Enable DLAB. */
+  outb (LCR_REG, make_lcr (bits, parity, stop, false, true));
+
+  /* Set baud rate. */
+  outb (LS_REG, divisor & 0xff);
+  outb (MS_REG, divisor >> 8);
+  
+  /* Reset DLAB. */
+  outb (LCR_REG, make_lcr (bits, parity, stop, false, false));
+}