Permalink
Browse files

Part 7, Output Driver

  • Loading branch information...
singpolyma committed Feb 1, 2013
1 parent 876a9d0 commit e32cd571bce206b188b464e949a55e70739db8dc
Showing with 29 additions and 20 deletions.
  1. +22 −18 kernel.c
  2. +7 −2 versatilepb.h
View
@@ -120,33 +120,37 @@ int open(const char *pathname, int flags) {
return fd;
}
-void otherguy() {
+void serialout(volatile unsigned int* uart, unsigned int intr) {
int fd;
- unsigned int len;
- char buf[20];
- mkfifo("/proc/0", 0);
- fd = open("/proc/0", 0);
+ char c;
+ int doread = 1;
+ mkfifo("/dev/tty0/out", 0);
+ fd = open("/dev/tty0/out", 0);
+
+ /* enable TX interrupt on UART */
+ *(uart + UARTIMSC) |= UARTIMSC_TXIM;
+
while(1) {
- read(fd, &len, 4);
- read(fd, buf, len);
- bwputs(buf);
+ if(doread) read(fd, &c, 1);
+ doread = 0;
+ if(!(*(uart + UARTFR) & UARTFR_TXFF)) {
+ *uart = c;
+ doread = 1;
+ }
+ interrupt_wait(intr);
}
}
void first(void) {
int fd;
if(!fork()) pathserver();
- if(!fork()) otherguy();
+ if(!fork()) serialout(UART0, PIC_UART0);
- fd = open("/proc/0", 0);
- while(1) {
- int len = sizeof("Ping\n");
- char buf[sizeof("Ping\n")+4];
- memcpy(buf, &len, 4);
- memcpy(buf+4, "Ping\n", len);
- write(fd, buf, len+4);
- }
+ fd = open("/dev/tty0/out", 0);
+ write(fd, "woo\n", sizeof("woo\n"));
+ write(fd, "thar\n", sizeof("thar\n"));
+ while(1);
}
struct pipe_ringbuffer {
@@ -255,7 +259,7 @@ int main(void) {
*(PIC + VIC_INTENABLE) = PIC_TIMER01;
- *TIMER0 = 1000000;
+ *TIMER0 = 10000;
*(TIMER0 + TIMER_CONTROL) = TIMER_EN | TIMER_PERIODIC
| TIMER_32BIT | TIMER_INTEN;
View
@@ -1,6 +1,10 @@
+/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0224i/Bbabegge.html */
#define UART0 ((volatile unsigned int*)0x101f1000)
-#define UARTFR 0x06
-#define UARTFR_TXFF 0x20
+/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0183g/I18381.html */
+#define UARTFR 0x06 /* 0x18 bytes */
+#define UARTIMSC 0x0E /* 0x38 bytes */
+#define UARTFR_TXFF 0x20
+#define UARTIMSC_TXIM 0x20
/* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0271d/index.html */
#define TIMER0 ((volatile unsigned int*)0x101E2000)
@@ -18,6 +22,7 @@
/* http://infocenter.arm.com/help/topic/com.arm.doc.dui0224i/I1042232.html */
#define PIC ((volatile unsigned int*)0x10140000)
#define PIC_TIMER01 0x10
+#define PIC_UART0 0x1000
/* http://infocenter.arm.com/help/topic/com.arm.doc.ddi0181e/I1006461.html */
#define VIC_INTENABLE 0x4 /* 0x10 bytes */
#define VIC_INTENCLEAR 0x5 /* 0x14 bytes */

0 comments on commit e32cd57

Please sign in to comment.