Add parallel port backend
authorJelmer Vernooij <jelmer@vernstok.nl>
Mon, 2 Feb 2004 13:31:22 +0000 (14:31 +0100)
committerJelmer Vernooij <jelmer@vernstok.nl>
Mon, 2 Feb 2004 13:31:22 +0000 (14:31 +0100)
Makefile
pins-parallel.c [new file with mode: 0644]

index dc4448ce8c79b7e4b880b02bf5f3ba9c4330054a..16c43b962c1ba5c622958a9adc04ac02e626790d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ LIBS = -lpopt
 DEBUG = -g3 #-pg -fprofile-arcs
 #DEBUG = 
 
-PROG_OBJ = prog1.o at89ser.o pins.o pins-serial.o pins-serial-raw.o delays.o
+PROG_OBJ = prog1.o at89ser.o pins.o pins-serial.o pins-serial-raw.o delays.o pins-parallel.o
 DELAYTEST_OBJ = delaytest.o delays.o
 
 all: at89prog
diff --git a/pins-parallel.c b/pins-parallel.c
new file mode 100644 (file)
index 0000000..89f5d68
--- /dev/null
@@ -0,0 +1,97 @@
+#include <stdio.h>
+#include "pins.h"
+#include <signal.h>
+#include <sys/types.h>
+#include <string.h>
+#include <sys/io.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <time.h>
+
+static char *available_pins[] = { "ERROR", "SLCT", "PE", "ACK", "BUSY", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "STROBE", "AUTO_FD_XT", "INIT", "SLCT_IN", NULL };
+
+struct bit {
+       int offset;
+       int bit;
+       char reverse;
+};
+
+static int parport = 0x3bc;
+
+static struct bit bits[] = {
+       { 1, 0x08, 0}, /* ERROR */
+       { 1, 0x10, 0}, /* SLCT */
+       { 1, 0x20, 0}, /* PE */
+       { 1, 0x40, 0}, /* ACK */
+       { 1, 0x80, 1}, /* BUSY */
+       { 0, 0x01, 0}, /* D0 */
+       { 0, 0x02, 0}, /* D1 */
+       { 0, 0x04, 0}, /* D2 */
+       { 0, 0x08, 0}, /* D3 */
+       { 0, 0x10, 0}, /* D4 */
+       { 0, 0x20, 0}, /* D5 */
+       { 0, 0x40, 0}, /* D6 */
+       { 0, 0x80, 0}, /* D7 */
+       { 2, 0x01, 1}, /* STROBE */
+       { 2, 0x02, 1}, /* AUTO_FD_XT */
+       { 2, 0x04, 0}, /* INIT */
+       { 2, 0x08, 1}, /* SLCT_IN */
+       { 0, 0, 0 }
+};
+
+static void par_set(int p)
+{
+       int status = inb(parport + bits[p].offset);
+       
+       if(bits[p].reverse)status &= ~bits[p].bit;
+       else status |= bits[p].bit;
+       outb(status, parport + bits[p].offset);
+}
+
+static void par_clear(int p)
+{
+       int status = inb(parport + bits[p].offset);
+       if(bits[p].reverse)status |= bits[p].bit;
+       else status &= ~bits[p].bit;
+       outb(status, parport + bits[p].offset);
+}
+
+static int par_get(int p)
+{
+       int status = inb(parport + bits[p].offset);
+       if(bits[p].reverse) return !(status & bits[p].bit);
+       else return status & bits[p].bit;
+}
+
+static int raw_init(char *location) 
+{
+
+       if(location) parport = strtol(location, NULL, 16);
+
+       if(ioperm(parport, 7, 1) == -1) 
+       {
+               perror("ioperm");
+               fprintf(stderr, "Run at89prog with IO port access\n");
+               return -1;
+       }
+
+       if(ioperm(0x80, 1, 1) == -1) 
+       {
+               perror("ioperm");
+               return -1;
+       }
+
+       return 0;
+}
+
+struct pins_backend parial_raw = {
+       "parallel",
+       available_pins,
+       raw_init,
+       par_set,
+       par_clear,
+       par_get,
+       NULL
+};
+