]> Joshua Wise's Git repositories - netwatch.git/commitdiff
Add a small serial driver
authorJoshua Wise <joshua@rebirth.joshuawise.com>
Fri, 7 Nov 2008 19:51:42 +0000 (14:51 -0500)
committerJoshua Wise <joshua@rebirth.joshuawise.com>
Fri, 7 Nov 2008 19:51:42 +0000 (14:51 -0500)
aseg/Makefile
lib/serial.c [new file with mode: 0644]

index 0ffd379d3a74a3d1a324c1d6fca4c5d92b7889aa..76eaa4530e8daee8c29af43be270aa9e4b971256 100644 (file)
@@ -30,7 +30,8 @@ LWIP_OBJS = \
 OBJS=counter.o firstrun.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o \
        ../ich2/smram-ich2.o ../ich2/smi.o vga-overlay.o packet.o \
        ../lib/sprintf.o ../lib/doprnt.o ../pci/pci.o ../net/net.o \
 OBJS=counter.o firstrun.o ../pci/pci-raw.o ../lib/minilib.o ../lib/console.o \
        ../ich2/smram-ich2.o ../ich2/smi.o vga-overlay.o packet.o \
        ../lib/sprintf.o ../lib/doprnt.o ../pci/pci.o ../net/net.o \
-       ../ich2/ich2-timer.o ../pci/pci-bother.o ../net/3c90x.o keyboard.o $(LWIP_OBJS)
+       ../ich2/ich2-timer.o ../pci/pci-bother.o ../net/3c90x.o keyboard.o \
+       ../lib/serial.o $(LWIP_OBJS)
 
 all: aseg.elf
 
 
 all: aseg.elf
 
diff --git a/lib/serial.c b/lib/serial.c
new file mode 100644 (file)
index 0000000..5318c95
--- /dev/null
@@ -0,0 +1,50 @@
+#include <minilib.h>
+#include <io.h>
+
+#define SER_BASE 0x3F8
+#define SER_THR 0x0
+#define SER_RBR 0x0
+#define SER_DLL 0x0
+#define SER_IER 0x1
+#define SER_DLM 0x1
+#define SER_IIR 0x2
+#define SER_FCR 0x2
+#define SER_LCR 0x3
+#define SER_LCR_DLAB 0x80
+#define SER_MCR 0x4
+#define SER_LSR 0x5
+#define SER_LSR_THR_EMPTY 0x20
+#define SER_MSR 0x6
+#define SER_SR 0x7
+
+#define SER_BAUD_BASE 115200
+#define SER_BAUD_REQ 115200
+
+void _outb(unsigned short port, unsigned char d)
+{
+       outb(SER_BASE + port, d);
+}
+
+unsigned char _inb(unsigned short port)
+{
+       return inb(SER_BASE + port);
+}
+
+void serial_init()
+{
+       unsigned short baud = SER_BAUD_REQ / SER_BAUD_BASE;
+       _outb(SER_LCR, inb(SER_LCR) | SER_LCR_DLAB);
+       _outb(SER_DLL, baud & 0xFF);
+       _outb(SER_DLM, baud >> 8);
+       _outb(SER_LCR, inb(SER_LCR) & ~SER_LCR_DLAB);
+       _outb(SER_IER, 0x0);
+       _outb(SER_FCR, 0x0);    /* FIFOs off */
+       _outb(SER_LCR, 0x03);   /* 8 data bits, one stop bit, no parity */
+}
+
+void serial_tx(unsigned char c)
+{
+       while (!(_inb(SER_LSR) & SER_LSR_THR_EMPTY))
+               ;
+       _outb(SER_THR, c);
+}
This page took 0.032805 seconds and 4 git commands to generate.