From: Jelmer Vernooij Date: Mon, 2 Feb 2004 13:31:22 +0000 (+0100) Subject: Add parallel port backend X-Git-Tag: at89prog-0.7~24 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=8e7cacf468b17873e0434a8e956576e187585445;p=jelmer%2Fat89prog.git Add parallel port backend --- diff --git a/Makefile b/Makefile index dc4448c..16c43b9 100644 --- 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 index 0000000..89f5d68 --- /dev/null +++ b/pins-parallel.c @@ -0,0 +1,97 @@ +#include +#include "pins.h" +#include +#include +#include +#include +#include +#include +#include +#include + +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 +}; +